Guides
Web search
Give the model current information from the web. Add openrouter:web_search to tools: the model decides when to search, reads the results and cites the URLs it uses. Available on standard models.
How it works
- You add
{"type": "openrouter:web_search"}to thetoolsarray. - The model decides whether it needs to search, and writes the query.
- The search runs, and the results (title, URL, date when there is one, and text) go back to the model.
- The model can search again, as many times as it needs within the limits, and several searches of the same step run in parallel.
- The model answers with what it found, and the response brings the URLs it cited.
It works alongside your own function tools: those still come back to you, as in Tool calling.
Quick start
curl https://api.libremodel.ai/v1/chat/completions \
-H "Authorization: Bearer $LIBREMODEL_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "deepseek-v4.1-flash-1017",
"messages": [{"role": "user", "content": "What changed in the latest stable release of Rust? Cite your sources."}],
"tools": [{"type": "openrouter:web_search"}]
}'import os
from openai import OpenAI
client = OpenAI(base_url="https://api.libremodel.ai/v1", api_key=os.environ["LIBREMODEL_API_KEY"])
response = client.chat.completions.create(
model="deepseek-v4.1-flash-1017",
messages=[{"role": "user", "content": "What changed in the latest stable release of Rust? Cite your sources."}],
tools=[{"type": "openrouter:web_search"}],
)
message = response.choices[0].message
print(message.content)
for annotation in getattr(message, "annotations", None) or []:
print(annotation.url_citation.url)const response = await fetch('https://api.libremodel.ai/v1/chat/completions', {
method: 'POST',
headers: {
Authorization: `Bearer ${process.env.LIBREMODEL_API_KEY}`,
'Content-Type': 'application/json',
},
body: JSON.stringify({
model: 'deepseek-v4.1-flash-1017',
messages: [{ role: 'user', content: 'What changed in the latest stable release of Rust? Cite your sources.' }],
tools: [{ type: 'openrouter:web_search' }],
}),
})
const data = await response.json()
console.log(data.choices[0].message.content)import os
from openai import OpenAI
client = OpenAI(base_url="https://api.libremodel.ai/v1", api_key=os.environ["LIBREMODEL_API_KEY"])
response = client.responses.create(
model="deepseek-v4.1-flash-1017",
store=False,
input="What changed in the latest stable release of Rust? Cite your sources.",
tools=[{"type": "openrouter:web_search"}],
)
print(response.output_text)import os
from anthropic import Anthropic
client = Anthropic(base_url="https://api.libremodel.ai", api_key=os.environ["LIBREMODEL_API_KEY"])
message = client.messages.create(
model="deepseek-v4.1-flash-1017",
max_tokens=2048,
messages=[{"role": "user", "content": "What changed in the latest stable release of Rust? Cite your sources."}],
tools=[{"type": "web_search_20250305", "name": "web_search", "max_uses": 3}],
)
print(message.content[-1].text)Which models
Available on standard models: the ones without the Uncensored mark on Models. With an Uncensored model, a request with the tool, under any of its names or with :online, returns 400 invalid_request:
{
"error": {
"message": "`openrouter:web_search` is not available for this model.",
"type": "invalid_request_error",
"code": "invalid_request",
"param": null
}
}Configuration
Every parameter is optional, inside parameters:
{
"type": "openrouter:web_search",
"parameters": {
"max_results": 5,
"max_uses": 3,
"max_total_results": 10,
"search_context_size": "medium",
"allowed_domains": ["docs.python.org"],
"excluded_domains": ["pinterest.com"],
"user_location": { "type": "approximate", "country": "AR" }
}
}| Parameter | Type | Default | Description |
|---|---|---|---|
engine | string | auto | auto or native, which do the same. Any other engine returns 400 invalid_request |
max_results | integer | 5 | Results per search, from 1 to 20 |
max_uses | integer | — | Searches per request, at most. Never more than max_tool_calls |
max_total_results | integer | — | Results across all the searches of the request, at most |
search_context_size | string | medium | Text per result: low (500 characters), medium (1,000) or high (2,000) |
max_characters | integer | — | Exact characters per result, from 1 to 100,000. Takes precedence over search_context_size |
user_location | object | — | Results for a country. See User location |
allowed_domains | string[] | — | Only results from these domains |
excluded_domains | string[] | — | No results from these domains |
A value out of range returns 400 invalid_request, and the message names the parameter.
User location
user_location.country is a two-letter country code (AR, MX, US…), and the search favors results from that country. The other fields of the object (city, region, timezone) are accepted.
Tool names
The same search runs under the names the OpenAI and Anthropic SDKs use, in any of the three formats:
| Name | Where the parameters go |
|---|---|
openrouter:web_search | In parameters, as in the table above |
web_search and web_search_preview (OpenAI) | At the root of the tool: search_context_size, user_location and filters.allowed_domains |
web_search_20250305 and any web_search_<date> (Anthropic) | At the root of the tool: max_uses, allowed_domains, blocked_domains (as excluded_domains) and user_location |
If the request brings more than one, the first one counts. With n greater than 1, or with a function of yours named web_search, the request returns 400 invalid_request.
Domain filtering
{
"type": "openrouter:web_search",
"parameters": {
"allowed_domains": ["arxiv.org", "nature.com"],
"excluded_domains": ["reddit.com"]
}
}- A domain covers its subdomains:
nature.comalso letswww.nature.comandblogs.nature.comthrough. - The scheme,
www.and the path are ignored:https://www.arxiv.org/listisarxiv.org. - You can use both lists at once.
Controlling total results
{
"type": "openrouter:web_search",
"parameters": { "max_results": 5, "max_total_results": 12 }
}max_results caps each search, and max_total_results caps the whole request. Once the total is reached, later searches come back with no results.
Limiting the number of searches
max_uses, in the tool'sparameters: searches per request.max_tool_calls, at the root of the request, next tomessagesorinput: the steps in which the model can call server tools, counting web search and web fetch. 30 by default and at most.
When it reaches either limit, the model gets a message that there are no more searches, and answers with what it already has.
Example with parameters
curl https://api.libremodel.ai/v1/chat/completions \
-H "Authorization: Bearer $LIBREMODEL_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "deepseek-v4.1-flash-1017",
"messages": [{"role": "user", "content": "What is the current price of Bitcoin in US dollars?"}],
"tools": [{
"type": "openrouter:web_search",
"parameters": {"max_results": 3, "max_uses": 2, "search_context_size": "low"}
}],
"max_tool_calls": 5
}'import os
from openai import OpenAI
client = OpenAI(base_url="https://api.libremodel.ai/v1", api_key=os.environ["LIBREMODEL_API_KEY"])
response = client.chat.completions.create(
model="deepseek-v4.1-flash-1017",
messages=[{"role": "user", "content": "What is the current price of Bitcoin in US dollars?"}],
tools=[{
"type": "openrouter:web_search",
"parameters": {"max_results": 3, "max_uses": 2, "search_context_size": "low"},
}],
extra_body={"max_tool_calls": 5},
)
print(response.choices[0].message.content)
print(response.usage.model_extra.get("server_tool_use_details"))Response
The answer comes with the URLs the model cited, as url_citation annotations:
| Format | Where |
|---|---|
| Chat Completions | message.annotations[]: {"type": "url_citation", "url_citation": {"url", "title", "content", "start_index", "end_index"}} |
| Responses | annotations[] of the output_text part: {"type": "url_citation", "url", "title", "start_index", "end_index"}. The results it read and did not cite come with "uncited": true |
In Responses each search is also a web_search_call item, with an id that starts with ws_, its action.query and its status. With stream: true the stream sends the response.web_search_call.in_progress, .searching and .completed events.
Usage tracking
In Chat Completions and Responses, usage adds server_tool_use_details when the model asked for a server tool:
{
"usage": {
"prompt_tokens": 6120,
"completion_tokens": 412,
"total_tokens": 6532,
"cost": 0.0213,
"server_tool_use_details": {
"web_search_requests": 3,
"tool_calls_requested": 3,
"tool_calls_executed": 3
}
}
}web_search_requests: the searches that answered. They are the ones charged.tool_calls_requested: the server tool calls the model asked for.tool_calls_executed: the ones that ran, searches and web fetches.
In Anthropic Messages it goes in usage.server_tool_use, with web_search_requests and web_fetch_requests.
Pricing
- Each search that answered costs $0.005, whatever the number of results. A search that fails is not charged.
- The results go into the model's input, so they are also charged as input tokens, at the model's price, every time they are sent again: in each later step of the same request, and in the next turns if your history keeps them.
- What the request cost, searches included, comes in
usage.cost. - Before the request starts, up to five searches are held from your balance along with the usual hold. If the balance does not cover more, the model stops searching and answers with what it has: you never get a
402in the middle of an answer.
Errors
| Case | Answer |
|---|---|
| An Uncensored model | 400 invalid_request, with the message in Which models |
An engine other than auto or native | 400 invalid_request: Unsupported web search engine |
A parameter out of range, or max_tool_calls outside 1 to 30 | 400 invalid_request, with the parameter in the message |
n greater than 1 | 400 invalid_request |
A function of yours named web_search | 400 invalid_request: rename it |
| A search that doesn't answer | The model gets that search is not available right now, and answers anyway. It is not charged |
Migrating from the web plugin
The :online model suffix and plugins: [{"id": "web"}], from OpenRouter, work too: they are the same search, with the same rules and price.
| Before | Now |
|---|---|
"model": "<model>:online" | "tools": [{"type": "openrouter:web_search"}] |
plugins: [{"id": "web", "max_results": 3}] | "parameters": {"max_results": 3} |
include_domains / exclude_domains | allowed_domains / excluded_domains |
With the plugin and :online the model also decides when to search, as with the tool.
Next steps
- Web fetch: let the model read a whole page or PDF from a URL.
- Tool calling: your own functions, next to the server tools.