通用开放接口文本 API
POST /v1/responses
POST
/v1/responsesResponses 对话接口,支持多轮对话、工具调用、推理等。
鉴权:Bearer Token
Content-Type:application/json
请求体
{ "model": "gpt-4o", "input": [ { "role": "user", "content": [ { "type": "input_text", "text": "Explain quantum computing in one sentence." } ] } ], "temperature": 0.7, "max_output_tokens": 1024, "stream": false}请求字段
| 字段 | 类型 | 必填 | 说明 |
|---|---|---|---|
model | string | 是 | 模型 ID |
input | string / array | 是 | 输入内容;可为字符串或消息数组 |
instructions | string | 否 | 系统指令 |
temperature | number | 否 | 采样温度 |
max_output_tokens | integer | 否 | 最大输出 Token 数 |
stream | boolean | 否 | 是否流式 |
tools | array | 否 | 工具定义 |
tool_choice | string / object | 否 | 工具选择策略 |
previous_response_id | string | 否 | 上一轮响应 ID,用于多轮对话 |
store | boolean | 否 | 是否存储对话 |
metadata | object | 否 | 自定义元数据 |
请求示例(curl)
非流式:
curl https://www.yunsell.com/v1/responses \ -H "Authorization: Bearer sk-xxx" \ -H "Content-Type: application/json" \ -d '{ "model": "gpt-4o", "input": [ { "role": "user", "content": [ {"type": "input_text", "text": "Explain quantum computing in one sentence."} ] } ], "temperature": 0.7, "max_output_tokens": 1024, "stream": false }'流式(SSE):
curl -N https://www.yunsell.com/v1/responses \ -H "Authorization: Bearer sk-xxx" \ -H "Content-Type: application/json" \ -d '{ "model": "gpt-4o", "input": "Hello", "stream": true }'响应体(非流式)
HTTP 200
{ "id": "resp_abc123", "object": "response", "created_at": 1712697600, "status": "completed", "model": "gpt-4o", "output": [ { "type": "message", "id": "msg_abc123", "status": "completed", "role": "assistant", "content": [ { "type": "output_text", "text": "Quantum computing uses quantum bits that can exist in superposition to perform certain calculations exponentially faster than classical computers.", "annotations": [] } ] } ], "usage": { "input_tokens": 15, "output_tokens": 28, "total_tokens": 43 }, "temperature": 0.7, "top_p": 1.0}响应字段
| 字段 | 类型 | 说明 |
|---|---|---|
id | string | 响应 ID,如 resp_xxx |
object | string | 固定为 response |
created_at | integer | Unix 时间戳(秒) |
status | string | 响应状态,见下表 |
model | string | 使用的模型 |
output | array | 输出项列表 |
output[].type | string | 输出类型,见下表 |
output[].id | string | 输出项 ID |
output[].status | string | 输出项状态 |
output[].role | string | 角色(message 类型时为 assistant) |
output[].content | array | 内容块列表 |
output[].content[].type | string | 内容类型,如 output_text |
output[].content[].text | string | 文本内容 |
output[].content[].annotations | array | 注释/引用列表 |
output[].call_id | string | 工具调用 ID(function_call 类型) |
output[].name | string | 函数名(function_call 类型) |
output[].arguments | string / object | 函数参数(function_call 类型) |
output[].quality | string | 图像质量(image_generation_call 类型) |
output[].size | string | 图像尺寸(image_generation_call 类型) |
instructions | string | 系统指令(回显) |
temperature | number | 采样温度(回显) |
top_p | number | 核采样(回显) |
max_output_tokens | integer | 最大输出 Token(回显) |
previous_response_id | string | 上一轮响应 ID |
parallel_tool_calls | boolean | 是否并行工具调用 |
store | boolean | 是否存储对话 |
metadata | object | 自定义元数据 |
incomplete_details.reason | string | 未完成原因(status=incomplete 时) |
error | object | 错误信息(status=failed 时) |
usage | object | Token 用量,见 公共响应对象 |
status 取值:
| 值 | 说明 |
|---|---|
completed | 生成完成 |
in_progress | 生成中 |
failed | 生成失败 |
incomplete | 因 Token 上限等原因未完成 |
output[].type 取值:
| 值 | 说明 |
|---|---|
message | 助手文本消息 |
function_call | 函数/工具调用 |
image_generation_call | 图像生成调用 |
web_search_call | 联网搜索调用 |
响应体(流式)
HTTP 200,Content-Type: text/event-stream
data: {"type":"response.created","response":{"id":"resp_abc123","object":"response","status":"in_progress"}}data: {"type":"response.output_text.delta","delta":"Quantum","output_index":0,"content_index":0}data: {"type":"response.output_text.delta","delta":" computing","output_index":0,"content_index":0}data: {"type":"response.completed","response":{"id":"resp_abc123","status":"completed","usage":{"input_tokens":15,"output_tokens":28,"total_tokens":43}}}data: [DONE]流式事件字段
| 字段 | 类型 | 说明 |
|---|---|---|
type | string | 事件类型,见下表 |
response | object | 完整或部分响应对象 |
delta | string | 增量文本 |
output_index | integer | 输出项索引 |
content_index | integer | 内容块索引 |
item | object | 新增/完成的输出项 |
item_id | string | 输出项 ID |
part | object | 推理摘要片段 |
常见 type 取值:
| 值 | 说明 |
|---|---|
response.created | 响应创建 |
response.output_text.delta | 文本增量 |
response.output_item.added | 新增输出项 |
response.output_item.done | 输出项完成 |
response.function_call_arguments.delta | 函数参数增量 |
response.function_call_arguments.done | 函数参数完成 |
response.completed | 响应完成 |