Appearance
ChatCompletions格式
ChatCompletions格式
POST/v1/chat/completions根据对话历史创建模型响应。支持流式和非流式响应。
兼容 OpenAI Chat Completions API。
请求头 (Headers)
| 参数名 | 类型 | 必选 | 描述 | 示例 |
|---|---|---|---|---|
Authorization | string | 否 | 鉴权令牌 | Bearer ******************** |
请求体 (Request Body)
Content-Type: application/json
| 字段 | 类型 | 必选 | 描述 |
|---|---|---|---|
| model | string | 是 | 模型 ID |
| messages | array of any | 是 | 对话消息列表 |
| temperature | number | 否 | 采样温度 |
| top_p | number | 否 | 核采样参数 |
| n | integer | 否 | 生成数量 |
| stream | boolean | 否 | 是否流式响应 |
| stream_options | object | 否 | |
| stream_options.include_usage | boolean | 否 | |
| stop | any | 否 | 停止序列 |
| max_tokens | integer | 否 | 最大生成 Token 数 |
| max_completion_tokens | integer | 否 | 最大补全 Token 数 |
| presence_penalty | number | 否 | |
| frequency_penalty | number | 否 | |
| logit_bias | object | 否 | |
| user | string | 否 | |
| tools | array of any | 否 | |
| tool_choice | any | 否 | |
| response_format | any | 否 | |
| seed | integer | 否 | |
| reasoning_effort | string | 否 | 推理强度 (用于支持推理的模型) |
| modalities | array of string | 否 | |
| audio | object | 否 | |
| audio.voice | string | 否 | |
| audio.format | string | 否 |
请求体示例
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 - 成功创建响应
| 字段 | 类型 | 描述 |
|---|---|---|
| id | string | |
| object | string | |
| created | integer | |
| model | string | |
| choices | array of object | |
| choices[].index | integer | |
| choices[].message | any | |
| choices[].finish_reason | string | |
| usage | any | |
| system_fingerprint | string |
响应示例
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 - 请求参数错误
| 字段 | 类型 | 描述 |
|---|---|---|
| error | object | |
| error.message | string | 错误信息 |
| error.type | string | 错误类型 |
| error.param | string (nullable) | 相关参数 |
| error.code | string (nullable) | 错误代码 |
响应示例
json
{
"error": {
"message": "string",
"type": "string",
"param": "string",
"code": "string"
}
}429 - 请求频率限制
| 字段 | 类型 | 描述 |
|---|---|---|
| error | object | |
| error.message | string | 错误信息 |
| error.type | string | 错误类型 |
| error.param | string (nullable) | 相关参数 |
| error.code | string (nullable) | 错误代码 |
响应示例
json
{
"error": {
"message": "string",
"type": "string",
"param": "string",
"code": "string"
}
}