---
title: "Claude Web Search Tool (API): Setup, Pricing & Dynamic Filtering"
description: "How to enable web search in the Claude API with web_search_20260209, read citations, handle pause_turn, use dynamic filtering and domain filters, what it costs, and when to use your own search tool instead."
category: "guides"
url: https://keirolabs.cloud/blog/claude-web-search-tool
published: 2026-11-24
updated: 2026-11-24
---

# Claude web search tool: setup, dynamic filtering, pricing and limits

## The 60-second version

**The Claude web search tool lets Claude search the web during a Messages API request, read the results and answer with citations, all server-side.** You add one tool definition. There's no search code to write and no loop to run for the searches themselves.

```json
{ "type": "web_search_20260209", "name": "web_search" }
```

| Detail | Value |
|---|---|
| Tool type | `web_search_20260209` (with dynamic filtering); older `web_search_20250305` without it |
| Price | **$10 per 1,000 searches**, plus the result tokens as input |
| Controls | `max_uses`, `allowed_domains` or `blocked_domains`, `user_location` |
| Output | Search result blocks, plus text blocks with citations |
| Long turns | May stop with `stop_reason: "pause_turn"`; send it back to continue |
| Google Cloud Vertex AI | Only the basic `web_search_20250305` version |

**Use it when** you want cited answers with the least code. **Bring your own search tool when** you need control over sources, caching, zero data retention or cost at volume. That comparison is further down.

## How do I enable web search in the Claude API?

**Add the tool to `tools` and Claude decides when to search.** In Python with the Anthropic SDK:

```python
import anthropic

client = anthropic.Anthropic()

response = client.messages.create(
    model="claude-opus-5-5",
    max_tokens=16000,
    tools=[{
        "type": "web_search_20260209",
        "name": "web_search",
        "max_uses": 5,                                   # cap searches per request
        "allowed_domains": ["nextjs.org", "github.com"], # or blocked_domains, not both
    }],
    messages=[{"role": "user", "content": "What changed in the latest Next.js release?"}],
)

for block in response.content:
    if block.type == "text":
        print(block.text)
        for c in block.citations or []:
            print("   source:", c.url)
```

**What comes back:** the response holds a mix of blocks.

- **`server_tool_use`:** the query Claude ran.
- **`web_search_tool_result`:** the results it got.
- **`text`:** the answer, with `citations` pointing at the sources each passage relies on.

Print the text blocks for the answer, and their citations for the sources.

**Handle `pause_turn`.** The server runs its own search loop. If that loop hits its iteration limit (10 by default), the response ends with `stop_reason: "pause_turn"`. Append the response to the conversation as an assistant turn and send the request again, and Claude continues where it stopped:

```python
messages = [{"role": "user", "content": "Compare the pricing pages of three vector databases."}]
while True:
    response = client.messages.create(model="claude-opus-5-5", max_tokens=16000,
                                      tools=[{"type": "web_search_20260209", "name": "web_search"}],
                                      messages=messages)
    if response.stop_reason != "pause_turn":
        break
    messages.append({"role": "assistant", "content": response.content})
```

**Search errors don't raise HTTP errors.** If a search fails, the request still returns 200, and the result block carries an error object instead of a result list. Check the block before assuming results.

## What is dynamic filtering?

**With `web_search_20260209`, Claude can write and run code to filter search results before they enter its context window.** It drops irrelevant results and trims long ones, which improves accuracy and saves tokens. Dynamic filtering is supported on current Claude models, including Claude Opus 5.5, Opus 5, Sonnet 5.5, Sonnet 5, and the Fable and Mythos models. Code execution used this way is free when it runs alongside web search or web fetch.

**Pair it with web fetch** (`web_fetch_20260209`) when Claude should read whole pages, not just search results:

```python
tools = [
    {"type": "web_search_20260209", "name": "web_search"},
    {"type": "web_fetch_20260209", "name": "web_fetch"},
]
```

## How much does Claude web search cost?

**$10 per 1,000 searches, plus tokens.** The search results count as input tokens in the turn where they appear. In a multi-turn conversation, they count again in every later turn, because they stay in the history.

| Volume | Search fee | Plus |
|---|---|---|
| 1,000 searches | $10 | Result tokens at the model's input rate |
| 100,000 searches | $1,000 | Same |
| 1,000,000 searches | $10,000 | Same |

**The token side often costs more than the search fee in long conversations.** Cap searches with `max_uses`, keep conversations short when you can, and let dynamic filtering trim results. There's a full cost comparison of built-in search across providers in [web search in LLM APIs](/blog/llm-web-search-api).

## Built-in web search or your own search tool?

| | Claude web search tool | Your own `web_search` tool |
|---|---|---|
| Code | One tool definition | A function plus a tool-use loop (about 30 lines) |
| Citations | Built in | You add them in the prompt and check them |
| Search cost | $10 per 1,000 | Your provider's price, e.g. $0.03 to $0.10 per 1,000 on Keirolabs plans |
| Choice of results | Claude's, within your domain filters | Yours: filter, rerank, cache before Claude sees them |
| Data retention | Anthropic's policy for the tool | Your search provider's; Keirolabs offers `"zdr": true` on paid plans |
| Platforms | Claude API; basic version on Vertex AI | Anywhere, any model |

**Choose built-in** for prototypes, low volume, or when citation formatting matters most. **Choose your own tool** when search volume is high, when you need to control or cache what Claude reads, or when you need the same search layer across Claude, OpenAI and local models.

**Your own tool in short:** define a custom `web_search` tool, run the search in your code when Claude calls it, and return the results as a `tool_result`. The full loop, with OpenAI-compatible and local-model versions, is in [how to give an LLM a web search tool](/blog/llm-web-search-tool-calling). For zero data retention across the whole chain, see [ZDR for AI and search APIs](/blog/zero-data-retention-ai-apis).

## Common problems

- **Claude doesn't search.** Questions it can answer from training won't trigger a search. Ask about something recent, or say "search the web" in the system prompt for time-sensitive tasks.
- **Searches hit unwanted sites.** Use `allowed_domains` for a strict list or `blocked_domains` to exclude a few. You can't use both at once.
- **Local results are wrong.** Set `user_location` (for example, an approximate country) for location-dependent questions.
- **The response ends early.** Check for `pause_turn` and continue.
- **Costs climb in long chats.** Old search results are re-sent every turn. Start fresh conversations for new topics.

New Keirolabs accounts get up to 2,000 free credits with no card, to try your own search tool side by side with the built-in one ([get a key](https://platform.keirolabs.cloud/register)).
