View Source Anthropic.Tools.WebSearch (anthropic_community v0.5.0)

Builds the web search server tool definition. Pass the result inside the :tools list to Anthropic.Messages.create/2 — Claude performs the search server-side and the result comes back as a %Anthropic.Messages.Content.WebSearchToolResult{} block; there is no client-side execute/1 to implement, unlike Anthropic.Tools-based custom tools.

Examples

Anthropic.Messages.create(client,
  model: "claude-opus-4-8",
  max_tokens: 1024,
  tools: [Anthropic.Tools.WebSearch.new(max_uses: 3)],
  messages: [%{role: "user", content: "What's the latest Elixir release?"}]
)

Summary

Functions

Options

  • :version (String.t/0) - The tool's versioned type string. Override to pin an older API version. The default value is "web_search_20260318".

Functions

@spec new(keyword()) :: map()

Options

  • :version (String.t/0) - The tool's versioned type string. Override to pin an older API version. The default value is "web_search_20260318".

  • :max_uses (pos_integer/0) - Maximum number of searches Claude can perform in this request.

  • :allowed_domains (list of String.t/0) - Only these domains are included in results. Cannot be combined with :blocked_domains.

  • :blocked_domains (list of String.t/0) - These domains are never included in results. Cannot be combined with :allowed_domains.

  • :user_location (map/0) - Location hint (e.g. %{type: "approximate", city: "..."}) for more relevant results.

  • :cache_control (map/0) - An Anthropic.CacheControl map.