fix: update ActionSearchSource type to support specialized API sources#3451
fix: update ActionSearchSource type to support specialized API sources#3451C1-BA-B1-F3 wants to merge 4 commits into
Conversation
Guard against empty type args when using bare dict or list annotations (no type parameters, e.g. instead of ). Previously: - construct_type() raised ValueError on bare dict - construct_type() raised IndexError on bare list - _transform_recursive() raised IndexError on bare dict Now these cases gracefully return the data as-is, matching the behavior of parameterized types when the data already matches. Fixes openai#3338, openai#3341
…I responses Fixes openai#3179 The API can return null for the action field in web search calls (e.g., when the search is still in progress or the action hasn't been determined yet). This change makes the action field Optional[Action] with a default of None, matching the actual API behavior. This allows users to safely check action.type without getting an AttributeError when action is None.
When NO_PROXY or other proxy environment variables contain newline characters (common in Docker, .env files, or shell scripts), httpx's get_environment_proxies() only splits by comma and fails with InvalidURL. This fix adds sanitize_proxy_env_vars() that removes newlines from proxy environment variables before httpx reads them. Fixes openai#3303
The ActionSearchSource type only supported type='url' with a required url field, but the API returns specialized data sources (weather, sports, finance) with type='api', a name field, and url=None. Changes: - Add 'api' to the type Literal in both response and param types - Make url optional (absent when type='api') - Add optional name field for the data source identifier Fixes openai#2736
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 898775e11b
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| """The unique ID of the web search tool call.""" | ||
|
|
||
| action: Action | ||
| action: Optional[Action] = None |
There was a problem hiding this comment.
Allow null web-search actions in input params
When the API returns action: null (the scenario this line now accepts), the corresponding input-item type still goes through ResponseFunctionWebSearchParam, where action remains Required[Action]. That leaves users unable to type a replay/round-trip of a web-search item with a null action into responses.create(input=...); please make the param field nullable and non-required in sync with the response model.
Useful? React with 👍 / 👎.
Summary
Fixes #2736
The
ActionSearchSourcetype definition doesn't match the actual API response structure when using specialized OpenAI APIs (weather, sports, finance). The API returns sources withtype='api', anamefield, andurl=None, but the current type only supportstype='url'with a requiredurlfield.Problem
When the API returns a specialized data source in a web search response:
The SDK's type definition causes type checking failures because:
typeonly acceptsLiteral["url"]urlis required (not optional)namefield doesn't existChanges
response_function_web_search.py(response type)"api"to thetypeLiteral:Literal["url", "api"]urloptional:Optional[str] = Nonenamefield:Optional[str] = Noneresponse_function_web_search_param.py(param type)"api"to thetypeLiteral:Required[Literal["url", "api"]]urloptional (removeRequired)namefieldtests/test_response_function_web_search.pyActionSearchSourcewithtype='url'ActionSearchSourcewithtype='api'ActionSearchSourcewithtype='api'and optional URLActionSearchcontaining API-type sourcesTesting
All 10 tests pass, including 4 new tests for the
ActionSearchSourcetype changes.