Skip to content

Conversation

@yashwantbezawada
Copy link

Description

Fixes #2736

This PR updates the ActionSearchSource type definition to match the actual API response structure when using specialized OpenAI APIs (weather, sports, finance).

Problem

The current type definition only supports type: Literal["url"] and requires both type and url fields, but the actual API returns responses like:

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

This causes type checking failures and forces developers to use # type: ignore or create custom type definitions.

Solution

Updated both ActionSearchSource definitions (BaseModel and TypedDict versions) to:

  1. Support both source types: Changed type from Literal["url"] to Literal["url", "api"]
  2. Make url optional: Changed from required str to Optional[str] = None (present only when type='url')
  3. Add name field: Added Optional[str] for specialized API identifiers (e.g., 'oai-weather', 'oai-sports', 'oai-finance')

Files Changed

  • src/openai/types/responses/response_function_web_search.py (BaseModel version)
  • src/openai/types/responses/response_function_web_search_param.py (TypedDict version)

Testing

While I don't have access to test against the actual specialized APIs, the type changes are:

  • Backward compatible (url sources still work)
  • Aligned with the documented behavior in the tools web search guide
  • Based on the actual API response structure reported in the issue

Additional Context

This aligns with the documentation mentioning specialized domains labeled as oai-sports, oai-weather, or oai-finance.

The ActionSearchSource type definition was incomplete and didn't match
the actual API response structure when using specialized OpenAI APIs
(weather, sports, finance).

Changes:
- Updated type field to support both "url" and "api" literals
- Made url field optional (present only when type='url')
- Added optional name field for specialized API identifiers

This allows proper type checking when working with responses from
specialized domains labeled as 'oai-sports', 'oai-weather', or
'oai-finance' as documented in the tools web search guide.

Fixes openai#2736
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

2 participants