from openai import OpenAI
client = OpenAI()
completion = client.chat.completions.create(
model="gpt-4o-search-preview",
web_search_options={},
messages=[
{
"role": "user",
"content": "What was a positive news story from today?",
}
],
)
print(completion.choices[0].message.content)
Hi!
You need to use the responses API.
In your code your are invoking the chat.completions API:
completion = client.chat.completions.create(
I copied this from the documentation:
from openai import OpenAI
client = OpenAI()
response = client.responses.create(
model="gpt-4o",
tools=[{"type": "web_search_preview"}],
input="What was a positive news story from today?"
)
print(response.output_text)
so you’re saying web searches don’t work with the chat completions API? Because I see it web_search_options as a valid argument in self.client.beta.chat.completions.parse
On chat completions, you’d use the offered model gpt-4o-search-preview-2025-03-11. It has built-in internet search retrieval, and some limitations in what else it can do.
Then the only parameter you need to address is the usefulness of adding those web_search_options, where size has a bit of effect on the default price of $0.035 per call (currently erroneously billed at $0.11 per call).
The API SDK code can deny unknown API parameters if not updated.
web_search_options (object, optional)
Tool configuration for searching the web to gather relevant results for a response.
search_context_size (string, optional, default: medium)
High-level guidance on how much context window space to use for the search. One of low, medium, high.
user_location (object or null, optional)
Approximate location parameters for the search.
type (string, required)
The location approximation type. Always approximate.