Responses API
Responses API 是 OpenAI 推出的全新一元化、有状态(Stateful)的智能体级 API 接口。它结合了传统聊天补全(Chat Completions)和助手(Assistants)的优势,并专门优化了工具链交互、推理模型(如 o3 系列)的思维链追踪以及上下文管理。
POST /v1/responses| 参数 | 类型 | 必填 | 默认值 | 说明 |
|---|---|---|---|---|
model | string | ✅ | - | 调用的模型 ID(例如 gpt-4o, o3)。 |
input | array | string | ✅ | - | 用户的输入。可以是简单的字符串或复杂的多模态消息对象数组。 |
instructions | string | ❌ | - | 系统指令或角色提示词。 |
conversation | string | ❌ | - | 关联的服务器端持久化对话状态 ID。如果传入,则支持免传输历史记录的状态对话。 |
previous_response_id | string | ❌ | - | 前一个响应的 ID。通过该参数实现无状态上下文链。 |
store | boolean | ❌ | true | 是否让服务器持久化该次交互数据。 |
tools | array | ❌ | - | 声明允许模型调用的外部工具集合(如代码沙箱、网页搜索等)。 |
cURL 请求
Section titled “cURL 请求”curl https://api.easytakeai.com/v1/responses \ -H "Content-Type: application/json" \ -H "Authorization: Bearer YOUR_API_KEY" \ -d '{ "model": "gpt-4o", "input": [ { "role": "user", "content": [ { "type": "text", "text": "简述 Responses API 和 Chat Completions 的核心区别。" } ] } ], "store": true }'JSON 响应示例
Section titled “JSON 响应示例”{ "id": "resp_9x8y7z", "object": "response", "created": 1716298540, "model": "gpt-4o", "output": [ { "type": "text", "text": "Responses API 的核心区别在于:1. 具有原生有状态会话管理(通过 conversation 和 previous_response_id);2. 输出由 choices 改为结构化的 output 列表;3. 对 Agent 长任务和思维链推理的天然支持。" } ], "usage": { "prompt_tokens": 20, "completion_tokens": 98, "total_tokens": 118 }}