> ## Documentation Index
> Fetch the complete documentation index at: https://docs.apiany.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# 创建对话补全

> OpenAI 兼容的 Chat Completions 接口。当前以非 streaming 调用为主。



## OpenAPI

````yaml /zh/openapi.json post /v1/chat/completions
openapi: 3.1.0
info:
  title: APIAny.AI 公开 API
  version: 1.0.0
  description: APIAny.AI 模型聚合、异步媒体任务、对话生成、积分查询和任务查询的公开 API。
servers:
  - url: https://apiany.ai
    description: Production
security:
  - bearerAuth: []
tags:
  - name: Models
    description: 公开模型目录。
  - name: Chat
    description: 文本生成和对话兼容接口。
  - name: Images
    description: 图片生成和图片编辑接口。
  - name: Videos
    description: 视频生成接口。
  - name: Moderation
    description: Image safety and moderation endpoints.
  - name: Tasks
    description: 异步任务查询。
  - name: Account
    description: 账户与积分查询。
  - name: Free APIs
    description: Free utility APIs protected by API key rate limits.
paths:
  /v1/chat/completions:
    post:
      tags:
        - Chat
      summary: 创建对话补全
      description: OpenAI 兼容的 Chat Completions 接口。当前以非 streaming 调用为主。
      operationId: createChatCompletion
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ChatCompletionRequest'
            examples:
              basic:
                value:
                  model: gpt-5.4
                  messages:
                    - role: user
                      content: Write a concise product tagline for APIAny.AI.
                  temperature: 0.7
      responses:
        '200':
          description: OpenAI 兼容的对话补全响应。
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ChatCompletionResponse'
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '429':
          $ref: '#/components/responses/RateLimited'
components:
  schemas:
    ChatCompletionRequest:
      type: object
      properties:
        model:
          type: string
          example: gpt-5.4
        messages:
          type: array
          items:
            $ref: '#/components/schemas/ChatMessage'
        temperature:
          type: number
          minimum: 0
          maximum: 2
          description: 采样温度。
        top_p:
          type: number
          minimum: 0
          maximum: 1
          description: 核采样累计概率。
        max_tokens:
          type: integer
          minimum: 1
          deprecated: true
          description: max_completion_tokens 的兼容旧别名。APIAny 仅在所选模型路由需要新字段时转换。
        max_completion_tokens:
          type: integer
          minimum: 1
          maximum: 1048576
          description: 思考过程与最终答案合计的最大 Token 数。Kimi K3 省略时默认 131072，最高支持 1048576。
        reasoning_effort:
          type: string
          enum:
            - max
          description: Kimi K3 的思考强度。K3 始终思考，目前仅支持 max。
        stop:
          oneOf:
            - type: string
            - type: array
              items:
                type: string
          description: 最多 4 个停止序列。
        'n':
          type: integer
          minimum: 1
          description: 生成候选条数。
        frequency_penalty:
          type: number
          minimum: -2
          maximum: 2
        presence_penalty:
          type: number
          minimum: -2
          maximum: 2
        seed:
          type: integer
          description: 尽量可复现的采样种子。
        response_format:
          type: object
          description: '强制 JSON 对象或 JSON Schema 输出，如 { "type": "json_object" }。'
          additionalProperties: true
        tools:
          type: array
          description: 模型可调用的工具/函数声明。
          items:
            type: object
            additionalProperties: true
        tool_choice:
          description: >-
            工具选择：'auto' | 'none' | 'required' | { type: 'function', function: {
            name } }。
          oneOf:
            - type: string
            - type: object
              additionalProperties: true
        logprobs:
          type: boolean
        top_logprobs:
          type: integer
          minimum: 0
          maximum: 20
        logit_bias:
          type: object
          additionalProperties: true
        user:
          type: string
          description: 终端用户标识，用于风险审计。
        stream:
          type: boolean
          description: >-
            为 true 时通过 SSE 流式返回增量（OpenAI chat.completion.chunk），以 'data: [DONE]'
            结束。
      required:
        - model
        - messages
    ChatCompletionResponse:
      type: object
      properties:
        id:
          type: string
        object:
          type: string
          example: chat.completion
        created:
          type: integer
        model:
          type: string
        choices:
          type: array
          items:
            type: object
            additionalProperties: true
        usage:
          $ref: '#/components/schemas/TokenUsage'
      required:
        - id
        - object
        - created
        - model
        - choices
    ChatMessage:
      type: object
      properties:
        role:
          type: string
          enum:
            - system
            - user
            - assistant
            - tool
        content:
          oneOf:
            - type: string
            - type: array
              items:
                type: object
                additionalProperties: true
        reasoning_content:
          type: string
          description: 支持思考的模型返回的思考过程。Kimi K3 多轮历史必须保留此字段。
        partial:
          type: boolean
          default: false
          description: Kimi Partial Mode，仅在最后一条 assistant 前缀消息上设置为 true。
        tools:
          type: array
          description: Kimi K3 通过不含 content 的 system message 动态加载的工具声明。
          items:
            type: object
            additionalProperties: true
      required:
        - role
    TokenUsage:
      type: object
      properties:
        prompt_tokens:
          type: integer
        completion_tokens:
          type: integer
        total_tokens:
          type: integer
        input_tokens:
          type: integer
        output_tokens:
          type: integer
        cached_input_tokens:
          type: integer
      additionalProperties: true
    ErrorResponse:
      type: object
      properties:
        error:
          type: object
          properties:
            type:
              type: string
              enum:
                - invalid_request
                - auth_error
                - rate_limit
                - insufficient_quota
                - content_policy
                - timeout
                - network_error
                - service_error
                - billable_error
                - unknown
            message:
              type: string
            param:
              type:
                - string
                - 'null'
            code:
              type:
                - string
                - 'null'
          required:
            - type
            - message
      required:
        - error
  responses:
    BadRequest:
      description: 请求参数无效。
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
    Unauthorized:
      description: 缺少 API Key 或 API Key 无效。
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
    RateLimited:
      description: 请求超过速率限制。
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      bearerFormat: API key

````