~/academy $ claude learn web-search-and-server-tools
Web search and other server tools
How to add the Claude web search tool and other server tools to API requests, read cited results, handle pause_turn and what each costs, checked today. 8 min
$ Read
Server tools run on Anthropic's side
A server tool is declared in tools like any other, but Anthropic runs it during the request. You write no handler and send no tool_result. The response shows the call as a server_tool_use block (its id starts srvtoolu_) followed by the result block.
The server tools in the docs today are web search, web fetch (read a specific page or PDF), code execution (run Python and Bash in a sandbox), the advisor tool (a faster model consults a stronger one), the tool search tool (find tools on demand from a large set) and the MCP connector (call remote MCP servers from the Messages API).
An organisation admin can switch web search and web fetch off, or restrict domains, on the Capabilities page of the Claude Console. If they are off, requests using them fail with a 400 error.
Lesson notes: Web search and other server tools
Everything in this lesson as text, for revision or to read without the interactive steps. By the end you will be able to: You give your app live, cited web answers with sensible limits and know what each server tool costs.
Step 1 of 6 · Read
Server tools run on Anthropic's side
A server tool is declared in
toolslike any other, but Anthropic runs it during the request. You write no handler and send notool_result. The response shows the call as aserver_tool_useblock (its id startssrvtoolu_) followed by the result block.The server tools in the docs today are web search, web fetch (read a specific page or PDF), code execution (run Python and Bash in a sandbox), the advisor tool (a faster model consults a stronger one), the tool search tool (find tools on demand from a large set) and the MCP connector (call remote MCP servers from the Messages API).
An organisation admin can switch web search and web fetch off, or restrict domains, on the Capabilities page of the Claude Console. If they are off, requests using them fail with a 400 error.
Step 2 of 6 · Read
Add web search
There are three versions:
web_search_20250305(basic),web_search_20260209(adds dynamic filtering, where Claude runs code to filter results before they fill the context) andweb_search_20260318(adds control over which result blocks appear in the response). Dynamic filtering works on Claude 4.6 and later models, and the code execution it needs is provisioned for you at no extra charge.Useful settings:
max_usescaps searches per turn.allowed_domainsorblocked_domains(one or the other, never both) restricts sources, written withouthttps://; subdomains are included.user_locationlocalises results.Search UK government pages only response = client.messages.create( model="claude-opus-5-5", max_tokens=4096, messages=[{"role": "user", "content": "What are the current UK National Living Wage rates?"}], tools=[{ "type": "web_search_20260209", "name": "web_search", "max_uses": 5, "allowed_domains": ["gov.uk"], "user_location": {"type": "approximate", "country": "GB", "timezone": "Europe/London"}, }], )Step 3 of 6 · Read
Reading results and handling pause_turn
The answer comes back as text blocks with
citationsof typeweb_search_result_location, each with aurl,titleand up to 150 characters ofcited_text. If you show the answer to users, show the sources too. To continue the conversation, send the content back unchanged, including each result'sencrypted_content.Search errors do not raise exceptions. The request still returns 200, and the result block's
contentis an error object with anerror_codesuch asmax_uses_exceededinstead of a list of results. Check which shape you got before you loop over it.On long turns the API may stop with
stop_reason: "pause_turn". Send the conversation back with the paused assistant content added and the same tools, and Claude carries on. Cap how many times you continue.Continue a paused turn messages = [{"role": "user", "content": question}] for _ in range(5): response = client.messages.create(model="claude-opus-5-5", max_tokens=4096, tools=tools, messages=messages) if response.stop_reason == "pause_turn": messages.append({"role": "assistant", "content": response.content}) else: break if response.usage.server_tool_use: print("Searches:", response.usage.server_tool_use.web_search_requests)Step 4 of 6 · Read
What it costs (checked 18 November 2026)
Web search: $10 per 1,000 searches, plus normal token prices for the results, which count as input in that turn and in later turns. A failed search is not billed.
usage.server_tool_use.web_search_requeststells you how many ran.Web fetch: no extra charge beyond tokens for the fetched content. For safety it only fetches URLs that already appeared in the conversation (in a user message, a client tool result or an earlier search or fetch), never one Claude made up. It does not render JavaScript-heavy pages. Use
max_content_tokensto cap large pages.Code execution: free when used alongside the 2026-02-09 or later web search or web fetch tools. Otherwise each organisation gets 1,550 free hours a month, then $0.05 per hour per container, with a 5-minute minimum.
Step 5 of 6 · Quiz
Check your understanding
A research feature runs 2,000 web searches in a month. What do the searches themselves cost?
- $2
- Nothing, web search is included in token prices
- $20, plus normal token prices for the search results
- $200
Show the answer
$20, plus normal token prices for the search results 2,000 searches at $10 per 1,000 is $20. The result content is billed as input tokens on top.
Step 6 of 6 · Quiz
Check your understanding
Web fetch keeps returning `url_not_in_prior_context` for a link you put in your system prompt. Why?
- Web fetch only fetches URLs from user messages, client tool results or earlier search and fetch results, not ones only in the system prompt.
- The site blocks Anthropic.
- You have used up `max_uses`.
Show the answer
Web fetch only fetches URLs from user messages, client tool results or earlier search and fetch results, not ones only in the system prompt. This protects against data leaks. Put the URL in the user message if you want Claude to fetch it.