The web search tool gives Claude direct access to real-time web content, allowing it to answer questions with up-to-date information beyond its knowledge cutoff. The response includes citations for sources drawn from search results.
With web_search_20260209 and later versions, Claude can write and run code that filters the search results before they reach the context window (dynamic filtering), keeping only relevant information. Dynamic filtering is available with Claude 4.6 and later models and Claude Mythos Preview.
Three versions of the web search tool are available:
web_search_20250305: basic web searchweb_search_20260209: adds dynamic filteringweb_search_20260318: adds response inclusion control for agentic workflowsThe examples on this page use web_search_20250305 for basic search and web_search_20260318 for dynamic filtering.
For web search's Zero Data Retention eligibility and the related allowed_callers configuration, see Server tools.
For model support, see the Tool reference.
When you add the web search tool to your API request:
Claude searches when the request depends on information that is current, changing, or outside its training data:
Claude answers directly without searching when the request draws on stable knowledge:
Triggering is steerable through your system prompt: you can encourage Claude to search more readily or to prefer answering directly. For a hard constraint, use max_uses to cap the number of searches for each request.
With basic web search, every search result is loaded into Claude's context window, and much of that content can be irrelevant to the request. With web_search_20260209 or later, Claude instead writes and runs code that filters the results first, so only relevant content reaches the context window. This reduces token use on search-heavy requests.
Dynamic filtering runs web search from inside code execution: on web_search_20260209 and later, the tool's allowed_callers field defaults to ["code_execution_20260120"], and when dynamic filtering runs, the API provisions the code execution it needs for the request automatically. You don't need to add the code execution tool to tools yourself. There are no additional charges for code execution calls made this way beyond the standard token costs.
To call web search directly, without dynamic filtering, set allowed_callers: ["direct"]. Models that don't support programmatic tool calling require this setting. Without it, the API returns a 400 error that tells you to set it.
The following examples use web_search_20260318:
client = anthropic.Anthropic()
response = client.messages.create(
model="claude-opus-5",
max_tokens=4096,
messages=[
{
"role": "user",
"content": "Search for the current prices of AAPL and GOOGL, then calculate which has a better P/E ratio.",
}
],
tools=[{"type": "web_search_20260318", "name": "web_search"}],
)
print(response)Provide the web search tool in your API request:
client = anthropic.Anthropic()
response = client.messages.create(
model