Moonshot AI Utilities API

The Utilities API from Moonshot AI — 1 operation(s) for utilities.

OpenAPI Specification

moonshot-ai-utilities-api-openapi.yml Raw ↑
openapi: 3.1.0
info:
  title: Moonshot AI Batch Utilities API
  version: 1.0.0
  description: API for Moonshot AI / Kimi large language model services
servers:
- url: https://api.moonshot.ai
  description: Production
tags:
- name: Utilities
paths:
  /v1/tokenizers/estimate-token-count:
    post:
      summary: Estimate Token Count
      description: Estimates the number of tokens that would be used for a given set of messages and model. The input structure is almost identical to that of chat completion.
      tags:
      - Utilities
      security:
      - bearerAuth: []
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/EstimateTokenRequest'
      responses:
        '200':
          description: Token count estimation
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/EstimateTokenResponse'
        '400':
          description: Bad request - Invalid parameters
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '401':
          description: Unauthorized - Invalid or missing API key
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '500':
          description: Server error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
components:
  schemas:
    EstimateTokenResponse:
      type: object
      properties:
        data:
          type: object
          properties:
            total_tokens:
              type: integer
              description: Estimated total number of tokens
              example: 80
          required:
          - total_tokens
      required:
      - data
    EstimateTokenRequest:
      type: object
      properties:
        model:
          type: string
          description: Model ID
          default: kimi-k2.5
          enum:
          - kimi-k2.6
          - kimi-k2.5
          - kimi-k2-0905-preview
          - kimi-k2-0711-preview
          - kimi-k2-turbo-preview
          - moonshot-v1-8k
          - moonshot-v1-32k
          - moonshot-v1-128k
          - moonshot-v1-auto
          - moonshot-v1-8k-vision-preview
          - moonshot-v1-32k-vision-preview
          - moonshot-v1-128k-vision-preview
        messages:
          type: array
          description: 'A list of messages in the conversation so far. Each element has the format {"role": "user", "content": "Hello"}. role supports system, user, or assistant. content must not be empty'
          items:
            $ref: '#/components/schemas/Message'
      required:
      - model
      - messages
    ErrorResponse:
      type: object
      properties:
        error:
          type: object
          properties:
            message:
              type: string
              description: Error message describing what went wrong
            type:
              type: string
              description: Error type
            code:
              type: string
              description: Error code
          required:
          - message
      required:
      - error
    Message:
      type: object
      properties:
        role:
          type: string
          enum:
          - system
          - user
          - assistant
          description: The role of the message sender
        content:
          oneOf:
          - type: string
          - type: array
            items:
              oneOf:
              - title: text
                type: object
                properties:
                  type:
                    type: string
                    enum:
                    - text
                  text:
                    type: string
                required:
                - type
                - text
              - title: image_url
                type: object
                properties:
                  type:
                    type: string
                    enum:
                    - image_url
                  image_url:
                    oneOf:
                    - type: object
                      properties:
                        url:
                          type: string
                      required:
                      - url
                    - type: string
                required:
                - type
                - image_url
              - title: video_url
                type: object
                properties:
                  type:
                    type: string
                    enum:
                    - video_url
                  video_url:
                    oneOf:
                    - type: object
                      properties:
                        url:
                          type: string
                      required:
                      - url
                    - type: string
                required:
                - type
                - video_url
          description: The content of the message. Can be a plain text string, or an array of objects with text/image_url/video_url types (for multimodal input)
        name:
          type: string
          default: null
          description: Optional name for the message sender
        partial:
          type: boolean
          default: false
          description: Enable Partial Mode by setting this to true in the last assistant message
      required:
      - role
      - content
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      description: The Authorization header expects a Bearer token. Use an MOONSHOT_API_KEY as the token. This is a server-side secret key. Generate one on the [API keys page](https://platform.kimi.ai/console/api-keys) in your dashboard.