API 手册
Responses API
OpenAI Responses 接口:创建、查询、取消和删除响应
Responses API 是 OpenAI 新版响应结构,适合希望使用统一 input、工具调用、后台任务或后续扩展能力的项目。
接口概览
| 能力 | 方法 | 路径 |
|---|---|---|
| 创建响应 | POST | /v1/responses |
| 获取响应 | GET | /v1/responses/{response_id} |
| 取消响应 | POST | /v1/responses/{response_id}/cancel |
| 删除响应 | DELETE | /v1/responses/{response_id} |
所有接口都使用:
Authorization: Bearer $API_KEY创建响应
请求体
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
model | string | 是 | 模型名称,例如 gpt-5.1 |
input | string | array | 是 | 用户输入;简单场景可以直接传字符串 |
instructions | string | 否 | 系统或开发者指令 |
stream | boolean | 否 | 是否流式返回 |
background | boolean | 否 | 是否后台运行响应 |
previous_response_id | string | 否 | 上一轮响应 ID,用于延续上下文 |
tools | array | 否 | 工具定义 |
tool_choice | string | object | 否 | 工具调用策略 |
text | object | 否 | 文本输出配置,可用于结构化输出 |
reasoning | object | 否 | 推理模型配置 |
temperature | number | 否 | 随机性 |
top_p | number | 否 | 核采样参数 |
max_output_tokens | integer | 否 | 最大输出 token 数 |
store | boolean | 否 | 是否存储响应以便后续查询 |
truncation | string | 否 | 截断策略,disabled 或 auto |
请求示例
curl https://cdn.12ai.org/v1/responses \
-H "Authorization: Bearer $API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-5.1",
"input": "写一个三行以内的产品更新公告"
}'from openai import OpenAI
client = OpenAI(
api_key="sk-xxx",
base_url="https://cdn.12ai.org/v1",
)
response = client.responses.create(
model="gpt-5.1",
instructions="你是一个简洁的产品文案助手。",
input="写一个三行以内的产品更新公告",
)
print(response.output_text)多模态输入
Responses API 的 input 可以传字符串,也可以传消息数组。文本、图片、文件分别使用 input_text、input_image、input_file。
{
"model": "gpt-5.1",
"input": [
{
"role": "user",
"content": [
{"type": "input_text", "text": "描述这张图片"},
{
"type": "input_image",
"image_url": "https://example.com/image.jpg"
}
]
}
]
}查询响应
curl https://cdn.12ai.org/v1/responses/resp_xxx \
-H "Authorization: Bearer $API_KEY"取消响应
curl -X POST https://cdn.12ai.org/v1/responses/resp_xxx/cancel \
-H "Authorization: Bearer $API_KEY"删除响应
curl -X DELETE https://cdn.12ai.org/v1/responses/resp_xxx \
-H "Authorization: Bearer $API_KEY"响应结构
| 字段 | 类型 | 说明 |
|---|---|---|
id | string | 响应 ID,用于查询、取消或删除 |
object | string | 对象类型,通常为 response |
status | string | completed、in_progress、failed 等 |
model | string | 实际调用的模型 |
output | array | 输出内容数组 |
previous_response_id | string | 上一轮响应 ID,可能为空 |
instructions | string | 本次响应使用的指令,可能为空 |
tools | array | 本次请求可用工具 |
tool_choice | string | object | 工具选择策略 |
text | object | 文本输出配置 |
truncation | string | 截断策略 |
usage | object | token 用量统计 |
响应示例
{
"id": "resp_xxx",
"object": "response",
"created_at": 1760000000,
"status": "completed",
"model": "gpt-5.1",
"output": [
{
"type": "message",
"role": "assistant",
"content": [
{
"type": "output_text",
"text": "本周我们优化了接口稳定性,并新增了更清晰的错误提示。"
}
]
}
],
"usage": {
"input_tokens": 18,
"output_tokens": 24,
"total_tokens": 42
}
}选型建议
| 场景 | 建议 |
|---|---|
| 兼容老客户端 | 使用 Chat Completions |
| 新项目自己写代码 | 可以优先使用 Responses API |
已经依赖 OpenAI SDK 的 responses | 直接把 base_url 改为 https://cdn.12ai.org/v1 |
