门户首页
API Reference · 附录

OpenAI Responses API · Schema 完整参考

POST /v1/responses 的完整 schema 参考——Responses 是 OpenAI 调用其模型 API(Application Programming Interface,应用程序接口)的新一代对话协议。以下内容从 platform.openai.com/docs/api-reference/responses 浓缩,每个字段都给出类型、是否必填、默认值、用途说明。 Responses 是 OpenAI 2025.03 起的新一代协议,GPT-5 起新模型只在它上提供,Chat Completions 进入维护模式。 与 Chat Completions 的三大差异:① 判别联合 item(工具调用升级为一等公民)② 服务端状态(previous_response_id)③ 推理链可加密续接(reasoning.encrypted_content)。

生成时间:2026-09-02 19:30 · 版本 v0.2 · 生成 Agent:MiniMax Code (LLM: MiniMax-M3) · 载体:agentsoft-research-platform teaching-web-platform

概览

1
HTTP 端点
~20
请求字段
5
item 类型
9
流式事件
项目说明
本卡定位附录页 · 字段全、说明全,适合查阅
覆盖范围OpenAI Responses API(2025.03 起)
权威来源platform.openai.com/docs/api-reference/responses
与 Chat 的关系新项目对接 OpenAI 新模型用 Responses;跨厂商兼容仍走 Chat Completions
教学版llm-api-schema-reference.html 第二篇(含 3 张教学卡 + Schema 全景)
为什么有 Responses:Chat Completions 在长程 Agent 里"无状态全量回放"成本线性膨胀;Responses 让你只发增量(previous_response_id 服务端续接),工具调用升级为一等 item(不再是 message 的附属字段),推理链可加密回传服务端续接推理。这是 OpenAI 应对"Agent 时代"的协议演进。

1. 端点与认证

HTTP 调用
POST https://api.openai.com/v1/responses
Authorization: Bearer <OPENAI_API_KEY>
Content-Type: application/json
与 Chat Completions 的端点差异
项目Chat CompletionsResponses
URL/v1/chat/completions/v1/responses
认证头Authorization: Bearer相同
对话载体messages: MessageParam[]input: string | ResponseItem[](更灵活,允许纯字符串)
系统指令messages[0].role="system"instructions(顶层,不进 input)
状态管理无状态(全量回放)有状态(previous_response_id 服务端续接)
工具定义tools: [{type:"function", function:{...}}] 两层tools: [{type:"function", name, parameters}] 扁平
推理控制reasoning_effort(顶层枚举)reasoning: {effort, summary}(嵌套对象,更细粒度)

2. 请求对象 ResponseRequest

完整 TypeScript 类型
type ResponseRequest = {
  // —— 必填 ——
  model: string,                          // "gpt-5" / "o3" / "o4-mini" / "gpt-4.1" ...
  input: string | ResponseItem[],         // ★ 直接传字符串也合法(极简入口)

  // —— 系统指令(顶层,不进 input)——
  instructions?: string,

  // —— 长度控制 ——
  max_output_tokens?: number,
  truncation?: "auto" | "disabled",      // 中点截断策略

  // —— 采样 ——
  temperature?: number,                   // [0, 2],默认 1.0
  top_p?: number,

  // —— 状态管理(与 Chat 的最大区别)——
  previous_response_id?: string,          // ★ 服务端续接上一轮,只发增量
  store?: boolean,                        // 服务端存储响应(默认 true)
  conversation?: string,                  // 会话对象 ID(更高级的状态原语)
  metadata?: Record<string, string>,     // 自定义元信息

  // —— 工具(扁平化 + 内置托管工具)——
  tools?: (FunctionTool | WebSearchTool | FileSearchTool
         | CodeInterpreterTool | McpTool)[],
  tool_choice?: "auto" | "none" | "required",   // 注意:没有"强制调某函数"形式
  parallel_tool_calls?: boolean,

  // —— 推理控制(GPT-5 / o 系列推理模型专属)——
  reasoning?: {
    effort?: "minimal" | "low" | "medium" | "high",
    summary?: "auto" | "concise" | "detailed"
  },

  // —— 输出格式 ——
  text?: { format: { type: "text" }
                | { type: "json_object" }
                | { type: "json_schema", name, schema, strict? } },

  // —— 流式 ——
  stream?: boolean,

  // —— 惩罚与微调 ——
  top_logprobs?: number,                  // [0, 20]
  user?: string,                          // 终端用户标识
  safety_identifier?: string              // 安全追踪 ID
}

