Web search tool
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. Claude automatically cites sources from search results as part of its answer.
Please reach out through our feedback form to share your experience with the web search tool.
Supported models
Web search is available on:
- Claude 3.7 Sonnet (
claude-3-7-sonnet-20250219
) - Claude 3.5 Sonnet (new) (
claude-3-5-sonnet-latest
) - Claude 3.5 Haiku (
claude-3-5-haiku-latest
)
How web search works
When you add the web search tool to your API request:
- Claude decides when to search based on the prompt.
- The API executes the searches and provides Claude with the results. This process may repeat multiple times throughout a single request.
- At the end of its turn, Claude provides a final response with cited sources.
How to use web search
Your organization’s administrator must enable web search in Console.
Provide the web search tool in your API request:
Tool definition
The web search tool supports the following parameters:
Max uses
The max_uses
parameter limits the number of searches performed. If Claude attempts more searches than allowed, the web_search_tool_result
will be an error with the max_uses_exceeded
error code.
Domain filtering
When using domain filters:
- Domains should not include the HTTP/HTTPS scheme (use
example.com
instead ofhttps://example.com
) - Subdomains are automatically included (
example.com
coversdocs.example.com
) - Subpaths are supported (
example.com/blog
) - You can use either
allowed_domains
orblocked_domains
, but not both in the same request.
Localization
The user_location
parameter allows you to localize search results based on a user’s location.
type
: The type of location (must beapproximate
)city
: The city nameregion
: The region or statecountry
: The countrytimezone
: The IANA timezone ID.
Response
Here’s an example response structure:
Search results
Search results include:
url
: The URL of the source pagetitle
: The title of the source pagepage_age
: When the site was last updatedencrypted_content
: Encrypted content that must be passed back in multi-turn conversations for citations
Citations
Citations are always enabled for web search, and each web_search_result_location
includes:
url
: The URL of the cited sourcetitle
: The title of the cited sourceencrypted_index
: A reference that must be passed back for multi-turn conversations.cited_text
: Up to 150 characters of the cited content
The web search citation fields cited_text
, title
, and url
do not count towards input or output token usage.
Errors
If an error occurs during web search, you’ll receive a response that takes the following form:
These are the possible error codes:
too_many_requests
: Rate limit exceededinvalid_input
: Invalid search query parametermax_uses_exceeded
: Maximum web search tool uses exceededquery_too_long
: Query exceeds maximum lengthunavailable
: An internal error occurred
pause_turn
stop reason
The response may include a pause_turn
stop reason, which indicates that the API paused a long-running turn. You may provide the response back as-is in a subsequent request to let Claude continue its turn, or modify the content if you wish to interrupt the conversation.
Prompt caching
Web search works with prompt caching. To enable prompt caching, add at least one cache_control
breakpoint in your request. The system will automatically cache up until the last web_search_tool_result
block when executing the tool.
For multi-turn conversations, set a cache_control
breakpoint on or after the last web_search_tool_result
block to reuse cached content.
For example, to use prompt caching with web search for a multi-turn conversation:
Streaming
With streaming enabled, you’ll receive search events as part of the stream. There will be a pause while the search executes:
Batch requests
You can include the web search tool in the Messages Batches API. Web search tool calls through the Messages Batches API are priced the same as those in regular Messages API requests.
Usage and pricing
Web search usage is charged in addition to token usage:
Web search is available on the Anthropic API for $10 per 1,000 searches, plus standard token costs for search-generated content. Web search results retrieved throughout a conversation are counted as input tokens, in search iterations executed during a single turn and in subsequent conversation turns.
Each web search counts as one use, regardless of the number of results returned. If an error occurs during web search, the web search will not be billed.
Was this page helpful?