Skip to content
한국어

Let Claude Search and Read the Web via the API: Web Search and Web Fetch Tools

In short
  • Web search and web fetch are server tools: the API runs them for you, so unlike Dev 1 you don’t write a loop that returns tool_result. You just add an entry to tools.
  • Web search finds pages and always returns citations. Web fetch reads the full content of a specific URL (text, HTML, PDF) and its citations are off by default.
  • Control the blast radius with max_uses, allowed_domains / blocked_domains (one or the other, not both), and for fetch max_content_tokens.
  • Cost (official docs, 2026-10-31): search is $10 per 1,000 searches plus token costs; fetch has no extra charge beyond tokens. Fetched pages become input tokens, so cap them.
  • New on October 20, 2026: org admins can turn off web fetch, or set allowed/blocked domains for it, on the Console Capabilities page.
  • We read the official pages on 2026-10-31 but made no real API calls. The code below follows the documented parameters and is not something we ran.

What you’ll be able to do after this tutorial

Section titled “What you’ll be able to do after this tutorial”
  • Add web_search and web_fetch to a Messages API request and pick the right tool version.
  • Limit which sites Claude can reach, and cap searches, fetches, and fetched tokens.
  • Read the response, show citations to users, and handle tool errors that arrive inside a 200 response.
  • Explain the safety rules (data exfiltration risk, URL validation) and where the organization-level switch lives.

In Dev 1 you wrote the loop yourself: Claude asks, your code runs the function, you send back a tool_result. Web search and web fetch are different. They are server tools: the API performs the search or fetch during your request and puts the results into the conversation. For citations in your own documents, see Dev 9. For driving a real browser (JavaScript pages, clicking), see Dev 10.

Term Meaning
Server tool A tool Anthropic runs. You see server_tool_use and result blocks in the response.
Web search Claude searches the web and answers with cited sources.
Web fetch Claude retrieves the full text of a URL that already appeared in the conversation.
Dynamic filtering With *_20260209 or later, Claude writes and runs code to trim results before they reach its context. Needs Claude 4.6 or later.
Domain filter allowed_domains or blocked_domains on the tool.
Tool Versions What was added
Web search web_search_20250305 Basic search
web_search_20260209 Dynamic filtering
web_search_20260318 response_inclusion control
Web fetch web_fetch_20250910 Basic fetch
web_fetch_20260209 Dynamic filtering
web_fetch_20260309 Cache bypass (use_cache)
web_fetch_20260318 response_inclusion control

On web_search_20260209 and later, allowed_callers defaults to the code execution tool so dynamic filtering can run. The API sets up that code execution for you, with no extra charge beyond tokens. Models that can’t do programmatic tool calling need allowed_callers: ["direct"], or the API returns a 400 error. Dynamic filtering is not eligible for zero data retention (ZDR) or HIPAA.

0/5 done
  1. Get set up

    Terminal window
    mkdir web-tools-lab && cd web-tools-lab
    python3 -m venv .venv && source .venv/bin/activate
    pip install anthropic

    Set ANTHROPIC_API_KEY as in C16. Web search is on for your organization unless an administrator turned it off in the Claude Console; if it’s off, a request that includes the tool fails with a 400 invalid_request_error. Use a model that supports it. The docs list, among others, claude-opus-5-5, claude-sonnet-5-5, and claude-haiku-5-5. You can check a model’s capabilities.server_tools.web_search.supported in the Models API.

  2. Add web search

    One entry in tools is enough. Here we limit searches to 3 and restrict the sites. allowed_domains takes bare domains like example.com or example.com/blog, with no https://. Subdomains are included automatically.

    import anthropic
    client = anthropic.Anthropic()
    response = client.messages.create(
    model="claude-opus-5-5",
    max_tokens=2048,
    messages=[{
    "role": "user",
    "content": "What changed in the Claude Platform release notes this week? Summarize in 3 bullets.",
    }],
    tools=[{
    "type": "web_search_20260318",
    "name": "web_search",
    "max_uses": 3,
    "allowed_domains": ["platform.claude.com"],
    }],
    )
    for block in response.content:
    if block.type == "text":
    print(block.text)
    for c in (getattr(block, "citations", None) or []):
    print(" source:", c.title, c.url)
    print("searches:", response.usage.server_tool_use.web_search_requests)

    We did not run this snippet. The block and field names (text, citations, url, title, usage.server_tool_use.web_search_requests) come from the example response in the official docs.

    Copy and paste this prompt

    Search the web for the official pricing page of the tool I name, summarize the price in two sentences, and list the URL you used. If you can’t find an official page, say so instead of guessing.

  3. Read the response and show citations

    The response contains Claude’s short note, a server_tool_use block (the query), a web_search_tool_result block (URL, title, page_age, and encrypted_content), and text blocks with citations. Each citation has url, title, cited_text (up to 150 characters), and encrypted_index.

    Two rules matter in multi-turn use. Send the assistant content blocks back exactly as received, including encrypted_content; if it’s missing or changed, the request fails with a 400. And when you show the output to end users, include the citations to the original source. The citation fields cited_text, title, and url don’t count toward token usage.

  4. Add web fetch for a specific page

    Fetch retrieves the full text of a URL. For PDFs it returns base64 data and processes it like an attached PDF. It does not support pages rendered dynamically with JavaScript.

    response = client.messages.create(
    model="claude-opus-5-5",
    max_tokens=2048,
    messages=[{
    "role": "user",
    "content": "Read https://platform.claude.com/docs/en/agents-and-tools/tool-use/web-fetch-tool and list the error codes.",
    }],
    tools=[{
    "type": "web_fetch_20260318",
    "name": "web_fetch",
    "max_uses": 2,
    "allowed_domains": ["platform.claude.com"],
    "max_content_tokens": 30000,
    "citations": {"enabled": True},
    }],
    )

    We did not run this snippet either. max_content_tokens truncates large text content (it does not apply to PDFs and is approximate). There is no default max_uses, so set one. Citations are optional for fetch and disabled by default. Domain matching for fetch is on the domain only: an entry with a path never matches a fetch URL.

    For rough budgeting the docs give: an average web page (10 kB) is about 2,500 tokens, a large documentation page (100 kB) about 25,000, and a research paper PDF (500 kB) about 125,000.

  5. Combine search and fetch

    With both tools enabled and a request that names a page without a URL (such as “read the README of the anthropic-sdk-python repository”), Claude searches to find it, picks the best results, and fetches them. Keep allowed_domains tight in this setup, because search results can bring new URLs into the conversation.

  6. Check the organization switch

    An organization admin can turn web search or web fetch off, or restrict domains, on the Capabilities page of the Claude Console. Request-level allowed_domains must be a subset of the organization-level allowed list, otherwise the API returns a validation error. If an org blocks a domain you list, you get a 400 naming the conflicting entries.

