`ActionOpenPage` mismatched API response

用户在使用 OpenAI Python SDK(如 v1.107.1、v2.9.0)通过 Batch API 或同步调用 `responses.create`(模型含 `web_search_preview` 或类似深度搜索功能)时,触发 `ActionOpenPage` 类型的数据校验失败。同时可

`ActionOpenPage` mismatched API response

`ActionOpenPage` mismatched API response

快速结论:此报错发生在使用 OpenAI Python SDK 调用 Responses API 的 `web_search_call` 时,API 返回的 `ActionOpenPage.url` 为 `null`,但 SDK 中该字段被定义为必需。优先升级至 SDK v2.17.0 或更高版本。

问题场景

用户在使用 OpenAI Python SDK(如 v1.107.1、v2.9.0)通过 Batch API 或同步调用 `responses.create`(模型含 `web_search_preview` 或类似深度搜索功能)时,触发 `ActionOpenPage` 类型的数据校验失败。同时可能伴随 `ActionFindInPage` 动作缺失、`ActionSearch.query` 为空等类似问题。

报错原文

ActionOpenPage: URL cannot be null (type=value_error)

实际 Pydantic 验证错误信息(具体格式因 SDK 版本而异),例如:

pydantic_core._pydantic_core.ValidationError: 1 validation error for ActionOpenPage
url
  Field required (type=value_error.missing)

原因分析

OpenAI API 在特定条件下(如 Batch API 结合深度搜索、`user_location` 等参数)会返回 `”action”: { “type”: “open_page”, “url”: null }`。SDK 中 `ActionOpenPage` 类的 `url` 字段被定义为 `str`(必需),而 API 响应中该字段可能为 `null` 或缺失。这属于 SDK 类型定义与 API 实际响应不一致的问题。

环境排查

  • Python 版本:3.12、3.13.5 等均可能触发(非核心因素)
  • SDK 版本:v1.107.1、v2.9.0 均受影响,v2.17.0 起修复
  • 模型:如 `o4-mini-deep-research`、`gpt-5.1` 等支持 web_search 的模型
  • 额外参数:使用 `include=[‘web_search_call.action.sources’]` 或 `user_location` 设置可能增加触发概率

解决步骤

  1. 升级 OpenAI Python SDK 至 v2.17.0 或以上版本(可通过 `pip install –upgrade openai` 执行)
  2. 如无法立即升级,可在代码中捕获 Pydantic 验证异常,或对 `ActionOpenPage` 对象手动处理 `url` 字段的 `None` 情况(但此方法不推荐作为长期方案)
  3. 如果仍遇到其他字段空值问题(如 `ActionSearch.query` 为 `None`),请确认 SDK 版本是否已包含 #2833 的所有修复

验证方法

升级后,使用相同参数调用 Responses API(如包含 `web_search_call.action.sources` 且模型为支持深度搜索的模型),检查日志中不再出现 Pydantic 验证错误,且 `action.url` 为 `null` 的记录能被正常解析。

参考来源

openai/openai-python #2620

GamsGo AI

AI 工具推荐

想把多个 AI 模型放在一个入口?

GamsGo AI 集成 ChatGPT、DeepSeek、Gemini、Claude、Midjourney、Veo 等常用模型,适合写作、绘图、视频和日常 AI 工作流。

了解 GamsGo AI

推广链接:通过此链接购买,我可能获得佣金,不影响你的价格。

celebrityanime
celebrityanime
文章: 12404

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注