// 工具类型(FunctionTool 是其中一种)
type FunctionTool = {
  type: "function",
  name: string,                            // ★ 扁平!无 function 包装层
  description?: string,
  parameters?: JSONSchema,
  strict?: boolean
}
请求字段表
字段必填类型默认值说明
model★string—模型 ID。新模型(GPT-5 / o3)只在 Responses 提供
input★string | Item[]—对话载体。字符串极简入口("input": "hi" 也合法)或判别联合 item 数组
instructions—stringnull系统指令。顶层参数,不进 input。相当于 Chat 的 role:"system" 消息但更清晰
max_output_tokens—numberinfinity最大生成 token 数。命名是 output_(区别于 Chat 的 completion_)
truncation—"auto" | "disabled""disabled"中点截断策略。"auto" 在达到 max_output_tokens 时从中间砍掉最旧消息
temperature—number [0, 2]1.0采样温度
top_p—number (0, 1]1.0nucleus 采样
previous_response_id—stringnull★ 服务端续接上一轮响应。传这个就不需要重发 history(也可继续手动传 input)
store—booleantrue是否服务端存储响应。false = 纯无状态模式(不再能与 previous_response_id 配合)
conversation—stringnull会话对象 ID(更高级的状态原语,多轮可挂同一会话)
metadata—Record<string, string>null自定义元信息键值对,16 个 key 限制
tools—(Tool)[]null工具定义数组。5 种 type 变体:function / web_search / file_search / code_interpreter / mcp
tool_choice—enum"auto""auto" / "none" / "required"。注意:没有"强制调某函数"形式(Chat 有)
parallel_tool_calls—booleantrue是否允许并行工具调用
reasoning.effort—enum"medium"推理强度。"minimal"(GPT-5 新增,最快)/ "low" / "medium" / "high"
reasoning.summary—enum"auto"推理摘要详细度。"auto" / "concise" / "detailed"
text.format—object{type:"text"}输出格式。3 种 type:"text" / "json_object" / "json_schema"
stream—booleanfalse是否流式(类型化事件流,非同构 chunk)
top_logprobs—number [0, 20]0返回 top N 候选 token 对数概率
user—stringnull终端用户标识
safety_identifier—stringnull应用级安全追踪 ID(OpenAI 用于检测滥用)

3. Input/Output Item 判别联合

与 Chat "扁平 message + 可选 tool_calls" 不同,Responses 把所有参与者建模为判别联合 item。每个 item 有 type 字段决定其形状。

