Skip to Content
ModelsClaudeWeb search

Claude web search

This page explains how to let Claude search the web with the web_search tool. For model IDs, endpoints and providers, see the Claude family overview.

Key pointWeb search requires the Anthropic provider, is limited to Fable 5, Opus 4.8, Opus 4.7 and Sonnet 5, and works only on the Anthropic-native API.

Add the official web_search server tool to tools. The model runs searches on its own and cites sources in its answer:

claude_web_search.py
import os import anthropic client = anthropic.Anthropic( base_url="https://api.ofox.ai/anthropic", api_key=os.environ["OFOX_API_KEY"], default_headers={"X-OfoxAI-Provider-Type": "anthropic"}, ) message = client.messages.create( model="anthropic/claude-sonnet-5", max_tokens=1500, tools=[{"type": "web_search_20250305", "name": "web_search", "max_uses": 3}], messages=[{"role": "user", "content": "What is the latest stable version of Python?"}], ) print("".join(b.text for b in message.content if b.type == "text")) print("Searches:", message.usage.server_tool_use.web_search_requests)
  • The response content contains, in order, server_tool_use (search queries), web_search_tool_result (search results) and text (answer) blocks.
  • usage.server_tool_use.web_search_requests is the actual number of searches. Searches are billed per use; see the model page  for the rate.
  • max_uses caps the number of searches in a single request.

For other errors, see Common errors.

Last updated on