Skip to content
Docs

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

  1. You add {"type": "openrouter:web_search"} to the tools array.
  2. The model decides whether it needs to search, and writes the query.
  3. The search runs, and the results (title, URL, date when there is one, and text) go back to the model.
  4. The model can search again, as many times as it needs within the limits, and several searches of the same step run in parallel.
  5. 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"}]
  }'

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:

JSON
{
  "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:

JSON
{
  "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" }
  }
}
ParameterTypeDefaultDescription
enginestringautoauto or native, which do the same. Any other engine returns 400 invalid_request
max_resultsinteger5Results per search, from 1 to 20
max_usesinteger—Searches per request, at most. Never more than max_tool_calls
max_total_resultsinteger—Results across all the searches of the request, at most
search_context_sizestringmediumText per result: low (500 characters), medium (1,000) or high (2,000)
max_charactersinteger—Exact characters per result, from 1 to 100,000. Takes precedence over search_context_size
user_locationobject—Results for a country. See User location
allowed_domainsstring[]—Only results from these domains
excluded_domainsstring[]—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:

NameWhere the parameters go
openrouter:web_searchIn 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

JSON
{
  "type": "openrouter:web_search",
  "parameters": {
    "allowed_domains": ["arxiv.org", "nature.com"],
    "excluded_domains": ["reddit.com"]
  }
}
  • A domain covers its subdomains: nature.com also lets www.nature.com and blogs.nature.com through.
  • The scheme, www. and the path are ignored: https://www.arxiv.org/list is arxiv.org.
  • You can use both lists at once.

Controlling total results

JSON
{
  "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's parameters: searches per request.
  • max_tool_calls, at the root of the request, next to messages or input: 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
  }'

Response

The answer comes with the URLs the model cited, as url_citation annotations:

FormatWhere
Chat Completionsmessage.annotations[]: {"type": "url_citation", "url_citation": {"url", "title", "content", "start_index", "end_index"}}
Responsesannotations[] 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:

JSON
{
  "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 402 in the middle of an answer.

Errors

CaseAnswer
An Uncensored model400 invalid_request, with the message in Which models
An engine other than auto or native400 invalid_request: Unsupported web search engine
A parameter out of range, or max_tool_calls outside 1 to 30400 invalid_request, with the parameter in the message
n greater than 1400 invalid_request
A function of yours named web_search400 invalid_request: rename it
A search that doesn't answerThe 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.

BeforeNow
"model": "<model>:online""tools": [{"type": "openrouter:web_search"}]
plugins: [{"id": "web", "max_results": 3}]"parameters": {"max_results": 3}
include_domains / exclude_domainsallowed_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.