参考文档:https://platform.openai.com/docs/api-reference/chat/create
POST
/v1/chat/completionsweb搜索
API Key application/json
Chat Completions 兼容协议
调用与返回说明
适合已经依赖 Chat Completions 的客户端和模型。新建 OpenAI 集成时优先确认模型支持 Responses API,再决定是否使用此兼容协议。
请求时注意
- model 和 messages 是基本必填项;tools、tool_choice、response_format 等能力参数按场景发送,不是所有模型都支持。
- 模型 ID 以 GET /v1/models 的返回为准。示例中的固定模型名只是格式示例,不代表当前账号一定可用。
- 对于新推理模型,优先使用 max_completion_tokens;max_tokens 是旧字段,且可能与推理模型不兼容。
返回时注意
- 非流式文本读取 choices[0].message.content,并检查 choices[0].finish_reason。
- Chat Completions 的工具调用位于 choices[].message.tool_calls,不能与 Responses 的 output[].type=function_call 混读。
请求示例
curl -X POST https://top.qingyuntop.ai/v1/chat/completions \
-H "Authorization: Bearer ${QINGYUN_TOP_API_KEY}" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-4o-search-preview",
"web_search_options": {},
"messages": [{
"role": "user",
"content": "What was a positive news story from today?"
}]
}'请求参数
| 参数 | 位置 | 类型 | 必填 | 说明 | 示例 |
|---|---|---|---|---|---|
Authorization | Header | string | 是 | - | Bearer $OPENAI_API_KEY |
Content-type | Header | string | 是 | - | application/json |
model | JSON body | string | 是 | 必填。使用 GET /v1/models 返回的准确模型 ID。 | - |
web_search_options | JSON body | object | 是 | - | - |
messages | JSON body | array<object> | 是 | 必填。按 role 和 content 组成对话消息;多模态 content 使用该模型支持的内容块格式。 | - |
messages[].role | JSON body | string | 否 | - | - |
messages[].content | JSON body | string | 否 | - | - |
返回响应 (200)
此部分没有定义参数。
响应示例
{
"id": "chatcmpl_example",
"object": "chat.completion",
"model": "MODEL_ID_FROM_V1_MODELS",
"choices": [
{
"index": 0,
"message": {"role": "assistant", "content": "你好,我可以帮助你。"},
"finish_reason": "stop"
}
],
"usage": {"prompt_tokens": 18, "completion_tokens": 12, "total_tokens": 30}
}来源原始接口定义(用于追溯)
以下内容来自 Apifox 快照,可能包含兼容层字段或旧示例;公开调用请以本页的协议说明和当前模型列表为准。
{
"id": 497673428,
"name": "web搜索",
"type": "http",
"serverId": "",
"preProcessors": [],
"postProcessors": [],
"inheritPreProcessors": {},
"inheritPostProcessors": {},
"description": "参考文档:https://platform.openai.com/docs/api-reference/chat/create",
"operationId": "",
"sourceUrl": "",
"method": "post",
"path": "/v1/chat/completions",
"tags": [],
"status": -2,
"requestBody": {
"type": "application/json",
"parameters": [],
"jsonSchema": {
"type": "object",
"properties": {
"model": {
"type": "string"
},
"web_search_options": {
"type": "object",
"properties": {},
"x-apifox-orders": []
},
"messages": {
"type": "array",
"items": {
"type": "object",
"properties": {
"role": {
"type": "string"
},
"content": {
"type": "string"
}
},
"x-apifox-orders": [
"role",
"content"
]
}
}
},
"required": [
"model",
"web_search_options",
"messages"
],
"x-apifox-orders": [
"model",
"web_search_options",
"messages"
]
},
"examples": [
{
"mediaType": "application/json",
"value": "{\n \"model\": \"gpt-4o-search-preview\",\n \"web_search_options\": {},\n \"messages\": [{\n \"role\": \"user\",\n \"content\": \"What was a positive news story from today?\"\n }]\n }",
"name": "示例"
}
],
"mediaType": "",
"oasExtensions": "",
"required": false,
"additionalContentTypes": []
},
"parameters": {
"path": [],
"query": [],
"cookie": [],
"header": [
{
"id": "u4oxZ9wVji",
"name": "Authorization",
"required": true,
"enable": true,
"description": "",
"type": "string",
"sampleValue": "Bearer $OPENAI_API_KEY"
},
{
"id": "P8YmwpolyQ",
"name": "Content-type",
"required": true,
"enable": true,
"description": "",
"type": "string",
"sampleValue": "application/json"
}
]
},
"commonParameters": {
"query": [],
"body": [],
"cookie": [],
"header": []
},
"auth": {},
"responses": [
{
"id": 131908891,
"name": "成功",
"code": 200,
"contentType": "json",
"jsonSchema": {
"type": "object",
"properties": {},
"x-apifox-orders": []
},
"itemSchema": {},
"description": "",
"mediaType": "",
"headers": [],
"oasExtensions": ""
}
],
"responseExamples": [],
"codeSamples": [],
"projectId": 8662722,
"moduleId": 8310462,
"folderId": 92749354,
"ordering": 0,
"responsibleId": 0,
"commonResponseStatus": {},
"advancedSettings": {
"disabledSystemHeaders": {}
},
"customApiFields": {},
"oasExtensions": "",
"mockScript": {},
"createdAt": "2026-08-05T14:40:23.000Z",
"updatedAt": "2026-08-06T12:15:55.000Z",
"creatorId": 2863449,
"editorId": 2863449,
"creatorUserId": 2863449,
"editorUserId": 2863449,
"responseChildren": [
"BLANK.131908891"
],
"visibility": "INHERITED",
"securityScheme": {},
"callbacks": ""
}