# Server tools

> Web search, web fetch and code execution for any model: native where the provider has them, run by the gateway otherwise.

URL: https://boelabs.com/en/docs/ai-gateway/server-tools
Language: English

A server tool is a tool the API runs itself instead of the client: web search, reading a web page,
running code. Each public contract has its own way to ask for one, and AI Gateway accepts all of them:

| Contract | How a request asks for it |
|---|---|
| [Messages](https://boelabs.com/docs/ai-gateway/messages) | Anthropic's `web_search_*`, `web_fetch_*` and `code_execution_*` tools |
| [Responses](https://boelabs.com/docs/ai-gateway/responses) | The hosted `web_search` and `code_interpreter` tools |
| [Chat completions](https://boelabs.com/docs/ai-gateway/chat-completions) | `web_search_options` |

Whatever model serves the request, the client gets the result in its own contract's shape: Messages
clients receive `server_tool_use` and `web_search_tool_result` blocks (what Claude Code's WebSearch
reads), Responses clients a `web_search_call` or `code_interpreter_call` item, and Chat Completions
clients `annotations` plus `provider_specific_fields.server_tool_calls`.

Only these typed tools are server tools. A function tool you define yourself, even one called
`web_search`, stays yours: the gateway returns its calls to you and never runs it.

## Who runs the tool

For each tool a request asks for, on each deployment, in this order:

1. **The model's provider**, when it runs the tool natively: Anthropic (all three), OpenAI and Azure
   OpenAI on Responses (search and code), OpenAI's search models on Chat Completions (search), and
   Gemini (search through Google Search, fetch through URL context, and code).
2. **The gateway**, with the tool provider you selected for that kind, or with its built-in fetcher
   for web fetch. The model receives a function tool, the gateway runs each call and calls the model
   again with the result, and the client sees one response.
3. **Nobody**: the tool is an unsupported parameter, reported as `server_tools.<kind>` and handled by
   the [parameter policy](https://boelabs.com/docs/ai-gateway/parameter-policy).

The mode per kind changes that order:

| Mode | Behavior |
|---|---|
| `native_first` (default) | The provider when it can, the gateway otherwise |
| `gateway_only` | Always the gateway, for one search engine and one cost everywhere |
| `native_only` | Never the gateway |
| `off` | Never served |

In a pool with several deployments, the router tries those that serve every tool first.

## Tool providers

| Provider | Runs | Notes |
|---|---|---|
| Exa | Web search | Domain filters supported |
| Tavily | Web search | Domain filters supported |
| Brave Search | Web search | Domain filters through query operators |
| Perplexity Search | Web search | Domain filters supported |
| Firecrawl | Web fetch | Returns the page as Markdown |
| Jina Reader | Web fetch | Returns the page as Markdown |
| E2B | Code execution | One sandbox per call, without internet access, deleted afterwards |
| Built-in fetcher | Web fetch | No key; public HTTPS only, the same SSRF protection as file inputs |

Web search has no built-in engine: without a native search and without a provider, it is lost.

Add providers in **Settings → Server tools** or with the admin API, then pick one per kind:

```bash
curl -X POST "$GATEWAY/admin/tool-providers" \
  -H "Authorization: Bearer $MASTER_KEY" -H "Content-Type: application/json" \
  -d '{ "name": "Exa", "providerKey": "exa", "apiKey": "...", "centsPerCall": 0.7 }'

curl -X PUT "$GATEWAY/admin/router-settings" \
  -H "Authorization: Bearer $MASTER_KEY" -H "Content-Type: application/json" \
  -d '{ "serverTools": { "web_search": { "providerId": "<id>" } } }'
```

The key is encrypted like deployment credentials and never returned. Code sandboxes run code a model
wrote, so only the owner (`extensions:manage`) can add or change one.

## Limits

- `max_uses` from the request is enforced; a call over it reaches the model as `max_uses_exceeded`.
- A request spends at most `serverTools.maxRounds` model calls on gateway tools (8 by default). The
  last round offers the model no gateway tools, so it answers with what it found.
- Each call has 30 seconds. A failing provider is reported to the model as an error result
  (`too_many_requests`, `unavailable`, `url_not_accessible`), and the request continues.
- A request that asks for several completions (`n` above one) is not served by gateway tools.

## Cost and usage

Every round is a model call of its own, so its tokens add up in the operation's usage. Calls appear in
`usage.serverToolCalls` per kind (Messages clients see `server_tool_use.web_search_requests`). The
gateway's own calls are priced at the provider's `centsPerCall`; native calls at the model's
`serverToolCallCents` pricing. The catalog declares it for web search on every Claude model ($10 per
1,000), on current OpenAI models ($10 per 1,000) and on Gemini 3 and newer ($14 per 1,000 queries,
without Google's monthly free allowance); a deployment's pricing override can set it for any other
model. Both count against virtual key budgets.

## Replaying a conversation

Clients send server tool turns back in later requests. A call the gateway ran, or one a provider ran
for another provider's wire, reaches the next model as text, never as a native block a provider would
reject. Native blocks go back unchanged only to the provider that made them.

