Web Search
Some models support performing web searches during conversations to retrieve real-time information before generating responses. Enable this by adding a web_search tool in tools.
Basic Usage
curl https://crazyrouter.com/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_API_KEY" \
-d '{
"model": "gpt-4o",
"messages": [
{"role": "user", "content": "What are today'\''s top tech news stories?"}
],
"tools": [
{
"type": "web_search"
}
]
}'
Streaming Search
stream = client.chat.completions.create(
model="gpt-4o",
messages=[
{"role": "user", "content": "What are the latest AI models in 2026?"}
],
tools=[{"type": "web_search"}],
stream=True
)
for chunk in stream:
if chunk.choices[0].delta.content is not None:
print(chunk.choices[0].delta.content, end="")
Search Configuration
You can control search behavior through the web_search tool parameters:
{
"tools": [
{
"type": "web_search",
"web_search": {
"enable": true,
"search_context_size": "medium"
}
}
]
}
| Parameter | Type | Description |
|---|
enable | boolean | Whether to enable search |
search_context_size | string | Search context size: low, medium, high |
Web search increases response latency and token consumption. The model automatically determines whether a search is needed and only triggers a search when real-time information is required.
Not all models support web search. If the model does not support it, the web_search tool will be ignored.