Where an admin controls web fetch (as of 2026-10-31)
  1. Claude Console, Capabilities pageTurn web fetch on or off for the organization→ With it off, a Messages API request that includes the tool fails with a 400 error
  2. Same page, with web fetch onSet allowed or blocked domains for web fetch→ Your request-level lists work together with these
  3. Your requestOptionally add allowed_domains or blocked_domains on the tool→ Allowed list must be a subset of the org list

This is a simplified flow. See the official help page for the actual screens.

The release notes for October 20, 2026 say admins can now turn off web fetch for their organization on the Capabilities page, and, with it on, set allowed or blocked domains for web fetch there. The same entry says Claude Managed Agents sessions follow these settings: a URL, including one reached by a redirect, must pass both the organization’s list and the agent’s own allowed_domains / blocked_domains. Web search in Managed Agents follows the Allow web search setting (since October 6) and web search domain restrictions (since October 14). In Managed Agents the tools are on by default in the agent toolset and don’t accept max_uses, citations, or cache_control.

Item Web search Web fetch
Citations Always on Optional, off by default (citations.enabled)
Usage cap max_uses (error max_uses_exceeded) max_uses (no default; failed fetches count)
Domain rules Subpaths supported Domain only
Size control None documented max_content_tokens (text only)
Price $10 per 1,000 searches plus tokens No extra charge, tokens only
ZDR Eligible (not for Covered Models or dynamic filtering) Eligible (same exclusions)
HIPAA Eligible (not dynamic filtering) Not eligible
Batch API Allowed, same price, throttled per org Allowed, same price

Domain filter rules from the Server tools page: no scheme, subdomains included, * only in the path (not in the domain), and never both allowed_domains and blocked_domains. Use ASCII-only domain names, because look-alike Unicode characters can bypass filters.

Errors arrive inside a 200 response, as a single error object in content. Search codes: too_many_requests, invalid_tool_input, max_uses_exceeded, query_too_long, request_too_large, unavailable. Fetch adds url_too_long (over 250 characters), url_not_allowed, url_not_in_prior_context, url_not_accessible, unsupported_content_type (only text, HTML, PDF), and content_too_large. A search with no matches returns an empty content list, not an error.

The request fails with 400 about web search or web fetch not being enabled

Section titled “The request fails with 400 about web search or web fetch not being enabled”
  • Cause: An org admin turned the capability off.
  • Fix: Ask the admin to check the Capabilities page in the Console.
  • Cause: allowed_domains and blocked_domains can’t be combined.
  • Fix: Choose one.
  • Cause: The URL appeared only in Claude’s own output, or only in a source your url_sources setting excludes.
  • Fix: Put the URL in a user message.
  • Cause: The API paused a long-running search turn.
  • Fix: Send the paused assistant message back unchanged in a new request to continue.
  • Cause: encrypted_content was dropped or edited.
  • Fix: Send assistant content blocks back exactly as received.
  • Start with max_uses of 3 to 5. The docs say simple factual queries typically use 1 to 3 searches and multi-entity research can use 10 or more.
  • Use a system prompt to steer whether Claude searches readily or answers directly; use max_uses as the hard limit.
  • Prefer dynamic filtering (*_20260209 or later) on token-heavy tasks, but remember it isn’t ZDR or HIPAA eligible.
  • Log usage.server_tool_use so search counts show up in your cost tracking (Dev 11).
  • Pages needing JavaScript or clicks are a job for the browser tool, not fetch.

Sources

Last verified: Nov 2, 2026

Prices, limits, and menu names change often. Before making an important decision, check the official pages above for the latest details.