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

# 创建对话补全

> 调用已启用模型，通过 GET /v1/models 查询工具、JSON 格式、采样、推理及组合限制。能力审查覆盖全部可调用路由；新增组合依据文档，仍待逐项真实调用验证。预留费用并按可信用量结算，请关闭 SDK 自动重试。Responses 为无状态／store:false，不支持托管工具及存储引用。所有可调用路由采用参数透传（parameter_policy upstream-first）；能力列表提供建议，普通 Schema 与扩展字段透传。保留原生响应与推理输出；模型服务方 400／422 拒绝释放预留，模型服务方故障、超时或断流需要对账。



## OpenAPI

````yaml /openapi.cn.json post /v1/chat/completions
openapi: 3.1.0
info:
  title: OmniRelay API
  version: 1.0.0
  description: 面向已核验真实文本模型的兼容 OpenAI 网关。访问按工作空间开通，使用自己的模型列表查询能力与客户价格。
servers:
  - url: https://api.omnirelay.ai
security:
  - bearerAuth: []
tags:
  - name: 服务
  - name: 模型
  - name: 对话
  - name: 管理 API
  - name: 响应
  - name: 向量
  - name: 图片
  - name: 视频
paths:
  /v1/chat/completions:
    post:
      tags:
        - 对话
      summary: 创建对话补全
      description: >-
        调用已启用模型，通过 GET /v1/models 查询工具、JSON
        格式、采样、推理及组合限制。能力审查覆盖全部可调用路由；新增组合依据文档，仍待逐项真实调用验证。预留费用并按可信用量结算，请关闭 SDK
        自动重试。Responses
        为无状态／store:false，不支持托管工具及存储引用。所有可调用路由采用参数透传（parameter_policy
        upstream-first）；能力列表提供建议，普通 Schema 与扩展字段透传。保留原生响应与推理输出；模型服务方 400／422
        拒绝释放预留，模型服务方故障、超时或断流需要对账。
      operationId: createChatCompletion
      parameters:
        - name: X-Gateway-Tags
          in: header
          required: false
          description: >-
            本次调用的标签，以逗号分隔的 `key=value`，例如 `client=acme,env=prod`。与 API Key
            的默认标签合并；同名 key 以请求体 `tags` 字段为准。`X-OmniRelay-Tags` 是同一个请求头的旧名，继续接受。
          schema:
            type: string
          example: client=acme,env=prod
        - name: X-Gateway-Metadata
          in: header
          required: false
          description: >-
            传 `enabled` 时，响应会附带
            `gateway_metadata`，说明网关为本次调用做出的决定。其他值或不传此头，响应保持不变。`X-OmniRelay-Metadata`
            是同一个请求头的旧名，继续接受。
          schema:
            type: string
            enum:
              - enabled
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ChatCompletionRequest'
            examples:
              liveProvider:
                summary: 仅已启用真实模型的工作区
                value:
                  model: gpt-6-luna
                  messages:
                    - role: system
                      content: Answer concisely.
                    - role: user
                      content: Hello OmniRelay
                  max_completion_tokens: 64
                  reasoning_effort: none
              liveStream:
                summary: 仅已启用真实模型的工作区
                value:
                  model: deepseek-v4-pro
                  messages:
                    - role: user
                      content: Hello OmniRelay
                  max_tokens: 128
                  stream: true
                  stream_options:
                    include_usage: true
      responses:
        '200':
          description: 返回已结算用量和费用的补全，或 SSE 流。流式请求可能在 HTTP 200 后输出错误，此时不会以 [DONE] 结束。
          headers:
            X-Request-ID:
              description: 用于诊断的 OmniRelay 请求 ID，与模型服务方追踪、响应头及响应体 ID 分别记录。
              schema:
                type: string
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ChatCompletion'
              examples:
                live:
                  summary: 仅已启用真实模型的工作区
                  value:
                    id: chatcmpl-example
                    object: chat.completion
                    created: 1790985600
                    model: gpt-6-luna
                    choices:
                      - index: 0
                        message:
                          role: assistant
                          content: Hello.
                        finish_reason: stop
                    usage:
                      prompt_tokens: 10
                      completion_tokens: 5
                      total_tokens: 15
                    cost_microusd: 30
            text/event-stream:
              schema:
                type: string
              example: >+
                data:
                {"id":"chatcmpl-fixture","object":"chat.completion.chunk","model":"gpt-6-luna","choices":[{"index":0,"delta":{"content":"Hello"},"finish_reason":"stop"}]}


                data: [DONE]

        '400':
          description: JSON、标签或参数不合法，模型不支持该能力，或 context_length_exceeded。发往模型服务方前即被拒绝。
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
              example:
                error:
                  code: unsupported_parameter
                request_id: 2f6c1d0e9a
        '401':
          $ref: '#/components/responses/Unauthorized'
        '402':
          description: >-
            inference_budget_or_access_denied 表示钱包、Key
            或平台预算无法覆盖预留；member_budget_exceeded 表示成员上限超出。均在派发前拒绝。
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
              example:
                error:
                  code: insufficient_balance
                request_id: 2f6c1d0e9a
        '403':
          description: '`model_not_allowed`：该 API Key 仅限调用其他模型。不会扣费。'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
              example:
                error:
                  code: model_not_allowed
                request_id: 2f6c1d0e9a
        '404':
          description: '`model_unavailable`：该模型不存在，或已在此工作区停用。'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
              example:
                error:
                  code: model_unavailable
                request_id: 2f6c1d0e9a
        '413':
          description: payload_too_large：请求体超过 4 MiB（4194304 字节 UTF-8）。
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
              example:
                error:
                  code: payload_too_large
                request_id: 2f6c1d0e9a
        '429':
          description: rate_limited：超过账户实际请求频率限制。
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
              example:
                error:
                  code: rate_limited
                request_id: 2f6c1d0e9a
        '502':
          description: 模型服务方拒绝、传输失败、响应无效或用量缺失/无效。已发送的调用可能保留预留等待对账；此状态不代表模型服务方未计费。
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '503':
          description: >-
            channel_unavailable、live_provider_not_configured、live_provider_unavailable、runtime_maintenance
            或 storage_unavailable。凭据与维护检查在发送前拒绝请求。已发送但结果不明确的请求保留
            pending；不要自动重试付费调用。
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
              example:
                error:
                  code: live_provider_not_configured
                request_id: 2f6c1d0e9a
