← LearnClaude API · Tools

How Does the Claude Web Search API Tool Work?

The Claude web search API tool is a built-in, server-side feature that lets Claude autonomously retrieve live web content during inference. You add it to your API request's tools array, and Anthropic's servers handle the searches, returning a synthesized answer with cited source URLs — all in a single API turn.

The Claude web search API tool is a built-in, server-side feature that gives Claude autonomous access to live web content during inference. You include it in your API request, and Anthropic's infrastructure handles everything: deciding when to search, executing the queries, retrieving content, and synthesizing a final response with cited source URLs — all within a single API turn. No custom scraping code, no third-party search API keys, no client-side round trips required.

What Exactly Is the Claude Web Search Tool?

Anthropic classifies this as a server tool, which distinguishes it from ordinary function-calling tools. With a typical custom tool, your application has to handle intermediate tool-use round trips: Claude signals it wants to call a function, your server runs the function, you send the result back, and Claude continues. With the web search tool, all of that happens on Anthropic's side. Your application sends one request and receives one final response.

Claude can issue multiple searches within a single request, filter and reason over the results, and return a coherent answer with citation objects containing the source URL, page title, and the specific text cited. This makes it practical for any situation where Claude's training knowledge cutoff would otherwise limit accuracy — current events, live pricing, recent documentation updates, regulatory changes, and more.

You can learn more in the official Anthropic web search tool documentation.

How Do You Enable and Configure the Web Search Tool?

Getting started requires a few straightforward steps:

  1. Enable at the organization level. Log in to the Anthropic Console and ensure your organization administrator has enabled web search for your organization.
  2. Obtain an API key. Get a valid Anthropic API key from the Console.
  3. Add the tool to your request. In your API request, add the tool definition to the tools array using the type identifier for the version you want and name it web_search.
  4. Optionally configure filtering parameters. You can cap searches per request, whitelist specific domains, blacklist domains, or localize results — more on these below.
  5. Send the request. Claude autonomously decides when to search, executes searches server-side, and returns a final response with citation objects.
  6. Render citations. Extract and display the URL, title, and cited text fields from citation objects before showing output to users — this is required by Anthropic's usage policy.

What Optional Parameters Can You Set?

Inside the tool definition object, four optional parameters give you meaningful control:

  • max_uses — an integer that caps how many searches Claude can issue per request, useful for keeping per-request costs predictable.
  • allowed_domains — an array of domain strings that whitelists specific sources. Claude will only retrieve content from those domains.
  • blocked_domains — an array of domain strings that blacklists specific sources.
  • user_location — an object that localizes search results to a specific city, region, and country.

Important: You cannot use allowed_domains and blocked_domains in the same request. Choose one strategy. Also note that request-level domain restrictions can only further narrow what the organization-level policy already permits — they cannot expand beyond it.

What Does a Minimal Working Example Look Like?

Here is the simplest possible configuration — a current-events question with no optional parameters:

import anthropic
client = anthropic.Anthropic()
response = client.messages.create(
    model='claude-sonnet-4-5-20250929',
    max_tokens=512,
    messages=[{"role": "user", "content": "Who won the most recent FIFA World Cup and what was the final score?"}],
    tools=[{"type": "web_search_20260209", "name": "web_search"}]
)
print(response.content)

The response will include a text block with the synthesized answer drawn from live sources, plus at least one citation object containing the URL, title, and cited text pointing to the source page. This minimal example confirms the tool is correctly enabled at the org level and that the API key has access.

How Does Domain Restriction Work in Practice?

One of the most practical configurations is restricting Claude to a single authoritative domain. For example, a developer tools company that wants Claude to answer questions exclusively from their official documentation site can set allowed_domains to that subdomain. The result is a highly accurate documentation assistant without building and maintaining a custom RAG vector database or chunking pipeline.

{
  "model": "claude-sonnet-4-5-20250929",
  "max_tokens": 1024,
  "tools": [{"type": "web_search_20260209", "name": "web_search", "allowed_domains": ["react.dev"]}],
  "messages": [{"role": "user", "content": "How does the useTransition hook work in React?"}]
}

All citations in the response will point exclusively to pages under the whitelisted domain — no third-party blog posts or community forums mixed in.

What Changed With the Latest Tool Version?

The most significant recent update introduced dynamic filtering. The newer tool version enables Claude to write and execute server-side code to pre-filter retrieved HTML before it enters the context window. This reduces token consumption and improves response accuracy compared to the earlier version, which passed full HTML into context without pre-filtering — a meaningful difference on noisy or content-heavy pages.

The earlier version remains available for models that do not support the newer one. See the Anthropic API release notes for the full changelog.

What Are the Most Common Pitfalls?

