跳到主要内容
API 参考/Responses/创建响应

创建响应

POST/v1/responses

使用 OpenAI Responses API 格式创建非流式或流式模型响应,适合 GPT-5.5 等新协议模型。

认证​

API Key 通过请求头传入。

Authorizationstring必填

API Key,格式为 Bearer YOUR_API_KEY。

默认值:-
Content-Typestring必填

请求体格式。

默认值:application/json
Request-Idstring可选

客户侧生成的唯一请求标识,用于追踪和排查。

默认值:-

请求​

请求体必须包含 model 和 input。Responses API 使用 max_output_tokens 限制响应的最大 Token 数;不要在此接口使用 Chat Completions 的 max_tokens。

modelstring必填

Responses API 模型 ID,例如 gpt-5.5 或 gpt-5.5-pro。

默认值:-
inputstring | array必填

输入内容,可以是字符串,也可以是结构化多轮消息。

默认值:-
instructionsstring可选

系统级指令,用于设定回答风格、角色或任务边界。

默认值:-
streamboolean可选

是否启用 SSE 流式输出。

默认值:false
temperaturenumber可选

采样温度,取值通常为 0 到 2。

默认值:1
top_pnumber可选

核采样参数。通常不要与 temperature 同时大幅调整。

默认值:1
max_output_tokensinteger可选

限制本次响应最多生成的输出 Token 数。

默认值:-
toolsarray可选

可供模型调用的工具列表。

默认值:-
tool_choicestring | object可选

工具调用策略,例如 auto、none 或指定工具。

默认值:-
textobject可选

文本输出格式配置,例如 JSON Schema。

默认值:-
reasoningobject可选

推理配置,用于支持推理模型的思考强度控制。

默认值:-
storeboolean可选

是否存储响应用于后续检索或延续上下文;省略时默认为 true。

默认值:true
safety_identifierstring可选

稳定的终端用户标识,用于安全策略识别;建议传入用户名或邮箱的哈希值。

默认值:-
prompt_cache_keystring可选

用于相似请求的提示缓存分桶;替代 Responses API 中已弃用的 user 字段。

默认值:-
prompt_cache_optionsobject可选

提示缓存选项;使用 ttl 配置缓存的最短生命周期。

默认值:-
prompt_cache_retentionstring可选

请改用 prompt_cache_options.ttl。

默认值:-
truncationstring可选

当前文档仍保留该字段以兼容旧请求,使用前请确认模型支持情况。

默认值:-
userstring可选

请使用 safety_identifier 和 prompt_cache_key。

默认值:-

响应​

非流式请求返回完整 response 对象。流式请求通过 SSE 逐步返回事件。

idstring必填

响应唯一标识。

默认值:-
objectstring必填

对象类型。

默认值:response
created_atinteger必填

创建时间,Unix 时间戳。

默认值:-
modelstring必填

实际执行请求的模型。

默认值:-
outputarray必填

模型输出列表,可能包含 message、function_call 等类型。

默认值:-
output[].contentarray可选

消息内容块列表,文本输出通常为 output_text。

默认值:-
usageobject可选

Token 用量统计。

默认值:-

流式响应​

设置 stream: true 后,响应会以 SSE 事件返回。常见事件包括 response.created、response.output_item.added、response.output_text.delta 和 response.completed。

data: {"type":"response.output_text.delta","delta":"量子"}
data: {"type":"response.output_text.delta","delta":"计算"}
data: {"type":"response.completed","response":{"id":"resp_abc123"}}

错误​

状态码说明
400请求体字段错误或模型不支持指定参数
401API Key 缺失或无效
403当前账户无权调用该模型
429请求超过速率限制
500 / 503平台或上游模型服务异常

相关指南​