跳到主要内容

OpenAI Response API

OpenAI 的新一代响应协议 /v1/responses,图灵平台以兼容模式代理到 Azure / OpenAI 后端。相比 Chat Completions,它主打推理模型(GPT-5 / o 系列)、有状态思考MCP tool connector 等 GPT-5 专有能力。

完整 schema 与 Try-It

本页讲概念、差异与典型用法。完整请求 / 响应字段、交互式 Try-It 与多语言代码样例在 API 参考 → Create a response

什么时候选这个接口

  • 用 GPT-5.x / o-series 做推理任务:reasoning 参数在这里是一等公民
  • 需要有状态(stateful)思考保持多轮 rs_id:非 Response 接口做不到
  • 要调用 MCP 服务器端工具:Response 原生支持 MCP tool connector

其它选择:

概览

项目说明
端点POST /api/v1/responses
协议兼容OpenAI Responses API ↗
主要用途GPT-5 推理、有状态思考、MCP tool、图像理解、函数调用
支持模型Response 模型清单 为准
输入字段input(string 或消息数组;不是 messages
不支持的 built-in tools

图灵平台目前 不支持 OpenAI 的以下 built-in tools:code_interpreter / file_search / web_search。需要这些能力请用自定义 function 工具或 MCP 连接器。

SDK 版本

本文档基于 OpenAI Python SDK v1.102.0 验证。

能力集成

推理 / 思考

推理类模型(o1/o3/o4、GPT-5 推理模式)支持 reasoning 参数:

curl $TURING_BASE_URL/responses \
-H "Authorization: Bearer $TURING_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "turing/gpt-5.5",
"input": "正方形对角线 10cm,求面积。",
"reasoning": {"effort": "high", "summary": "auto"}
}'
  • effort:思考强度。强度越高,思考 token 越多,计费越贵。
  • summary:思考过程的摘要展示模式;null 表示不回显(仍按 reasoning token 计费)。

思考 token 按 output_cost_per_reasoning_token 计费(未设则 fallback 到 output_cost_per_token)。详见 思考模型配置

有状态思考(stateful)

支持 stateful 的思考模型在多轮对话中可以复用前一轮的思考状态,避免重复 reasoning。通过 tags: ["stateful"] 启用:

stateful 的适用范围
  • 需要:以 Response 模型清单 中支持 stateful reasoning 的推理型号为准,或请求里带 rs_id(response id)。
  • 不需要:GPT-5.1-chat 等非思考模型,按普通多轮处理即可。
  • 这是能力限定示例,不是通用模型推荐;普通推理优先从 gpt-5.5 / gpt-5.4 系列选择。
curl $TURING_BASE_URL/responses \
-H "Authorization: Bearer $TURING_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "turing/gpt-5.2",
"input": "...",
"tags": ["stateful"]
}'

MCP 工具连接器

MCP (Model Context Protocol) ↗ 让模型连接远程 MCP 服务器使用其工具。Response API 原生支持,无需自己实现 tool_use 循环。

curl $TURING_BASE_URL/responses \
-H "Authorization: Bearer $TURING_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "turing/gpt-5.4-mini",
"input": "Roll 2d4+1",
"tools": [{
"type": "mcp",
"server_label": "dmcp",
"server_description": "A Dungeons and Dragons MCP server.",
"server_url": "https://dmcp-server.deno.dev/sse",
"require_approval": "never"
}]
}'

图像理解

input_image content block 接受 base64 data URL 或 HTTPS URL:

curl $TURING_BASE_URL/responses \
-H "Authorization: Bearer $TURING_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "turing/gpt-5.4-mini",
"input": [{
"role": "user",
"content": [
{"type": "input_text", "text": "这张图里有什么?"},
{"type": "input_image", "image_url": "https://example.com/image.jpg"}
]
}]
}'

base64 形式:"image_url": "data:image/jpeg;base64,<base64_image>"

与 Chat Completions 的关键差异

  • 字段是 input不是 messages)。
  • 输出是 output 数组(多种类型 block:message / tool_call / reasoning 等)。便利字段 output_text 直接给最终文本。
  • 流式是 SSE,事件类型更细(response.created / response.output_item.added / response.output_text.delta / response.completed 等)。
  • Response API 的 function tool 是扁平结构(没有外层 function 包装),参数直接在顶层。
  • usageinput_tokens_details / output_tokens_details(对应 Chat Completions 的 prompt_tokens_details / completion_tokens_details);output_tokens_details.reasoning_tokens 是思考 token 数量,纳入输出总量一起计。

字段到账单单价的映射见 计费与用量 → 计费维度速查表

turing_options

图灵平台扩展的 turing_options 字段(请求体顶层;OpenAI SDK 里用 extra_body 传),用于配置超时、重试、fallback 等平台行为。字段定义与取值见 超时、重试与 Fallback

See also