-
Notifications
You must be signed in to change notification settings - Fork 4.4k
Open
Labels
bugSomething isn't workingSomething isn't working
Description
Confirm this is an issue with the Python library and not an underlying OpenAI API
- This is an issue with the Python library
Describe the bug
The type definition for ActionSearchSource in the OpenAI Python SDK (v2.7.1) doesn't match the actual API response structure when using specialized OpenAI APIs (weather, sports, finance).
Current SDK Type Definition:
# From: src/openai/types/responses/response_function_web_search_param.py
class ActionSearchSource(BaseModel):
type: Literal["url"]
"""The type of source. Always `url`."""
url: str
"""The URL of the source."""Actual API Response:
ActionSearchSource(type='api', url=None, name='oai-weather')Expected Type Definition:
class ActionSearchSource(BaseModel):
type: Literal["url", "api"]
"""The type of source. Can be 'url' for web sources or 'api' for specialized OpenAI APIs."""
url: Optional[str] = None
"""The URL of the source (present when type='url')."""
name: Optional[str] = None
"""The name/identifier of the specialized API (e.g., 'oai-weather', 'oai-sports', 'oai-finance')."""Impact:
This causes type checking failures when working with actual API responses, forcing developers to use # type: ignore or create custom type definitions.
Related:
This aligns with the documentation mentioning specialized domains labeled as oai-sports, oai-weather, or oai-finance (https://platform.openai.com/docs/guides/tools-web-search).
To Reproduce
- Create a response with web search enabled and
include=["web_search_call.action.sources"] - Make a query that triggers a specialized API (e.g., "What's the weather in NYC?")
- Examine the
ActionSearchSourcein the response - Observe that the type is 'api' instead of 'url', and there's a
namefield that doesn't exist in the type definition
Code snippets
from openai import OpenAI
client = OpenAI()
response = client.responses.create(
model="gpt-5-2025-08-07",
tools=[{"type": "web_search"}],
include=["web_search_call.action.sources"],
input="What's the weather in NYC today?"
)
# Response contains:
# ActionSearchSource(type='api', url=None, name='oai-weather')
# But types expect: type must be "url" and url must be a stringOS
macOS
Python version
Python 3.12.2
Library version
openai==2.7.1
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working