GPT Codex API 是一个多模态对话补全风格的接口,支持使用结构化 input 数组、可调节推理力度,并可结合联网搜索或函数调用工具。
/api/v1/responses 端点,指定 model 为 gpt-5-codex、gpt-5.1-codex、gpt-5.2-codex 或 gpt-5.3-codex 之一即可使用。tools 数组用于开启 联网搜索 (Web Search) 或 函数调用 (Function Calling) 能力。
联网搜索(Web Search)
函数调用(Function Calling)
tools 中配置了函数调用工具时,将 tool_choice 设置为 "auto",允许模型根据需要自动决定是否调用函数;如果没有配置任何函数工具,请不要设置 tool_choice 字段。所有 API 均需要通过 Bearer Token 进行身份验证。
获取 API Key:
使用方法: 在请求头中添加: Authorization: Bearer YOUR_API_KEY
注意:
目标模型名称。可选值:gpt-5-codex、gpt-5.1-codex、gpt-5.2-codex、gpt-5.3-codex。
gpt-5-codex, gpt-5.1-codex, gpt-5.2-codex, gpt-5.3-codex "gpt-5.1-codex"
input 可以是字符串类型。
模型推理配置。
可选,模型可以调用的工具数组。一次请求中应仅配置联网搜索或函数调用其一,请勿同时配置。
联网搜索工具配置。
工具选择行为。当在 tools 中配置了函数调用工具时,将其设置为 auto,让模型自动决定何时调用函数。
"auto"
请求成功。仅支持以 Server-Sent Events (SSE) 形式返回的流式响应。
流式响应以 Server-Sent Events (SSE) 的形式返回,响应头为 Content-Type: text/event-stream。
普通返回
event: response.output_text.delta
data.delta:流中的增量文本内容data.type:事件类型,固定为 response.output_text.deltaevent: response.completed
data.response.usage:Token 用量信息,如 input_tokens、output_tokens 等函数调用(Function Calling)
event: response.function_call_arguments.delta
data.delta:函数参数的增量字符串内容data.type:事件类型,固定为 response.function_call_arguments.deltaevent: response.completed
data.response.usage:Token 用量信息,如 input_tokens、output_tokens 等最后一行 data: [DONE] 为流结束标记,表示不会再有新的事件发送。