OpenAI Web Search
GPT-4o mini Search Preview models are specialised models for web search in Chat Completions. It is trained to understand and execute web search queries.
A Few Considerations
The table below provides a detailed breakdown of OpenAI model costs.
From my perspective, OpenAI excels in two key areas…
First, their models consistently demonstrate superior accuracy and alignment. Numerous studies highlight OpenAI models as top performers in terms of reliability and effectiveness.
Second, the simplicity of their ecosystem stands out.
In a recent post, I explored how effortless it is to build a Computer-Using AI Agent (CUA) with OpenAI’s CUA model — a testament to their user-friendly design.
Similarly, leveraging OpenAI’s web search model is both straightforward and transparent.
Users can specify regional preferences for tailored, localised search results, and OpenAI Web Search provides reference URLs, clearly citing data sources.
Overall, the integration of web search marks a significant advancement, effectively addressing the longstanding challenge of the training data cutoff by enabling real-time information access.
Tension Between Simplicity & Control
Web search AI solutions like LLamaIndex offer granular, fine-grained control over the source data being searched, allowing users to tailor results with precision.
However, this high degree of control comes at the cost of increased complexity, requiring technical expertise to manage effectively.
In contrast, OpenAI provides a streamlined approach, delivering easy access to search and data orchestration with significantly lower complexity.
While OpenAI’s simplicity is a strength, it sacrifices a level of control, leaving users with less influence over how data is processed or prioritised.
Data orchestration platforms, often dubbed “Search 2.0,” represent a new frontier in web search, blending retrieval and synthesis into a cohesive experience.
These platforms, however, exert considerable influence over the narrative by determining how data is synthesised and presented to users.
The tension between simplicity and control reflects a trade-off: detailed customisation versus ease of use.
For developers or advanced users, solutions like LLamaIndex might be preferable despite the steeper learning curve they entail.
OpenAI’s model, on the other hand, appeals to those who value accessibility and quick deployment over intricate customisation.
The lack of control in simpler systems can sometimes obscure how data is filtered or ranked, raising questions about transparency.
Advanced data orchestration tools aim to balance this by offering structured outputs, but their complexity can still overwhelm casual users.
I haven’t tested it yet, but the system prompt in these models should theoretically allow builders to exert significant control over how searches are conducted.
This potential for customisation via prompts could bridge the gap between simplicity and control, offering a hybrid solution.
Ultimately, the choice between platforms depends on the user’s priorities: effortless operation or meticulous oversight of the search process.
As web search AI evolves, striking an optimal balance between these two poles will likely define the next generation of tools.
How To
Models can now search the web for up-to-date information prior to crafting a response.
With the Chat Completions API, you gain direct access to the fine-tuned models and tools utilised by Search in ChatGPT.
When employing Chat Completions, the model consistently fetches web-based information before addressing your question.
To leverage web_search_preview
as a tool that models such as gpt-4o
and gpt-4o-mini
activate only when required, opt for the Responses API instead.
To incorporate web search within Chat Completions at present, you must use one of these models:
- gpt-4o-search-preview
- gpt-4o-mini-search-preview
Below is a basic Python script you can paste into a Notebook and run…
import os
from openai import OpenAI
# Set your OpenAI API key as an environment variable
os.environ["OPENAI_API_KEY"] = "YOUR_API_KEY" # Replace YOUR_API_KEY with your actual API key
client = OpenAI()
completion = client.chat.completions.create(
model="gpt-4o-search-preview",
web_search_options={},
messages=[
{
"role": "user",
"content": "What is current weather in Cape Town?",
}
],
)
print(completion.choices[0].message.content)
I ask the following question:
What is the current weather in Cape Town?
Notice the detailed response and also the source citation…
As of April 9, 2025, the current weather in Cape Town, South Africa, is partly cloudy with a temperature of 69°F (21°C).
## Weather for Cape Town, South Africa:
Current Conditions: Some clouds, 69°F (21°C)
Daily Forecast:
* Wednesday, April 09: Low: 59°F (15°C), High: 72°F (22°C), Description: Mainly cloudy
* Thursday, April 10: Low: 60°F (16°C), High: 77°F (25°C), Description: Sunny, pleasant and warmer
* Friday, April 11: Low: 60°F (16°C), High: 74°F (23°C), Description: Partly sunny
* Saturday, April 12: Low: 60°F (15°C), High: 66°F (19°C), Description: Cloudy and not as warm; a brief afternoon shower or two
* Sunday, April 13: Low: 59°F (15°C), High: 68°F (20°C), Description: Clouds breaking for some sun
* Monday, April 14: Low: 57°F (14°C), High: 68°F (20°C), Description: Mostly sunny
* Tuesday, April 15: Low: 56°F (13°C), High: 67°F (19°C), Description: Partly sunny
In April, Cape Town experiences mild autumn weather, with average high temperatures around 72°F (22°C) and lows near 59°F (15°C). The city typically receives about 1.26 inches (32 mm) of rainfall over approximately 8.8 days during the month. ([weather-atlas.com](https://www.weather-atlas.com/en/south-africa/cape-town-weather-april?utm_source=openai))
Detailed view:
ChatCompletion
(id='chatcmpl-cb9d19ae-7914-4088-ba9d-0cd6a02f760e',
choices=[Choice(finish_reason='stop',
index=0,
logprobs=None,
message=ChatCompletionMessage
(content='##
[Cape Town, South Africa]
(https://www.google.com/maps/search/Cape+Town%2C+South+Africa)
## Weather for Cape Town, South Africa:
Current Conditions: Sunny, 63°F (17°C)
Daily Forecast:
* Thursday, April 10: Low: 60°F (15°C), High: 78°F (26°C), Description: Sunny and comfortable
* Friday, April 11: Low: 61°F (16°C), High: 74°F (23°C), Description: Partly sunny and pleasant
* Saturday, April 12: Low: 58°F (14°C), High: 68°F (20°C), Description: Cloudy with a brief shower or two in the afternoon
* Sunday, April 13: Low: 57°F (14°C), High: 67°F (19°C), Description: Clouds breaking for some sun
* Monday, April 14: Low: 56°F (14°C), High: 69°F (20°C), Description: Mostly sunny
* Tuesday, April 15: Low: 58°F (14°C), High: 67°F (19°C), Description: Partly sunny
* Wednesday, April 16: Low: 53°F (12°C), High: 71°F (22°C), Description: Plenty of sunshine
', refusal=None, role='assistant',
annotations=[Annotation(type='url_citation',
url_citation=AnnotationURLCitation(end_index=90, start_index=3,
title='Cape Town, South Africa',
url='https://www.google.com/maps/search/Cape+Town%2C+South+Africa'))],
audio=None,
function_call=None,
tool_calls=None))],
created=1744267781,
model='gpt-4o-search-preview-2025-03-11',
object='chat.completion',
service_tier=None,
system_fingerprint='',
usage=CompletionUsage(completion_tokens=280,
prompt_tokens=8,
total_tokens=288,
completion_tokens_details=CompletionTokensDetails(accepted_prediction_tokens=0, audio_tokens=0, reasoning_tokens=0, rejected_prediction_tokens=0), prompt_tokens_details=PromptTokensDetails(audio_tokens=0, cached_tokens=0)))
User Location
To enhance the accuracy of search results based on geographic context, you can provide an approximate user location by specifying details such as country, city, region, and/or timezone.
from openai import OpenAI
client = OpenAI()
completion = client.chat.completions.create(
model="gpt-4o-search-preview",
web_search_options={
"user_location": {
"type": "approximate",
"approximate": {
"country": "ZA",
"city": "Cape Town",
"region": "Cape Town",
}
},
},
messages=[{
"role": "user",
"content": "What are the best restaurants close to Campsbay?",
}],
)
print(completion.choices[0].message.content)
And below the detailed output…
Chief Evangelist @ Kore.ai | I’m passionate about exploring the intersection of AI and language. From Language Models, AI Agents to Agentic Applications, Development Frameworks & Data-Centric Productivity Tools, I share insights and ideas on how these technologies are shaping the future.