Skip to content

ChatCompletions格式

ChatCompletions格式

POST /v1/chat/completions

根据对话历史创建模型响应。支持流式和非流式响应。

兼容 OpenAI Chat Completions API。

请求头 (Headers)

参数名类型必选描述示例
Authorizationstring鉴权令牌Bearer ********************

请求体 (Request Body)

Content-Type: application/json

字段类型必选描述
modelstring模型 ID
messagesarray of any对话消息列表
temperaturenumber采样温度
top_pnumber核采样参数
ninteger生成数量
streamboolean是否流式响应
stream_optionsobject
stream_options.include_usageboolean
stopany停止序列
max_tokensinteger最大生成 Token 数
max_completion_tokensinteger最大补全 Token 数
presence_penaltynumber
frequency_penaltynumber
logit_biasobject
userstring
toolsarray of any
tool_choiceany
response_formatany
seedinteger
reasoning_effortstring推理强度 (用于支持推理的模型)
modalitiesarray of string
audioobject
audio.voicestring
audio.formatstring

请求体示例

json
{
  "model": "gpt-4",
  "messages": [
    {
      "role": "string",
      "content": null,
      "name": "string",
      "tool_calls": [
        {
          "id": "string",
          "type": "function",
          "function": {
            "name": "string",
            "arguments": "string"
          }
        }
      ],
      "tool_call_id": "string",
      "reasoning_content": "string"
    }
  ],
  "temperature": 0,
  "top_p": 0,
  "n": 0,
  "stream": true,
  "stream_options": {
    "include_usage": true
  },
  "stop": null,
  "max_tokens": 0,
  "max_completion_tokens": 0,
  "presence_penalty": 0,
  "frequency_penalty": 0,
  "logit_bias": {},
  "user": "string",
  "tools": [
    {
      "type": "function",
      "function": {
        "name": "string",
        "description": "string",
        "parameters": {}
      }
    }
  ],
  "tool_choice": null,
  "response_format": {
    "type": "string",
    "json_schema": {}
  },
  "seed": 0,
  "reasoning_effort": "string",
  "modalities": [
    "string"
  ],
  "audio": {
    "voice": "string",
    "format": "string"
  }
}

返回响应 (Responses)

200 - 成功创建响应

字段类型描述
idstring
objectstring
createdinteger
modelstring
choicesarray of object
choices[].indexinteger
choices[].messageany
choices[].finish_reasonstring
usageany
system_fingerprintstring

响应示例

json
{
  "id": "string",
  "object": "chat.completion",
  "created": 0,
  "model": "string",
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "string",
        "content": null,
        "name": "string",
        "tool_calls": [
          {
            "id": "string",
            "type": "function",
            "function": {
              "name": "string",
              "arguments": "string"
            }
          }
        ],
        "tool_call_id": "string",
        "reasoning_content": "string"
      },
      "finish_reason": "string"
    }
  ],
  "usage": {
    "prompt_tokens": 0,
    "completion_tokens": 0,
    "total_tokens": 0,
    "prompt_tokens_details": {
      "cached_tokens": 0,
      "text_tokens": 0,
      "audio_tokens": 0,
      "image_tokens": 0
    },
    "completion_tokens_details": {
      "text_tokens": 0,
      "audio_tokens": 0,
      "reasoning_tokens": 0
    }
  },
  "system_fingerprint": "string"
}

400 - 请求参数错误

字段类型描述
errorobject
error.messagestring错误信息
error.typestring错误类型
error.paramstring (nullable)相关参数
error.codestring (nullable)错误代码

响应示例

json
{
  "error": {
    "message": "string",
    "type": "string",
    "param": "string",
    "code": "string"
  }
}

429 - 请求频率限制

字段类型描述
errorobject
error.messagestring错误信息
error.typestring错误类型
error.paramstring (nullable)相关参数
error.codestring (nullable)错误代码

响应示例

json
{
  "error": {
    "message": "string",
    "type": "string",
    "param": "string",
    "code": "string"
  }
}

Released under the MIT License.