切换主题
ChatCompletions格式
根据对话历史创建模型响应。支持流式和非流式响应。
兼容 OpenAI Chat Completions API。
ChatCompletions格式
POST /v1/chat/completions
根据对话历史创建模型响应。支持流式和非流式响应。
兼容 OpenAI Chat Completions API。
认证
BearerAuth
请求体
必填:是
application/json
| 字段 | 必填 | 类型 | 说明 |
|---|---|---|---|
| model | 是 | string | 模型 ID Examples: gpt-4 |
| messages | 是 | array<object> | 对话消息列表 |
| messages[].role | 否 | enum: system | user | assistant | tool | developer | 消息角色 |
| messages[].content | 否 | oneOf<string | array<object>> | 消息内容 |
| messages[].name | 否 | string | 发送者名称 |
| messages[].tool_calls | 否 | array<object> | - |
| messages[].tool_call_id | 否 | string | 工具调用 ID(用于 tool 角色消息) |
| messages[].reasoning_content | 否 | string | 推理内容 |
| temperature | 否 | number | 采样温度 Default: 1 |
| top_p | 否 | number | 核采样参数 Default: 1 |
| n | 否 | integer | 生成数量 Default: 1 |
| stream | 否 | boolean | 是否流式响应 Default: false |
| stream_options | 否 | object | - |
| stream_options.include_usage | 否 | boolean | - |
| stop | 否 | oneOf<string | array<string>> | 停止序列 |
| max_tokens | 否 | integer | 最大生成 Token 数 |
| max_completion_tokens | 否 | integer | 最大补全 Token 数 |
| presence_penalty | 否 | number | Default: 0 |
| frequency_penalty | 否 | number | Default: 0 |
| logit_bias | 否 | object | - |
| user | 否 | string | - |
| tools | 否 | array<object> | - |
| tools[].type | 否 | string | Examples: function |
| tools[].function | 否 | object | - |
| tools[].function.name | 否 | string | - |
| tools[].function.description | 否 | string | - |
| tools[].function.parameters | 否 | object | JSON Schema 格式的参数定义 |
| tool_choice | 否 | oneOf<enum: none | auto | required | object> | - |
| tool_choice.type | 否 | string | - |
| tool_choice.function | 否 | object | - |
| tool_choice.function.name | 否 | string | - |
| response_format | 否 | object | - |
| response_format.type | 否 | enum: text | json_object | json_schema | - |
| response_format.json_schema | 否 | object | JSON Schema 定义 |
| seed | 否 | integer | - |
| reasoning_effort | 否 | enum: low | medium | high | 推理强度 (用于支持推理的模型) |
| modalities | 否 | array<enum: text | audio> | - |
| audio | 否 | object | - |
| audio.voice | 否 | string | - |
| audio.format | 否 | string | - |
原始 Schema
json
{
"type": "object",
"required": [
"model",
"messages"
],
"properties": {
"model": {
"type": "string",
"description": "模型 ID",
"examples": [
"gpt-4"
]
},
"messages": {
"type": "array",
"items": {
"type": "object",
"required": [
"role",
"content"
],
"properties": {
"role": {
"type": "string",
"enum": [
"system",
"user",
"assistant",
"tool",
"developer"
],
"description": "消息角色"
},
"content": {
"oneOf": [
{
"type": "string"
},
{
"type": "array",
"items": {
"type": "object",
"properties": {
"type": {
"type": "string",
"enum": [
"text",
"image_url",
"input_audio",
"file",
"video_url"
]
},
"text": {
"type": "string"
},
"image_url": {
"type": "object",
"properties": {
"url": {
"type": "string",
"description": "图片 URL 或 base64"
},
"detail": {
"type": "string",
"enum": [
"low",
"high",
"auto"
]
}
},
"x-apifox-orders": [
"url",
"detail"
]
},
"input_audio": {
"type": "object",
"properties": {
"data": {
"type": "string",
"description": "Base64 编码的音频数据"
},
"format": {
"type": "string",
"enum": [
"wav",
"mp3"
]
}
},
"x-apifox-orders": [
"data",
"format"
]
},
"file": {
"type": "object",
"properties": {
"filename": {
"type": "string"
},
"file_data": {
"type": "string"
},
"file_id": {
"type": "string"
}
},
"x-apifox-orders": [
"filename",
"file_data",
"file_id"
]
},
"video_url": {
"type": "object",
"properties": {
"url": {
"type": "string"
}
},
"x-apifox-orders": [
"url"
]
}
},
"x-apifox-orders": [
"type",
"text",
"image_url",
"input_audio",
"file",
"video_url"
]
}
}
],
"description": "消息内容"
},
"name": {
"type": "string",
"description": "发送者名称"
},
"tool_calls": {
"type": "array",
"items": {
"type": "object",
"properties": {
"id": {
"type": "string"
},
"type": {
"type": "string",
"examples": [
"function"
]
},
"function": {
"type": "object",
"properties": {
"name": {
"type": "string"
},
"arguments": {
"type": "string"
}
},
"x-apifox-orders": [
"name",
"arguments"
]
}
},
"x-apifox-orders": [
"id",
"type",
"function"
]
}
},
"tool_call_id": {
"type": "string",
"description": "工具调用 ID(用于 tool 角色消息)"
},
"reasoning_content": {
"type": "string",
"description": "推理内容"
}
},
"x-apifox-orders": [
"role",
"content",
"name",
"tool_calls",
"tool_call_id",
"reasoning_content"
]
},
"description": "对话消息列表"
},
"temperature": {
"type": "number",
"minimum": 0,
"maximum": 2,
"default": 1,
"description": "采样温度"
},
"top_p": {
"type": "number",
"minimum": 0,
"maximum": 1,
"default": 1,
"description": "核采样参数"
},
"n": {
"type": "integer",
"minimum": 1,
"default": 1,
"description": "生成数量"
},
"stream": {
"type": "boolean",
"default": false,
"description": "是否流式响应"
},
"stream_options": {
"type": "object",
"properties": {
"include_usage": {
"type": "boolean"
}
},
"x-apifox-orders": [
"include_usage"
]
},
"stop": {
"oneOf": [
{
"type": "string"
},
{
"type": "array",
"items": {
"type": "string"
}
}
],
"description": "停止序列"
},
"max_tokens": {
"type": "integer",
"description": "最大生成 Token 数"
},
"max_completion_tokens": {
"type": "integer",
"description": "最大补全 Token 数"
},
"presence_penalty": {
"type": "number",
"minimum": -2,
"maximum": 2,
"default": 0
},
"frequency_penalty": {
"type": "number",
"minimum": -2,
"maximum": 2,
"default": 0
},
"logit_bias": {
"type": "object",
"additionalProperties": {
"type": "number"
},
"properties": {},
"x-apifox-orders": []
},
"user": {
"type": "string"
},
"tools": {
"type": "array",
"items": {
"type": "object",
"properties": {
"type": {
"type": "string",
"examples": [
"function"
]
},
"function": {
"type": "object",
"properties": {
"name": {
"type": "string"
},
"description": {
"type": "string"
},
"parameters": {
"type": "object",
"description": "JSON Schema 格式的参数定义",
"properties": {},
"x-apifox-orders": []
}
},
"x-apifox-orders": [
"name",
"description",
"parameters"
]
}
},
"x-apifox-orders": [
"type",
"function"
]
}
},
"tool_choice": {
"oneOf": [
{
"type": "string",
"enum": [
"none",
"auto",
"required"
]
},
{
"type": "object",
"properties": {
"type": {
"type": "string"
},
"function": {
"type": "object",
"properties": {
"name": {
"type": "string"
}
},
"x-apifox-orders": [
"name"
]
}
},
"x-apifox-orders": [
"type",
"function"
]
}
]
},
"response_format": {
"type": "object",
"properties": {
"type": {
"type": "string",
"enum": [
"text",
"json_object",
"json_schema"
]
},
"json_schema": {
"type": "object",
"description": "JSON Schema 定义",
"properties": {},
"x-apifox-orders": []
}
},
"x-apifox-orders": [
"type",
"json_schema"
]
},
"seed": {
"type": "integer"
},
"reasoning_effort": {
"type": "string",
"enum": [
"low",
"medium",
"high"
],
"description": "推理强度 (用于支持推理的模型)"
},
"modalities": {
"type": "array",
"items": {
"type": "string",
"enum": [
"text",
"audio"
]
}
},
"audio": {
"type": "object",
"properties": {
"voice": {
"type": "string"
},
"format": {
"type": "string"
}
},
"x-apifox-orders": [
"voice",
"format"
]
}
},
"x-apifox-orders": [
"model",
"messages",
"temperature",
"top_p",
"n",
"stream",
"stream_options",
"stop",
"max_tokens",
"max_completion_tokens",
"presence_penalty",
"frequency_penalty",
"logit_bias",
"user",
"tools",
"tool_choice",
"response_format",
"seed",
"reasoning_effort",
"modalities",
"audio"
]
}响应
200 成功创建响应
application/json
| 字段 | 必填 | 类型 | 说明 |
|---|---|---|---|
| id | 否 | string | - |
| object | 否 | string | Examples: chat.completion |
| created | 否 | integer | - |
| model | 否 | string | - |
| choices | 否 | array<object> | - |
| choices[].index | 否 | integer | - |
| choices[].message | 否 | object | - |
| choices[].message.role | 是 | enum: system | user | assistant | tool | developer | 消息角色 |
| choices[].message.content | 是 | oneOf<string | array<object>> | 消息内容 |
| choices[].message.name | 否 | string | 发送者名称 |
| choices[].message.tool_calls | 否 | array<object> | - |
| choices[].message.tool_call_id | 否 | string | 工具调用 ID(用于 tool 角色消息) |
| choices[].message.reasoning_content | 否 | string | 推理内容 |
| choices[].finish_reason | 否 | enum: stop | length | tool_calls | content_filter | - |
| usage | 否 | object | - |
| usage.prompt_tokens | 否 | integer | 提示词 Token 数 |
| usage.completion_tokens | 否 | integer | 补全 Token 数 |
| usage.total_tokens | 否 | integer | 总 Token 数 |
| usage.prompt_tokens_details | 否 | object | - |
| usage.prompt_tokens_details.cached_tokens | 否 | integer | - |
| usage.prompt_tokens_details.text_tokens | 否 | integer | - |
| usage.prompt_tokens_details.audio_tokens | 否 | integer | - |
| usage.prompt_tokens_details.image_tokens | 否 | integer | - |
| usage.completion_tokens_details | 否 | object | - |
| usage.completion_tokens_details.text_tokens | 否 | integer | - |
| usage.completion_tokens_details.audio_tokens | 否 | integer | - |
| usage.completion_tokens_details.reasoning_tokens | 否 | integer | - |
| system_fingerprint | 否 | string | - |
原始 Schema
json
{
"type": "object",
"properties": {
"id": {
"type": "string"
},
"object": {
"type": "string",
"examples": [
"chat.completion"
]
},
"created": {
"type": "integer"
},
"model": {
"type": "string"
},
"choices": {
"type": "array",
"items": {
"type": "object",
"properties": {
"index": {
"type": "integer"
},
"message": {
"type": "object",
"required": [
"role",
"content"
],
"properties": {
"role": {
"type": "string",
"enum": [
"system",
"user",
"assistant",
"tool",
"developer"
],
"description": "消息角色"
},
"content": {
"oneOf": [
{
"type": "string"
},
{
"type": "array",
"items": {
"type": "object",
"properties": {
"type": {
"type": "string",
"enum": [
"text",
"image_url",
"input_audio",
"file",
"video_url"
]
},
"text": {
"type": "string"
},
"image_url": {
"type": "object",
"properties": {
"url": {
"type": "string",
"description": "图片 URL 或 base64"
},
"detail": {
"type": "string",
"enum": [
"low",
"high",
"auto"
]
}
},
"x-apifox-orders": [
"url",
"detail"
]
},
"input_audio": {
"type": "object",
"properties": {
"data": {
"type": "string",
"description": "Base64 编码的音频数据"
},
"format": {
"type": "string",
"enum": [
"wav",
"mp3"
]
}
},
"x-apifox-orders": [
"data",
"format"
]
},
"file": {
"type": "object",
"properties": {
"filename": {
"type": "string"
},
"file_data": {
"type": "string"
},
"file_id": {
"type": "string"
}
},
"x-apifox-orders": [
"filename",
"file_data",
"file_id"
]
},
"video_url": {
"type": "object",
"properties": {
"url": {
"type": "string"
}
},
"x-apifox-orders": [
"url"
]
}
},
"x-apifox-orders": [
"type",
"text",
"image_url",
"input_audio",
"file",
"video_url"
]
}
}
],
"description": "消息内容"
},
"name": {
"type": "string",
"description": "发送者名称"
},
"tool_calls": {
"type": "array",
"items": {
"type": "object",
"properties": {
"id": {
"type": "string"
},
"type": {
"type": "string",
"examples": [
"function"
]
},
"function": {
"type": "object",
"properties": {
"name": {
"type": "string"
},
"arguments": {
"type": "string"
}
},
"x-apifox-orders": [
"name",
"arguments"
]
}
},
"x-apifox-orders": [
"id",
"type",
"function"
]
}
},
"tool_call_id": {
"type": "string",
"description": "工具调用 ID(用于 tool 角色消息)"
},
"reasoning_content": {
"type": "string",
"description": "推理内容"
}
},
"x-apifox-orders": [
"role",
"content",
"name",
"tool_calls",
"tool_call_id",
"reasoning_content"
]
},
"finish_reason": {
"type": "string",
"enum": [
"stop",
"length",
"tool_calls",
"content_filter"
]
}
},
"x-apifox-orders": [
"index",
"message",
"finish_reason"
]
}
},
"usage": {
"type": "object",
"properties": {
"prompt_tokens": {
"type": "integer",
"description": "提示词 Token 数"
},
"completion_tokens": {
"type": "integer",
"description": "补全 Token 数"
},
"total_tokens": {
"type": "integer",
"description": "总 Token 数"
},
"prompt_tokens_details": {
"type": "object",
"properties": {
"cached_tokens": {
"type": "integer"
},
"text_tokens": {
"type": "integer"
},
"audio_tokens": {
"type": "integer"
},
"image_tokens": {
"type": "integer"
}
},
"x-apifox-orders": [
"cached_tokens",
"text_tokens",
"audio_tokens",
"image_tokens"
]
},
"completion_tokens_details": {
"type": "object",
"properties": {
"text_tokens": {
"type": "integer"
},
"audio_tokens": {
"type": "integer"
},
"reasoning_tokens": {
"type": "integer"
}
},
"x-apifox-orders": [
"text_tokens",
"audio_tokens",
"reasoning_tokens"
]
}
},
"x-apifox-orders": [
"prompt_tokens",
"completion_tokens",
"total_tokens",
"prompt_tokens_details",
"completion_tokens_details"
]
},
"system_fingerprint": {
"type": "string"
}
},
"x-apifox-orders": [
"id",
"object",
"created",
"model",
"choices",
"usage",
"system_fingerprint"
]
}400 请求参数错误
application/json
| 字段 | 必填 | 类型 | 说明 |
|---|---|---|---|
| error | 否 | object | - |
| error.message | 否 | string | 错误信息 |
| error.type | 否 | string | 错误类型 |
| error.param | 否 | string | null | 相关参数 |
| error.code | 否 | string | null | 错误代码 |
原始 Schema
json
{
"type": "object",
"properties": {
"error": {
"type": "object",
"properties": {
"message": {
"type": "string",
"description": "错误信息"
},
"type": {
"type": "string",
"description": "错误类型"
},
"param": {
"type": [
"string",
"null"
],
"description": "相关参数"
},
"code": {
"type": [
"string",
"null"
],
"description": "错误代码"
}
},
"x-apifox-orders": [
"message",
"type",
"param",
"code"
]
}
},
"x-apifox-orders": [
"error"
]
}429 请求频率限制
application/json
| 字段 | 必填 | 类型 | 说明 |
|---|---|---|---|
| error | 否 | object | - |
| error.message | 否 | string | 错误信息 |
| error.type | 否 | string | 错误类型 |
| error.param | 否 | string | null | 相关参数 |
| error.code | 否 | string | null | 错误代码 |
原始 Schema
json
{
"type": "object",
"properties": {
"error": {
"type": "object",
"properties": {
"message": {
"type": "string",
"description": "错误信息"
},
"type": {
"type": "string",
"description": "错误类型"
},
"param": {
"type": [
"string",
"null"
],
"description": "相关参数"
},
"code": {
"type": [
"string",
"null"
],
"description": "错误代码"
}
},
"x-apifox-orders": [
"message",
"type",
"param",
"code"
]
}
},
"x-apifox-orders": [
"error"
]
}