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

# /v1/chat/completions

> OpenAI-compatible chat completion endpoint for multi-turn conversations, tool calling, and streaming responses.

用于为一段聊天对话生成模型回复。

这个接口适合标准文本对话，也可以承载视觉、音频和工具调用等场景。具体可用参数会随着模型能力不同而变化，尤其是推理模型与通用模型之间会有差异。

## 接入说明

* 鉴权方式使用 `Authorization: Bearer {API_KEY}`
* 请求体通常至少包含 `messages` 和 `model`
* 如果你在兼容现有 OpenAI SDK、聊天前端或多轮对话工作流，这通常是默认入口
* 如果你更看重统一的结构化输出、多模态输入和后续能力扩展，可以优先评估 `/v1/responses`
* 开启流式返回时，请按 SSE chunk 增量处理，而不是等待完整 JSON

## 请求重点

* `messages` 是必填字段，用于承载完整对话历史；不同模型支持的消息模态可能不同
* `model` 是必填字段，用于指定本次调用的模型 ID
* `temperature` 和 `top_p` 都会影响采样行为，通常只需要重点调整其中一个
* 如果需要更丰富的调试或概率信息，可以结合 `logprobs` 与 `top_logprobs`
* 如果需要缓存优化或安全归因，优先使用 `prompt_cache_key` 与 `safety_identifier`

## 返回重点

* 常规文本结果通常从 `choices[0].message.content` 读取
* 如果模型触发工具调用，可以从 `message.tool_calls` 中读取工具名称和参数
* 流式模式下，返回内容会分段推送，客户端需要持续消费事件流
* 用量统计可以从 `usage` 中读取，包括输入、输出和更细粒度的 token 明细


## OpenAPI

````yaml POST /v1/chat/completions
openapi: 3.1.0
info:
  title: OpenAPI Plant Store
  description: >-
    A sample API that uses a plant store as an example to demonstrate features
    in the OpenAPI specification
  license:
    name: MIT
  version: 1.0.0
servers:
  - url: https://api-vip.apigo.ai
security:
  - bearerAuth: []
paths:
  /v1/chat/completions:
    post:
      summary: OpenAI chat completions
      description: 兼容 OpenAI 的聊天补全接口，支持多轮对话、工具调用和流式返回。
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/OpenAIChatCompletionsRequest'
      responses:
        '200':
          description: Successful chat completion response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/OpenAIChatCompletionsResponse'
        '400':
          description: Invalid request
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
components:
  schemas:
    OpenAIChatCompletionsRequest:
      type: object
      required:
        - model
        - messages
      properties:
        model:
          type: string
          example: gpt-4o
        messages:
          type: array
          items:
            $ref: '#/components/schemas/OpenAIMessage'
        temperature:
          type: number
          example: 0.7
        stream:
          type: boolean
    OpenAIChatCompletionsResponse:
      type: object
      properties:
        id:
          type: string
        object:
          type: string
          example: chat.completion
        choices:
          type: array
          items:
            type: object
            properties:
              index:
                type: integer
              message:
                $ref: '#/components/schemas/OpenAIMessage'
              finish_reason:
                type: string
        usage:
          type: object
          properties:
            prompt_tokens:
              type: integer
            completion_tokens:
              type: integer
            total_tokens:
              type: integer
    Error:
      required:
        - error
        - message
      type: object
      properties:
        error:
          type: integer
          format: int32
        message:
          type: string
    OpenAIMessage:
      type: object
      required:
        - role
        - content
      properties:
        role:
          type: string
          enum:
            - system
            - user
            - assistant
            - tool
        content:
          type: string
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer

````