Claude‘s official format for the web search API.
| Parameter | Type | Required | Default | Range | Description |
|---|---|---|---|---|---|
model | string | ✅ Yes | claude-sonnet-4-5-20250929 | - | The model to use for the request |
messages | array | ✅ Yes | [{'role': 'user', 'content': "What's the weather in NYC?"}] | - | Array of message objects for the conversation. Each message must have a role (user/assistant) and content. See Messages Structure below for details |
max_tokens | integer | ✅ Yes | 1024 | 1-64000 | The maximum number of tokens to generate before stopping |
tools | array | ✅ Yes | - | - | Array of tool objects. For web search, must include the web_search tool configuration. |
temperature | number | ❌ No | 1.0 | 0.0-1.0 | Controls randomness in output. Use lower values (closer to 0.0) for analytical tasks, higher values (closer to 1.0) for creative tasks. Note: Even at 0.0, results are not fully deterministic |
top_p | number | ❌ No | 1.0 | 0.0-1.0 | Nucleus sampling threshold. Controls diversity by considering only tokens with cumulative probability up to top_p. Recommended for advanced use only. Do not use with temperature |
top_k | integer | ❌ No | null | >0 | Only sample from the top K options for each token. Removes low probability responses. Recommended for advanced use only |
stream | boolean | ❌ No | false | - | Whether to incrementally stream the response using server-sent events |
stop_sequences | array | ❌ No | - | Max 8191 sequences | Custom text sequences that will cause the model to stop generating. Each sequence must contain non-whitespace characters |
messages array should have the following structure:
| Field | Type | Required | Range | Description |
|---|---|---|---|---|
role | string | ✅ Yes | - | The role of the message. Can be: user or assistant |
content | array/string | ✅ Yes | - | The content of the message |
| Field | Type | Required | Range | Description |
|---|---|---|---|---|
type | string | ✅ Yes | - | The type of content |
text | string | ✅ Yes | - | The text content when type is text |
tools array should contain a web search tool object:
| Field | Type | Required | Range | Description |
|---|---|---|---|---|
type | string | ✅ Yes | - | The type of tool. Must be web_search_20250305 for web search |
name | string | ✅ Yes | - | The name of the tool |
max_uses | integer | ❌ No | 1-10 | Maximum number of times the web search tool can be used in a single request |
allowed_domains | array | ❌ No | - | Only include search results from these domains |
blocked_domains | array | ❌ No | - | Never include search results from these domains |
user_location | object | ❌ No | - | Localize search results based on user’s location |
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.
example.com instead of https://example.com)example.com covers docs.example.com)docs.example.com returns only results from that subdomain, not from example.com or api.example.com)example.com/blog)allowed_domains or blocked_domains, but not both in the same requestuser_location object allows you to localize search results based on a user’s location:
| Field | Type | Required | Range | Description |
|---|---|---|---|---|
type | string | ✅ Yes | - | The type of location (must be approximate) |
city | string | ✅ Yes | - | The city name |
region | string | ✅ Yes | - | The region or state |
country | string | ✅ Yes | - | The country code |
timezone | string | ✅ Yes | - | The IANA timezone ID |