Default web search to `type="approximate"`
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 31.6k
- Forks
- 5.7k
- Avg merge
- 1d 6h
- Merged PRs (30d)
- 96
Description
Confirm this is a feature request for the Python library and not the underlying OpenAI API.
- This is a feature request for the Python library
Describe the feature or improvement you're requesting
Currently, if a user passes tools=[{"type": "web_search"}] to client.responses.create, it's get turned into this (on the OpenAI server side) with the country set to US:
{
"type": "web_search",
"search_context_size": "medium",
"user_location": {
"city": None,
"country": "US", # <- note this line
"region": None,
"timezone": None,
"type": "approximate",
},
}
And apparently this is by design.
But I would say that this is NOT what the developer wants or expects.
The workaround is to pass tools=[{"type": "web_search", "user_location": {"type": "approximate"}}] (which is what the OpenAI playground does - I guess they agree that defaulting to the US is a bad idea).
I would suggest that if the server-side isn't going to change, then defaulting to this in the SDKs will better align with user/developer expectation.
At the very least, if defaulting to the USA really is the intended behaviour in the backend and for the client SDKs, it would be nice to say so in the docs, so it's not a hidden surprise.
Something like:
Note that if you pass
tools=[{"type": "web_search"}]without specifying a location, then the following string will be injected into the system prompt: "The user is in an estimated location of United States."
Additional context
No response
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at the Python library's client.responses.create handling for tools and trace how a web_search tool without user_location is serialized. Check the relevant tests or request payload assertions, then verify that the default location type is approximate and that the documented behavior matches the resulting request.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- api
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 65/100