components:
  schemas:
    ChatCompletionRequest:
      type: object
      required:
        - model
        - messages
      properties:
        model:
          type: string
          description: 来自 `GET /v1/models` 的已启用模型 ID。
          example: gpt-6-luna
        messages:
          type: array
          minItems: 1
          maxItems: 2000
          description: >-
            1 至 2000 条文本消息，遵守模型上下文约定。请求体上限 4 MiB（4194304 字节
            UTF-8）。Provider-context-ceiling 分别预留输入与输出，由模型服务方验证实际上下文是否容纳。
          items:
            $ref: '#/components/schemas/Message'
        stream:
          type: boolean
          description: 以服务器发送事件的方式返回回复，而不是一次性返回 JSON。
          default: false
        stream_options:
          type: object
          description: 仅在 `stream` 为 true 时生效。
          properties:
            include_usage:
              type: boolean
              description: 成功 SSE 中请求 choices 为空的最终 usage 与已结算 cost_microusd 块。始终收集最终用量。
              default: false
        tags:
          type: object
          description: >-
            本次调用的标签。与请求头和 Key 默认标签合并后最多 10 个。key 为 1 至 64 个字符，统一存为小写；value 为 1 至
            128 个字符。两者只能包含字母、数字和 `- _ . : /`。以 `gateway:` 或 `omnirelay:` 开头的 key
            为保留字。`tags` 不是对象时会被忽略。
          additionalProperties:
            type: string
          example:
            client: acme
            project: invoices
        max_tokens:
          type: integer
          minimum: 1
          description: >-
            仅真实调用。正整数，两个输出限制字段只传一个；网关按模型要求转换字段。默认值及上限读取模型列表
            limits.default_output_tokens 和 limits.output_tokens；GPT 5.4 Mini 为
            64／256，多数其他已接入文本路由默认 32,000，最多 128,000（Gemini 3.1 Pro Preview 和
            Gemini 3.6 Flash 为 65,536），DeepSeek V4 Pro、GLM 5.3 和 Kimi K3 为
            4,096／4,096。
        max_completion_tokens:
          type: integer
          minimum: 1
          description: >-
            仅真实调用。正整数，两个输出限制字段只传一个；网关按模型要求转换字段。默认值及上限读取模型列表
            limits.default_output_tokens 和 limits.output_tokens；GPT 5.4 Mini 为
            64／256，多数其他已接入文本路由默认 32,000，最多 128,000（Gemini 3.1 Pro Preview 和
            Gemini 3.6 Flash 为 65,536），DeepSeek V4 Pro、GLM 5.3 和 Kimi K3 为
            4,096／4,096。
        temperature:
          type: number
          minimum: 0
          maximum: 2
          description: 透传并由模型服务方判断，可能忽略不支持的取值；请查阅具体模型的文档建议。
        top_p:
          type: number
          minimum: 0
          maximum: 1
          description: 透传并由模型服务方判断，可能忽略不支持的取值；请查阅具体模型的文档建议。
        frequency_penalty:
          type: number
          minimum: -2
          maximum: 2
          description: 仅真实模式，且端点核验配置明确支持时可用。
        presence_penalty:
          type: number
          minimum: -2
          maximum: 2
          description: 仅真实模式，且端点核验配置明确支持时可用。
        seed:
          type: integer
          description: 仅真实模式，且端点核验配置明确支持时可用。
        stop:
          oneOf:
            - type: string
              maxLength: 256
            - type: array
              minItems: 1
              maxItems: 4
              items:
                type: string
                maxLength: 256
          description: 仅真实模式，且端点核验配置明确支持时可用。
        'n':
          type: integer
          enum:
            - 1
          description: 仅真实模式。每次请求不支持生成多个补全。
        tools:
          type: array
          minItems: 1
          maxItems: 64
          items:
            type: object
            required:
              - type
              - function
            properties:
              type:
                type: string
                enum:
                  - function
              function:
                type: object
                required:
                  - name
                properties:
                  name:
                    type: string
                    maxLength: 64
                  description:
                    type: string
                    maxLength: 4096
                  parameters:
                    type: object
                  strict:
                    type: boolean
          description: >-
            仅真实模式且模型支持 tools 时可用。只支持 function 工具；严格工具和 JSON Schema
            关键字另需支持。详见模型接入指南。
        tool_choice:
          oneOf:
            - type: string
              enum:
                - auto
                - none
                - required
            - type: object
              required:
                - type
                - function
              properties:
                type:
                  type: string
                  enum:
                    - function
                function:
                  type: object
                  required:
                    - name
                  properties:
                    name:
                      type: string
          description: >-
            模型声明 tool_choice 时可使用 auto、none 或 required。指定函数名选择还要求
            capabilities.named_tool_choice。
        parallel_tool_calls:
          type: boolean
          description: 仅真实模式，且端点核验配置明确支持时可用。
        response_format:
          type: object
          required:
            - type
          properties:
            type:
              type: string
              enum:
                - text
                - json_object
                - json_schema
            json_schema:
              type: object
              required:
                - name
                - schema
              properties:
                name:
                  type: string
                  maxLength: 64
                description:
                  type: string
                  maxLength: 4096
                schema:
                  type: object
                strict:
                  type: boolean
          description: 透传并由模型服务方判断，可能忽略不支持的取值；请查阅具体模型的文档建议。
        reasoning_effort:
          type: string
          description: 透传并由模型服务方判断，可能忽略不支持的取值；请查阅具体模型的文档建议。
        thinking:
          type: object
          additionalProperties: false
          required:
            - type
          properties:
            type:
              type: string
              enum:
                - enabled
                - disabled
          description: 文档通过 thinking_modes 声明支持；GLM 5.3 仅接受 enabled。
        tool_stream:
          type: boolean
          description: 文档通过 tool_stream 声明支持；true 要求 stream:true。
      additionalProperties: true
      description: 参数透传：普通扩展字段透传，仍执行鉴权、文本／函数协议及预算结算边界。
    ChatCompletion:
      type: object
      required:
        - id
        - object
        - created
        - model
        - choices
        - usage
        - cost_microusd
      properties:
        id:
          type: string
          example: chatcmpl-2f6c1d0e9a
        object:
          type: string
          enum:
            - chat.completion
        created:
          type: integer
          description: Unix 时间戳，单位为秒。
        model:
          type: string
        choices:
          type: array
          items:
            type: object
            properties:
              index:
                type: integer
              message:
                $ref: '#/components/schemas/AssistantMessage'
              finish_reason:
                type: string
                enum:
                  - stop
                  - length
                  - tool_calls
                  - content_filter
        usage:
          type: object
          description: >-
            已验证模型服务方用量，缺失或不合法会阻止自动结算。Prompt 包含缓存分项，completion 包含推理。省略明细计数不会抹除
            Token 用量。
          properties:
            prompt_tokens:
              type: integer
            completion_tokens:
              type: integer
            total_tokens:
              type: integer
            prompt_tokens_details:
              type: object
              properties:
                cached_tokens:
                  type: integer
                  minimum: 0
                cache_write_tokens:
                  type: integer
                  minimum: 0
            completion_tokens_details:
              type: object
              properties:
                reasoning_tokens:
                  type: integer
                  minimum: 0
          required:
            - prompt_tokens
            - completion_tokens
            - total_tokens
        cost_microusd:
          type: integer
          description: 按冻结价格、Token 分项、阶梯和折扣计算的已结算费用，单位微美元。整次费用取整后应用折扣，再向上取整。这是最终费用，不是最高预留。
        omnirelay_metadata:
          $ref: '#/components/schemas/RequestMetadata'
        gateway_metadata:
          $ref: '#/components/schemas/RequestMetadata'
    Error:
      type: object
      required:
        - error
      properties:
        error:
          type: object
          required:
            - code
            - message
            - type
          properties:
            code:
              type: string
              example: model_unavailable
            message:
              type: string
              example: The model does not exist or is disabled.
              description: 用于日志和 SDK 异常的简短英文说明；措辞可能调整，请按 code 判断。
            type:
              type: string
              example: not_found_error
              description: >-
                按 HTTP
                状态划分的错误类别：invalid_request_error、authentication_error、insufficient_quota、permission_error、not_found_error、conflict_error、rate_limit_error、service_unavailable
                或 api_error。
            param:
              type: string
              maxLength: 200
              description: 可识别时返回被拒绝的请求字段路径，不包含参数值；Responses 使用原生字段名。
        request_id:
          type: string
          description: 在对话补全、Responses 和 Embeddings 出错时返回。
    Message:
      type: object
      required:
        - role
      properties:
        role:
          type: string
          enum:
            - system
            - developer
            - user
            - assistant
            - tool
        content:
          oneOf:
            - type: string
              maxLength: 1048576
            - type: array
              maxItems: 64
              items:
                type: object
                required:
                  - type
                  - text
                properties:
                  type:
                    type: string
                    enum:
                      - text
                  text:
                    type: string
                    maxLength: 1048576
            - type: 'null'
          description: 文本值或文本片段：单个文本值最多 1048576 字符，并受 4 MiB 请求体上限和模型上下文窗口约束。角色需模型能力支持。
        name:
          type: string
          maxLength: 64
        tool_call_id:
          type: string
        tool_calls:
          type: array
          maxItems: 64
          items:
            $ref: '#/components/schemas/ToolCall'
        reasoning_content:
          type:
            - string
            - 'null'
          maxLength: 1048576
          description: 文档通过 reasoning_history 声明支持的助手推理历史，包括 DeepSeek 工具对话。
    AssistantMessage:
      type: object
      required:
        - role
      properties:
        role:
          type: string
          enum:
            - system
            - developer
            - user
            - assistant
            - tool
        content:
          oneOf:
            - type: string
              maxLength: 1048576
            - type: array
              maxItems: 64
              items:
                type: object
                required:
                  - type
                  - text
                properties:
                  type:
                    type: string
                    enum:
                      - text
                  text:
                    type: string
                    maxLength: 1048576
            - type: 'null'
          description: 文本值或文本片段：单个文本值最多 1048576 字符，并受 4 MiB 请求体上限和模型上下文窗口约束。角色需模型能力支持。
        name:
          type: string
          maxLength: 64
        tool_call_id:
          type: string
        tool_calls:
          type: array
          maxItems: 64
          items:
            $ref: '#/components/schemas/ToolCall'
        reasoning_content:
          type: string
          description: >-
            仅在模型能力 reasoning_content 为 true 时可返回的推理文本；SSE 中位于
            choices[].delta.reasoning_content。这不是请求字段。
    RequestMetadata:
      type: object
      description: >-
        仅在请求带有 `X-Gateway-Metadata: enabled` 时出现。同时以 `gateway_metadata` 和旧名
        `omnirelay_metadata` 返回，内容相同。流式响应中随第一个数据块返回。
      properties:
        request_id:
          type: string
          description: 请求 ID，与 `X-Request-ID` 相同。
        requested:
          type: string
          description: 你请求的模型 ID。
        model:
          type: string
          description: 实际响应本次调用的模型。
        provider:
          type: string
          description: 该模型的模型服务方。
        mode:
          type: string
          enum:
            - live
          description: live 表示调用了真实模型服务方。
        strategy:
          type: string
          enum:
            - direct
          description: 模型的解析方式。目前每个模型只有一个渠道，因此恒为 `direct`。
        attempt:
          type: integer
          description: 最终响应的是第几次尝试（从 1 开始）。在支持故障转移之前恒为 1。
        attempts:
          type: array
          description: 按顺序列出的全部尝试。
          items:
            type: object
            properties:
              provider:
                type: string
              model:
                type: string
              mode:
                type: string
        tags:
          type: object
          additionalProperties:
            type: string
          description: 本次调用记录的标签；没有时为 `{}`。
        deprecated_header:
          type: string
          description: >-
            当请求同时带有旧名请求头（`X-OmniRelay-Tags` 或
            `X-OmniRelay-Metadata`）和值不同的新名请求头时出现：给出被忽略的旧请求头名。
    ToolCall:
      type: object
      required:
        - id
        - type
        - function
      properties:
        id:
          type: string
          maxLength: 128
        type:
          type: string
          enum:
            - function
        function:
          type: object
          required:
            - name
            - arguments
          properties:
            name:
              type: string
              maxLength: 64
            arguments:
              type: string
              maxLength: 65536
  responses:
    Unauthorized:
      description: '`unauthorized`：缺少 API Key，或该 Key 已吊销或无效。'
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          example:
            error:
              code: unauthorized
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      description: 在 OmniRelay 控制台创建的 API Key。所有者确认身份后可在控制台再次查看。

````

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