跳到主要内容

Responses 格式

使用 OpenAI Responses API(响应接口)的请求和响应结构调用对话模型。它与 Chat Completions 是两种独立的接口格式:Responses 使用 input,返回 output;Chat Completions 使用 messages,返回 choices。

请求​

POST /v1/responses
Content-Type: application/json
Authorization: Bearer sk-your-api-key

调用示例​

curl -X POST "https://www.walmind.cn/v1/responses" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $API_KEY" \
-d '{
"model": "your-model-id",
"instructions": "你是一个有帮助的助手。",
"input": "解释一下什么是向量数据库。",
"stream": false
}'

常用参数​

参数类型说明
modelstring模型列表中的模型 ID,必填
inputstring 或 array用户输入,可以是文本或结构化消息,必填
instructionsstring对模型的高层指令
streamboolean是否使用 SSE 流式响应,默认 false
temperaturenumber输出随机性;是否可用取决于模型和渠道
toolsarray工具定义;只有支持工具调用的模型可用

非流式响应​

{
"id": "resp_example",
"object": "response",
"status": "completed",
"output": [
{
"type": "message",
"role": "assistant",
"content": [
{"type": "output_text", "text": "向量数据库用于存储和检索向量表示。"}
]
}
],
"usage": {"input_tokens": 20, "output_tokens": 18, "total_tokens": 38}
}

不同模型的输出项可能包含工具调用、推理摘要或其他内容类型。解析时应根据 output[].type 判断,不要假设数组中永远只有一段文本。

流式响应​

设置 stream: true 后,响应使用 text/event-stream 返回事件。客户端应持续读取事件并根据事件类型拼接文本;不要把 Responses 流直接当作一次完整 JSON 解析。调试连接时可以先关闭流式输出。

与 Chat Completions 的区别​

项目Responses 格式Chat Completions 格式
路径/v1/responses/v1/chat/completions
输入字段input、instructionsmessages
文本输出output[].content[].text 或 SDK 的 output_textchoices[].message.content
SDK 调用client.responses.create(...)client.chat.completions.create(...)

两种格式不能只替换路径后混用字段。请确认模型和渠道已开通对应接口,再按页面中的请求示例调用。