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

# OpenAI 对话

> 接口说明：OpenAI Chat Completions API 的兼容端点，支持 `stream` 流式输出。请求、响应与错误格式完全遵循 OpenAI 规范；鉴权使用 `Authorization: Bearer <API Key>`（OpenAI SDK 默认携带），已有 OpenAI SDK 或生态工具只需替换 baseURL 与 API Key 即可接入，按 AiToEarn 积分计费。

调用本接口前，请先请求[「对话模型列表」](/api-reference/get-api-ai-models-chat)接口（`GET /api/ai/models/chat`），获取当前可用的模型列表。



## OpenAPI

````yaml /openapi/zh/aitoearn.openapi.json post /api/ai/chat/completions
openapi: 3.0.1
info:
  title: AiToEarn 开放平台 API
  description: AiToEarn 开放平台 API，支持在中国站与国际站之间切换调试。业务是否成功以响应体 code === 0 为准。
  version: 1.0.0
  contact: {}
servers:
  - url: https://aitoearn.cn
    description: 中国站
  - url: https://aitoearn.ai
    description: 国际站
security: []
tags:
  - name: AI 服务
  - name: AI 服务/视频生成
  - name: AI 服务/图像生成
  - name: 渠道管理
  - name: 渠道管理/账号
  - name: 渠道管理/内容发布
  - name: 渠道管理/平台
  - name: 渠道管理/作品
  - name: 渠道管理/账号分组
  - name: 渠道管理/授权
  - name: 资源管理
  - name: AI 服务/大语言模型
  - name: AI 服务/真人素材
  - name: AI 服务/Agent
paths:
  /api/ai/chat/completions:
    post:
      tags:
        - AI 服务/大语言模型
      summary: OpenAI 对话
      description: >-
        接口说明：OpenAI Chat Completions API 的兼容端点，支持 `stream` 流式输出。请求、响应与错误格式完全遵循
        OpenAI 规范；鉴权使用 `Authorization: Bearer <API Key>`（OpenAI SDK 默认携带），已有
        OpenAI SDK 或生态工具只需替换 baseURL 与 API Key 即可接入，按 AiToEarn 积分计费。


        调用本接口前，请先请求[「对话模型列表」](/api-reference/get-api-ai-models-chat)接口（`GET
        /api/ai/models/chat`），获取当前可用的模型列表。
      operationId: RelayController_chatCompletions
      parameters: []
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/RelayChatCompletionsDto'
            examples: {}
        required: true
      responses:
        '200':
          description: 第三方协议原生响应或 SSE 数据。不使用 AiToEarn 通用响应包裹。
          content:
            application/json:
              examples:
                gpt-5.6-terra:
                  value:
                    id: string
                    object: string
                    created: integer
                    model: string
                    choices:
                      - index: integer
                        message:
                          role: string
                          content: string
                          reasoning_content: string
                          tool_calls:
                            - object
                        finish_reason: string
                        native_finish_reason: string
                    usage:
                      completion_tokens: integer
                      total_tokens: integer
                      prompt_tokens: integer
                      prompt_tokens_details: object | null
                      completion_tokens_details: object | null
                glm-5.2:
                  value:
                    id: string
                    object: string
                    created: integer
                    model: string
                    choices:
                      - index: integer
                        finish_reason: string
                        logprobs: object | null
                        message:
                          role: string
                          content: string
                          name: string | null
                          reasoning_content: string
                          tool_calls:
                            - object
                    usage:
                      prompt_tokens: integer
                      completion_tokens: integer
                      total_tokens: integer
                      prompt_tokens_details: object | null
                    cost: string
                deepseek-v4-pro:
                  value:
                    id: string
                    object: string
                    created: integer
                    model: string
                    choices:
                      - index: integer
                        finish_reason: string
                        logprobs: object | null
                        message:
                          role: string
                          content: string
                          reasoning_content: string
                    usage:
                      prompt_tokens: integer
                      completion_tokens: integer
                      total_tokens: integer
                      prompt_cache_hit_tokens: integer
                      prompt_cache_miss_tokens: integer
                      prompt_tokens_details: object | null
                      completion_tokens_details: object | null
                    cost: string
            text/event-stream:
              schema:
                type: string
                description: SSE 流式响应。
              example: string
      deprecated: false
      security:
        - apikey-header-Authorization: []
components:
  schemas:
    RelayChatCompletionsDto:
      type: object
      properties:
        messages:
          minItems: 1
          type: array
          items:
            type: object
            properties:
              role:
                type: string
                description: 消息角色，用于区分不同消息来源
              content:
                description: 内容正文
            required:
              - role
              - content
            additionalProperties: true
          description: 消息列表
        model:
          type: string
          description: >-
            模型 ID。先调用[「对话模型列表」](/api-reference/get-api-ai-models-chat)接口（`GET
            /api/ai/models/chat`），传入其返回的 `data[n].name`。
        stream:
          description: 是否流式返回
          type: boolean
      required:
        - messages
        - model
      additionalProperties: true
  securitySchemes:
    apikey-header-Authorization:
      type: apiKey
      in: header
      name: Authorization
      description: >-
        传入从 AiToEarn 获取 API Key。点击前往[「API Key 获取教程」](/zh/use/api-key)。示例：Bearer
        xxx。

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.