Bearer sk-xxxxxxxxxxgpt-4.1、gpt-4o、gpt-4o-mini、gpt-3.5-turbo 等claude-sonnet-4-5-20250929、claude-sonnet-4-20250514 等deepseek-v3-1-250821、deepseek-v3 等grok-4、grok-3、grok-3-fast、grok-4-fast-reasoning 等gemini-3-pro-preview、gemini-2.5-pro、gemini-2.5-flash 及其 -thinking/-nothinking / -thinking-<预算> / -thinking-low/-thinking-high 后缀变体qwen3-omni-flash 等role(user/system/assistant)和 contentresponse_format 参数控制输出格式,适用于 GPT、Claude、Grok 等模型。
thinking 字段开启思考能力:thinking.type 为 "disabled",需要显式设置为 "enabled" 开启stream: true 以获得更好的交互体验parameters 对象中。
enable_search、search_options、asr_options、temperature、top_p 等)都需要放在 parameters 对象中,而不是请求体的顶层。web_search_options 参数开启网络搜索功能,所以使用只能通过tool工具调用实现,且可能因为网络和提示词等原因不稳定,详细看上面工具调用(Functions / Tools)。基础示例(展示工具调用流程):/v1/responses 接口调用,而不是 /v1/chat/completions。
gpt-4o、gpt-4o-mini、gpt-5-chat 等支持文本和图像输入的模型/v1/responses 接口grok-4-fast-reasoning)支持推理能力,响应中的 usage 会区分 completion_tokens 和 reasoning_tokens:
completion_tokens - reasoning_tokens
| 异常类型 | 触发场景 | 返回信息 |
|---|---|---|
| AuthenticationError | API密钥无效或未授权 | 错误:API密钥无效或未授权 |
| NotFoundError | 模型不存在或不被支持 | 错误:模型 [model] 不存在或不被支持 |
| APIConnectionError | 网络中断或服务器未响应 | 错误:无法连接到API服务器 |
| APIError | 请求格式错误等服务端异常 | API请求失败:[错误详情] |
/v1/responses 接口)messages 列表中 system 角色用于设定模型行为,user 角色为用户提问assistant 角色的回复)openai 库:pip install openai