Token bloat from unfiltered HTML

Using an older tool version means full HTML is passed into context, increasing token costs and potentially degrading response quality. Use the latest version on a supported model to get dynamic filtering.

Mixing allowed_domains and blocked_domains

The API does not allow both in a single tool definition. Using both will result in a validation error. Pick one strategy per request.

Omitting citations from user-facing output

Anthropic's usage policy requires that citations be displayed to end users when surfacing web search results directly. Always extract and render the URL, title, and cited text fields from citation objects. Do not silently drop source attribution.

Handling pause_turn responses

If Claude hits the max_uses limit mid-turn, the response stop reason signals a pause. Re-submit the response as-is in a subsequent request to let Claude continue, or handle the interruption in your application logic. Also handle error codes in search result blocks that indicate the limit was exceeded.

Using an unsupported model with the dynamic filtering version

The latest tool version only works with specific supported models. Using it with an unsupported model will cause an error. Fall back to the earlier version for models not on the supported list, or upgrade the model.

When Should You Use Web Search vs. Alternatives?

Approach Best when… Not ideal when…
Claude web search tool You need live public web content with zero client-side infrastructure — no search API keys, no scraping code, no round-trip tool calls You need full control over the search provider, result ranking, or post-processing pipeline; or you're on a platform where the tool is unavailable
Custom function-calling + third-party search API You need a specific search provider, custom ranking logic, or must operate on a platform where Anthropic's tool isn't available You want simplicity and don't want to manage API keys, quotas, or scraping infrastructure
RAG with a vector database You have a fixed, proprietary document corpus (internal wikis, PDFs, contracts) that cannot be publicly crawled You need live, public web content retrieved at query time and don't have a pre-existing corpus to index
web_fetch tool You already know the exact URL of a document and need Claude to ingest its full content You need discovery — finding the right sources across the public web — rather than ingesting a known URL
Document upload at request time You've already collected the relevant source material and want to avoid external network calls or ensure reproducibility Freshness is the primary requirement and the answer must reflect live data

The tool use overview in Anthropic's documentation covers how server tools fit into the broader tool-use architecture.

What Are the Best Real-World Use Cases?

  • Real-time financial data — pulling live stock prices, P/E ratios, and earnings summaries from financial sites with cited sources users can verify.
  • Domain-restricted documentation assistant — answering questions using only an official docs site, replacing a custom RAG pipeline for documentation-heavy products.
  • Legal and regulatory research — surfacing recent court decisions, newly enacted regulations, or agency guidance that postdates the training cutoff, with citations back to primary sources.
  • Competitive intelligence — enriching company lists with current funding rounds, product launches, and executive changes across dozens of entities in a single pipeline.
  • SEC filing and earnings analysis — grounding due-diligence workflows in primary SEC filings with direct URLs rather than potentially outdated secondary sources.
  • Up-to-date developer tooling reference — referencing the latest API documentation, release notes, or changelogs for rapidly evolving frameworks at query time.

Frequently asked questions

Does the Claude web search tool require me to handle tool-use round trips in my application?

No. The web search tool is a server-side tool, meaning Anthropic's infrastructure handles the searches internally. Your application sends one request and receives one final response with citations — no intermediate round trips required.

Can I restrict Claude to only search specific websites?

Yes. You can add an allowed_domains parameter to the tool definition with an array of domain strings. Claude will only retrieve content from those domains. Note that you cannot combine allowed_domains and blocked_domains in the same request.

Do I have to display citations to users?

Yes. Anthropic's usage policy requires that citations be displayed to end users when surfacing web search results directly. Always extract and render the URL, title, and cited text fields from citation objects in the response.

What is dynamic filtering and why does it matter?

Dynamic filtering, introduced in the latest tool version, allows Claude to write and execute server-side code to pre-filter retrieved HTML before it enters the context window. This reduces token consumption and improves accuracy compared to the earlier version, which passed full HTML into context.

How is the web search tool different from the web_fetch tool?

The web search tool is for discovery — finding relevant sources across the public web when you don't know the exact URL. The web_fetch tool is for ingestion — when you already know the exact URL and want Claude to read its full content. The two tools are complementary.

Can I limit how many searches Claude performs per request?

Yes. Set the max_uses parameter to an integer in the tool definition. This caps the number of searches Claude can issue in a single request, which helps keep per-request costs predictable.

Go deeper

Web search tool (API) is one of 85 features in Claude Master — the independent, continuously updated manual with worked examples, the pitfalls, and the workflows that put Claude to work.

Get Claude Master — founding price →

Independent product. Not affiliated with or endorsed by Anthropic. "Claude" is a trademark of Anthropic, used here only to describe the subject of this guide.