LLM Web Search API: Add Search to Any Model
Web search used to depend on the provider, so adding it meant switching models. With LLM Gateway's web search API, one tool definition works on every chat model: natively where the provider searches, and through a gateway-run search loop everywhere else, with the same citations and cost reporting.
By LLM Gateway

A model's knowledge stops at its training cutoff. Ask it about this week's release, today's exchange rate or a regulation that changed last month, and it either refuses or guesses. Web search fixes that, but until recently only some providers offered it, each with its own request format. Choosing to search meant choosing the model, and often the most expensive one.
An LLM web search API should work the other way around: pick the model for the task, and add search with one line. That is how web search works on LLM Gateway now. The same web_search tool runs on every chat model, with the same response format and the same cost reporting.
Add web search with one tool
1curl https://api.llmgateway.io/v1/chat/completions \2 -H "Authorization: Bearer $LLM_GATEWAY_API_KEY" \3 -H "Content-Type: application/json" \4 -d '{5 "model": "gpt-5.2",6 "messages": [{ "role": "user", "content": "What shipped in AI this week?" }],7 "tools": [{ "type": "web_search" }]8 }'1curl https://api.llmgateway.io/v1/chat/completions \2 -H "Authorization: Bearer $LLM_GATEWAY_API_KEY" \3 -H "Content-Type: application/json" \4 -d '{5 "model": "gpt-5.2",6 "messages": [{ "role": "user", "content": "What shipped in AI this week?" }],7 "tools": [{ "type": "web_search" }]8 }'Or set "web_search": true at the top level and the gateway adds the tool for you. The answer comes back with url_citation annotations. Native search usually marks which span of text each source supports; gateway-run search and some providers return the source with both offsets set to 0:
1{2 "type": "url_citation",3 "url_citation": {4 "url": "https://example.com/article",5 "title": "Article Title",6 "start_index": 0,7 "end_index": 508 }9}1{2 "type": "url_citation",3 "url_citation": {4 "url": "https://example.com/article",5 "title": "Article Title",6 "start_index": 0,7 "end_index": 508 }9}Citations use this format on every provider, in chat completions and in /v1/responses, streamed or not.
Native search and gateway-run search
Behind the same request there are two ways a search can run.
| Mode | When | Who runs the search | Billed at |
|---|---|---|---|
| Native search | The serving provider has built-in search | The provider | The model's web search price |
| Gateway-run search | The serving provider has no built-in search | LLM Gateway, with an engine | Your engine's price per search |
A few providers only search natively when the request requires it; web_search_forced_only in /v1/models marks them, and on those you set tool_choice to require a search.
In gateway-run search, LLM Gateway gives the model a web_search function. The model decides whether the turn needs a search, writes its own queries, reads the results, searches again if it needs to, and then answers. That loop is what separates it from "search once and paste the results": a model can refine a query that came back empty, or follow up on something it found.
On /v1/responses, on models without tool calling, and in a few other cases, the loop is replaced by a single search before the model answers: a small model writes up to three queries from the latest turns, and the results are added to your latest user message.
Each model call in the loop shows up in your activity log as the request ID plus -ws0, -ws1, and so on, and the response's usage adds them all up. Text the model writes before a search streams immediately, so users see progress instead of a spinner.
Control the search
The tool takes a few options that work in both modes where the provider supports them:
| Option | Effect |
|---|---|
max_uses | Caps searches in the gateway-run loop (default 5) |
search_context_size | Results per search: low 3, medium 5, high 10 |
user_location | Location context for local results |
allowed_domains | Restrict search to listed domains |
blocked_domains | Exclude listed domains |
To require a search on every request, set tool_choice: {"type": "web_search"}. DeepSeek is the exception: on requests it serves, the model still decides whether to search, so pin another provider when every answer must cite fresh sources. Use it sparingly: a forced search is billed on every request, and the retrieved snippets are billed as input tokens too. For a chat interface with a search toggle, leaving the tool attached with the default tool_choice is usually better, so a follow-up like "make it shorter" does not trigger a search.
Choose the search engine
Gateway-run searches use an engine your organization picks under Settings → Preferences → Web Search. Only owners can change it.
| Engine | Price per search | Data handling |
|---|---|---|
| Perplexity Search (default) | $0.005 | No training on queries; retention is not zero |
| Exa | $0.007 | Queries may be retained and used for training |
The engine sees your search queries, so it is treated like a provider: if your organization's or API key's compliance policy rejects it, no search runs. Your activity log records which engine ran each search.
Check support per provider
GET /v1/models reports how search works for each model and provider:
1curl -s https://api.llmgateway.io/v1/models \2 | jq '.data[] | select(.id == "glm-5.4") | .providers[] | {providerId, web_search, web_search_native}'1curl -s https://api.llmgateway.io/v1/models \2 | jq '.data[] | select(.id == "glm-5.4") | .providers[] | {providerId, web_search, web_search_native}'web_search_native tells you whether the provider searches itself, and web_search_forced_only flags providers whose native search runs only when the request requires one. If you need raw ranked results instead of a written answer, use the Search API.
Add search to your models
Frequently asked questions
- What is an LLM web search API?
- An API that lets a language model search the web while it answers, read the results and cite its sources. In LLM Gateway you add {"type": "web_search"} to the tools array of a chat completions or Responses request, and the model decides when to search.
- Which models support web search on LLM Gateway?
- Every chat model. Models with native web search search through their provider. For every other chat model, LLM Gateway gives the model a web_search function and runs the searches it asks for, so the request and response look the same either way.
- How much does LLM web search cost?
- Native search is billed per search at the model's web search price. A gateway-run search is billed per search at your organization's engine price: $0.005 for Perplexity Search, the default, or $0.007 for Exa. The search cost is included in usage.cost and shown separately as costdetails.websearch_cost.
- How do I know if a provider searches natively?
- Read the model's providers array in GET /v1/models. websearch is true when the tool works on that provider, websearchnative is true when the provider runs the search itself, and websearchforcedonly is true when native search runs only when the request requires a search.
Models and providers in this post
Providers
One API key for every model.
Route to 200+ models with automatic failover, caching, and real-time cost analytics. Free to start — no credit card required.
Not ready to switch yet?
Follow new model releases instead.
A short roundup when new models land. Unsubscribe anytime.