5 种 item 类型一览
type用途出现位置关键字段
message文本消息input / output 均可role + content
function_call工具调用(一等 item)outputcall_id + name + arguments
function_call_output工具结果回填input(与 function_call 配对)call_id + output
reasoning推理链input / output 均可summary[] + encrypted_content
item_reference引用既有 iteminput(免重传)id
flowchart TB U["ResponseItem 判别联合
type 字段决定形状"] U --> M["message
文本消息(role + content)
input / output 均可"] U --> FC["function_call
工具调用一等 item
call_id + name + arguments"] U --> FCO["function_call_output
工具结果回填(无 role)
call_id + output"] U --> RS["reasoning
推理链 item
summary + encrypted_content"] U --> IR["item_reference
引用既有 item 免重传
仅 id"]
图 1 · ResponseItem 判别联合:5 种 item type 一览
完整类型定义
type ResponseItem =
  | { type: "message",
      role: "user" | "assistant" | "system" | "developer",
      content: string | ContentPart[] }

  | { type: "function_call",                // ★ 工具调用是一等 item
      call_id: string,                      // ★ 命名从 id → call_id
      name: string,
      arguments: string }

  | { type: "function_call_output",         // ★ 工具结果也是一等 item(无 role 概念)
      call_id: string,
      output: string }

  | { type: "reasoning",                    // ★ 推理链 item
      summary?: SummaryPart[],
      encrypted_content?: string }          // 加密形态,回传服务端续接推理

  | { type: "item_reference",
      id: string }                          // 引用既有 item,免重传

type ContentPart =
  | { type: "input_text", text: string }
  | { type: "output_text", text: string,
      annotations?: Annotation[] }
  | { type: "input_image", ... }            // 多模态(GPT-4o vision 走 message item)
关键设计洞察(与 Chat 的对比)
维度Chat CompletionsResponses
工具调用命名tool_calls[].idfunction_call.call_id
工具结果回填role:"tool" 独立消息function_call_output item
role 范围5 种(system/developer/user/assistant/tool)仅在 message item 内 4 种(system/developer/user/assistant)
推理链可见❌(仅 reasoning_tokens 计数)✅ reasoning item 可跨轮保留 + 加密续接
结构对称性工具是 message 的"附属"(tool_calls 字段)工具调用与消息平级(都是 item)

4. 工具定义

Responses 支持 5 种工具类型。FunctionTool 与 Chat 的最关键差异是"扁平"——无 function 包装层。

5 种工具类型
type描述说明
"function"用户自定义函数(Agent 工具调用主战场)扁平结构,无 function 包装层
"web_search"托管 Web 搜索OpenAI 内部跑搜索,output 是带引用的文本
"file_search"托管文件搜索(RAG)需要预先上传文件到 vector store
"code_interpreter"托管代码执行OpenAI 沙箱跑 Python,output 含 stdout / 文件
"mcp"MCP 协议外部工具Model Context Protocol,统一外部工具接口
FunctionTool 完整定义
type FunctionTool = {
  type: "function",
  name: string,                            // 工具名
  description?: string,                    // 工具描述
  parameters?: JSONSchema,                 // 参数 schema
  strict?: boolean                         // 强约束模式
}
FunctionTool 字段表
字段必填类型说明
type★"function"固定为 "function"
name★string工具名(与 Chat 类似正则约束)
description—string工具描述
parameters—JSONSchema参数 schema
strict—boolean强约束模式
与 Chat 的关键差异:Chat 的 tools[].function.name(两层嵌套)vs Responses 的 tools[].name(扁平)。跨协议转换时记得去掉 / 加上 function 包装层。

5. 响应对象 Response

完整类型定义
type Response = {
  id: string,                             // "resp_..."
  object: "response",
  created_at: number,                     // unix 秒(命名变化:Chat 是 created)
  model: string,                          // 实际使用的模型
  status: "completed" | "failed" | "in_progress" | "cancelled",
  output: ResponseItem[],                 // ★ 与 input 同构的 item 数组
  output_text?: string,                   // 便捷字段:output 里所有 text item 的拼接
  usage: {
    input_tokens: number,                 // ★ 命名从 prompt_tokens → input_tokens
    input_tokens_details?: { cached_tokens: number },
    output_tokens: number,
    output_tokens_details?: { reasoning_tokens: number },
    total_tokens: number
  },
  previous_response_id?: string | null,   // 续接键
  next_response_id?: string | null,       // 同一会话下一响应 ID
  instructions?: string | null,
  reasoning?: { effort, summary } | null,
  text?: { format } | null,
  tools?: Tool[] | null,                  // 实际使用的工具(可能与请求不同)
  tool_choice?: "auto" | "none" | "required",
  parallel_tool_calls?: boolean,
  temperature?: number,
  top_p?: number,
  truncation?: "auto" | "disabled",
  max_output_tokens?: number,
  store?: boolean,
  user?: string,
  metadata?: Record<string, string>,
  safety_identifier?: string,
  error?: { code: string, message: string } | null
}
关键字段表
字段类型说明
idstring"resp_..." 响应 ID。下轮可作 previous_response_id 用
object"response"对象类型
created_atnumberunix 时间戳(秒)命名变化:Chat 是 created,Responses 是 created_at
modelstring实际使用的模型
statusenum循环分支依据。"completed"(成功)/ "failed"(失败)/ "in_progress"(进行中,previous_response_id 模式下可见)/ "cancelled"(取消)
outputItem[]输出项数组。结构与 input 同构(含 reasoning / function_call 等)
output_textstring便捷字段:output 中所有 text item 的拼接。大多数场景直接读这个字段就够
usage.input_tokensnumber输入 token 数(prompt_tokens → input_tokens 命名升级)
usage.input_tokens_details.cached_tokensnumber命中缓存的 token 数
usage.output_tokensnumber输出 token 数
usage.output_tokens_details.reasoning_tokensnumber推理 token 数(独立计费)
usage.total_tokensnumber合计
previous_response_idstring | null上一响应 ID。配合 store:true 组成"服务端续接"
next_response_idstring | null下一响应 ID
errorobject | null错误对象。{code, message}。status="failed" 时有值
status 4 个值详解
值含义Agent 主循环如何处理
"completed"正常完成读 output_text 收尾
"failed"失败读 error.code / error.message,重试 / 降级
"in_progress"进行中(长任务、background:true 模式)轮询或等回调
"cancelled"用户取消终止循环,清理资源

6. 流式事件(类型化事件流)

与 Chat "同构 chunk 流"不同,Responses 的流是显式类型化事件——每个事件带 type 字段,且事件有明确的生命周期。

完整事件类型
type StreamEvent =
  // —— 生命周期 —— 
  | { type: "response.created",             response: Response }     // 创建(in_progress 状态)
  | { type: "response.in_progress",         response: Response }
  | { type: "response.completed",           response: Response }     // 完成
  | { type: "response.failed",              response: Response }
  | { type: "response.cancelled",           response: Response }
  | { type: "response.incomplete",          response: Response }     // 长度截断

  // —— 输出项添加/完成 —— 
  | { type: "response.output_item.added",   output_index: number, item: ResponseItem }
  | { type: "response.output_item.done",    output_index: number, item: ResponseItem }

  // —— 文本增量 —— 
  | { type: "response.output_text.delta",   output_index: number, delta: string }
  | { type: "response.output_text.done",    output_index: number, text: string }

  // —— 函数调用参数增量 —— 
  | { type: "response.function_call_arguments.delta",
                                            output_index: number, delta: string }
  | { type: "response.function_call_arguments.done",
                                            output_index: number, arguments: string }

  // —— 推理摘要增量(reasoning 模型)—— 
  | { type: "response.reasoning_summary_text.delta", ... }
  | { type: "response.reasoning_summary_text.done", ... }

  // —— 拒绝(refusal)—— 
  | { type: "response.refusal.delta",       output_index: number, delta: string }
  | { type: "response.refusal.done",        output_index: number, refusal: string }

  // —— 错误 —— 
  | { type: "error",                        code: string, message: string }
事件表(按生命周期排序)
事件 type触发时机主要字段
response.created响应创建(status: in_progress)response(含 id)
response.in_progress持续进行中(长任务可见)response
response.output_item.added每个 output item 开始output_index, item
response.output_text.delta文本流式增量output_index, delta(字符串分片)
response.function_call_arguments.delta工具参数流式增量output_index, delta
response.output_item.done每个 output item 完成(含完整 item)output_index, item
response.output_text.done文本流式完成output_index, text
response.function_call_arguments.done工具参数完成output_index, arguments(JSON(JavaScript Object Notation,人类可读的文本数据格式)字符串)
response.reasoning_summary_text.delta推理摘要增量(GPT-5 reasoning 模型)delta
response.reasoning_summary_text.done推理摘要完成text
response.refusal.delta拒绝文本流式delta
response.refusal.done拒绝文本完成refusal
response.completed正常完成response(status: completed)
response.failed失败response(status: failed,含 error)
response.cancelled取消response(status: cancelled)
response.incomplete未完成(撞 max_output_tokens 截断)response(status: incomplete,含 incomplete_details)
error协议级错误code, message
与 Chat 流式的关键差异:Chat 是"同构 chunk 流"(每个 chunk 形态相同,按字段是否出现表义);Responses 是"类型化事件流"(每个事件 type 明确,事件之间有生命周期关系)。
解析器优势:可以根据 type 直接 switch 处理,不用靠字段缺失猜状态。
工具参数分片:response.function_call_arguments.delta 增量到达,按 output_index 聚合,完整后用 .done 事件的 arguments 字段。

7. 完整往返示例(工具调用最小环)

① 请求:直接传字符串 input(极简入口)+ 扁平工具定义
{
  "model": "gpt-5",
  "input": "跑一下测试",
  "tools": [{
    "type": "function",
    "name": "run_tests",
    "parameters": {
      "type": "object",
      "properties": {"suite": {"type": "string"}},
      "required": ["suite"]
    }
  }]
}
② 响应:output 是 item 数组
{
  "id": "resp_001",
  "object": "response",
  "created_at": 1725273600,
  "model": "gpt-5-2025-01-01",
  "status": "completed",
  "output": [
    {
      "type": "reasoning",
      "summary": [{"type": "summary_text", "text": "用户想跑测试"}]
    },
    {
      "type": "function_call",
      "call_id": "fc_abc",
      "name": "run_tests",
      "arguments": "{\"suite\":\"all\"}"
    }
  ],
  "output_text": "",
  "usage": {
    "input_tokens": 80,
    "input_tokens_details": {"cached_tokens": 0},
    "output_tokens": 40,
    "output_tokens_details": {"reasoning_tokens": 25},
    "total_tokens": 120
  }
}
③ 回填请求:两条 item(function_call 原样 + function_call_output)
{
  "model": "gpt-5",
  "input": [
    {
      "type": "function_call",
      "call_id": "fc_abc",
      "name": "run_tests",
      "arguments": "{\"suite\":\"all\"}"
    },
    {
      "type": "function_call_output",
      "call_id": "fc_abc",
      "output": "42 passed"
    }
  ]
}
④ 进阶:previous_response_id 续接(不重传 history)
{
  "model": "gpt-5",
  "previous_response_id": "resp_001",         // 服务端已有 resp_001 的状态
  "input": "那覆盖率呢?"                        // 只发新增输入
}

8. 错误与异常

Responses 的错误处理与 Chat 类似,但 finish_reason → status 的概念变化需要重新映射。

错误码速查(部分)
code含义常见原因
invalid_request请求格式错误JSON 解析失败 / 必填字段缺失 / item 配对错
invalid_api_key认证失败API key 错 / 过期
insufficient_quota额度不足OpenAI 账户欠费
rate_limit_exceeded速率限制TPM / RPM 超限。读 Retry-After 头
server_error服务端错误OpenAI 内部问题。指数退避重试
model_not_found模型不存在模型 ID 错 / 无权访问
Chat finish_reason → Responses status 映射
Chat 概念Responses 概念
finish_reason: "stop"status: "completed" + output_text 有内容
finish_reason: "tool_calls"status: "completed" + output 含 function_call item
finish_reason: "length"status: "incomplete"(带 incomplete_details.reason)
finish_reason: "content_filter"status: "failed" 或 "completed" + output 含 refusal

9. 字段速查表(按字母序)

字段位置一句话
argumentsfunction_call itemJSON 字符串,需 json.loads
cached_tokensusage.input_tokens_details命中缓存的 input token 数
call_idfunction_call / function_call_output工具调用配对键(替代 Chat 的 tool_call_id)
codeerror 对象错误码
contentmessage item消息内容(string 或 ContentPart[])
conversation请求 / 响应会话对象 ID(多轮可挂同一会话)
created_at响应顶层unix 时间戳(秒)
delta流式事件增量内容(文本 / 工具参数 / 推理摘要)
descriptionFunctionTool工具描述
effortreasoning 对象推理强度
encrypted_contentreasoning item加密的推理链(回传服务端续接)
error响应顶层 / 流式 error 事件错误对象
formattext 对象输出格式约束
function_callitem type工具调用 item
function_call_outputitem type工具结果 item
id响应顶层 / item_reference item响应 ID / item 引用 ID
incomplete_details响应顶层(status: incomplete 时)截断原因
input请求顶层对话载体(string 或 Item[])
input_tokensusage输入 token 数
instructions请求 / 响应顶层系统指令(顶层参数)
item_referenceitem type引用既有 item
max_output_tokens请求顶层最大输出 token
messageitem type文本消息 item
metadata请求 / 响应顶层自定义元信息
model请求 / 响应顶层模型 ID
nameFunctionTool / function_call工具名
next_response_id响应顶层同一会话下一响应 ID
object响应顶层"response"
output响应顶层输出 item 数组
output_index流式事件output 项索引(聚合用)
output_text响应顶层便捷字段:所有 text item 拼接
output_tokensusage输出 token 数
parallel_tool_calls请求 / 响应顶层是否允许并行工具调用
parametersFunctionTool工具参数 schema
previous_response_id请求 / 响应顶层服务端续接键
reasoning请求 / 响应 / item type推理控制 / 推理链 item
reasoning_tokensusage.output_tokens_details推理 token 数
refusal响应 / 流式拒绝原因
response流式事件 / 通用当前响应对象
rolemessage item消息身份
safety_identifier请求顶层应用级安全追踪 ID
status响应顶层响应状态
store请求 / 响应顶层是否服务端存储
stream请求顶层是否流式
strictFunctionTool强约束模式
summaryreasoning 对象 / item推理摘要配置 / 内容
temperature请求 / 响应顶层采样温度
text请求顶层 / 响应顶层输出格式配置
tool_choice请求 / 响应顶层工具选择策略
tools请求 / 响应顶层工具定义数组
top_logprobs请求顶层返回 top N 候选 token 概率
top_p请求 / 响应顶层nucleus 采样
total_tokensusage合计 token 数
truncation请求 / 响应顶层中点截断策略
typeitem type 判别"message" / "function_call" / "function_call_output" / "reasoning" / "item_reference"
user请求 / 响应顶层终端用户标识

10. 引用与配套资料

来源链接 / 路径说明
OpenAI Responses API 文档(权威)platform.openai.com/docs/api-reference/responses官方权威源
OpenAI Chat → Responses 迁移指南platform.openai.com/docs/guides/migrate-to-responses从 Chat 迁到 Responses 的最佳实践
OpenAI Function Calling 指南platform.openai.com/docs/guides/function-calling工具调用最佳实践
教学讲义(卡片化讲解)llm-api-schema-reference.html第二篇 · OpenAI Responses
协议讲义(怎么用)llm-chat-protocol-guide.html7 篇协议讲义
姊妹:OpenAI Chat Completionsopenai-chat-completions-schema.htmlOpenAI 老协议(事实标准)
姊妹:Anthropic Messagesanthropic-messages-schema.htmlAnthropic Claude
三协议翻译表llm-api-schema-reference.html#part-mapping跨协议字段名对照