OpenAI format for the web search API.
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
model | string | ✅ Yes | claude-3-5-haiku-20241022 | 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 or assistant) and content. |
tools | array | ✅ Yes | - | Array of tool objects. For web search, must include the web_search tool configuration. |
stream | boolean | ❌ No | false | Whether to stream the response |
temperature | number | ❌ No | 1.0 | Amount of randomness injected into the response. Ranges from 0.0 to 1.0 |
top_p | number | ❌ No | 1.0 | Use nucleus sampling. Ranges from 0.0 to 1.0 |
max_tokens | integer | ❌ No | - | The maximum number of tokens to generate before stopping |
stop | array | ❌ No | - | Custom text sequences that will cause the model to stop generating |
messages array should have the following structure:
| Field | Type | Required | Description |
|---|---|---|---|
role | string | ✅ Yes | The role of the message. Can be: user, assistant, or system |
content | array/string | ✅ Yes | The content of the message |
| Field | Type | Required | Example | Description |
|---|---|---|---|---|
type | string | ✅ Yes | text | The type of content |
text | string | ✅ Yes | "What's the weather in NYC?" | The text content when type is text |
tools array should contain a web search tool object:
| Field | Type | Required | Example | Description |
|---|---|---|---|---|
type | string | ✅ Yes | web_search | The type of tool. Must be web_search for web search |
max_uses | integer | ❌ No | 5 | Maximum number of times the web search tool can be used in a single request |
allowed_domains | array | ❌ No | ["example.com", "trusteddomain.org"] | Only include search results from these domains |
blocked_domains | array | ❌ No | ["untrustedsource.com"] | Never include search results from these domains |
max_uses parameter limits the number of searches performed. If Claude attempts more searches than allowed, the web search 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 request