Skip to content

fix: update ActionSearchSource type to support specialized API sources#3451

Open
C1-BA-B1-F3 wants to merge 4 commits into
openai:mainfrom
C1-BA-B1-F3:fix/action-search-source-api-type
Open

fix: update ActionSearchSource type to support specialized API sources#3451
C1-BA-B1-F3 wants to merge 4 commits into
openai:mainfrom
C1-BA-B1-F3:fix/action-search-source-api-type

Conversation

@C1-BA-B1-F3

Copy link
Copy Markdown

Summary

Fixes #2736

The ActionSearchSource type definition doesn't match the actual API response structure when using specialized OpenAI APIs (weather, sports, finance). The API returns sources with type='api', a name field, and url=None, but the current type only supports type='url' with a required url field.

Problem

When the API returns a specialized data source in a web search response:

ActionSearchSource(type='api', url=None, name='oai-weather')

The SDK's type definition causes type checking failures because:

  • type only accepts Literal["url"]
  • url is required (not optional)
  • name field doesn't exist

Changes

response_function_web_search.py (response type)

  • Add "api" to the type Literal: Literal["url", "api"]
  • Make url optional: Optional[str] = None
  • Add optional name field: Optional[str] = None

response_function_web_search_param.py (param type)

  • Add "api" to the type Literal: Required[Literal["url", "api"]]
  • Make url optional (remove Required)
  • Add optional name field

tests/test_response_function_web_search.py

  • Add test for ActionSearchSource with type='url'
  • Add test for ActionSearchSource with type='api'
  • Add test for ActionSearchSource with type='api' and optional URL
  • Add integration test for ActionSearch containing API-type sources

Testing

All 10 tests pass, including 4 new tests for the ActionSearchSource type changes.

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
@C1-BA-B1-F3 C1-BA-B1-F3 requested a review from a team as a code owner June 26, 2026 01:42

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ActionSearchSource type definition incomplete - missing type='api' and name field

1 participant