Kimi (Moonshot AI) Utilities API

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

OpenAPI Specification

kimi-moonshot-utilities-api-openapi.yml Raw ↑
openapi: 3.1.0
info:
  title: Moonshot AI Utilities API
  version: 1.0.0
  description: Moonshot AI / Kimi 大语言模型服务 API
servers:
- url: https://api.moonshot.cn
  description: 生产环境
tags:
- name: Utilities
paths:
  /v1/tokenizers/estimate-token-count:
    post:
      summary: 估算 Token 数量
      description: 估算给定消息和模型所需的 Token 数量。输入结构与聊天补全几乎相同。
      tags:
      - Utilities
      security:
      - bearerAuth: []
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/EstimateTokenRequest'
      responses:
        '200':
          description: Token 数量估算结果
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/EstimateTokenResponse'
        '400':
          description: 请求错误 - 参数无效
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '401':
          description: 未授权 - API 密钥无效或缺失
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '500':
          description: 服务器错误
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
components:
  schemas:
    EstimateTokenResponse:
      type: object
      properties:
        data:
          type: object
          properties:
            total_tokens:
              type: integer
              description: 估算的总 Token 数量
              example: 80
          required:
          - total_tokens
      required:
      - data
    EstimateTokenRequest:
      type: object
      properties:
        model:
          type: string
          description: 模型 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: '包含迄今为止对话的消息列表。每个元素格式为 {"role": "user", "content": "你好"}。role 支持 system、user、assistant 其一,content 不得为空'
          items:
            $ref: '#/components/schemas/Message'
      required:
      - model
      - messages
    ErrorResponse:
      type: object
      properties:
        error:
          type: object
          properties:
            message:
              type: string
              description: 描述错误原因的错误消息
            type:
              type: string
              description: 错误类型
            code:
              type: string
              description: 错误码
          required:
          - message
      required:
      - error
    Message:
      type: object
      properties:
        role:
          type: string
          enum:
          - system
          - user
          - assistant
          description: 消息发送者的角色
        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: 消息内容。可以是纯文本字符串,也可以是包含 text/image_url/video_url 类型的对象数组(用于多模态输入)
        name:
          type: string
          default: null
          description: 消息发送者的名称(可选)
        partial:
          type: boolean
          default: false
          description: 在最后一条 assistant 消息中设置为 true 以启用 Partial Mode
      required:
      - role
      - content
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      description: Authorization 请求头需要一个 Bearer 令牌。使用 MOONSHOT_API_KEY 作为令牌。这是一个服务端密钥,请在 [API 密钥页面](https://platform.kimi.com/console/api-keys) 生成。