HomeAdvanced FeaturesTools & Web Search
intermediate15 min read· Module 6, Lesson 3

🔧Tools & Web Search

Give Claude the ability to search the web, run code, and use custom tools

Tools — Extending Claude's Abilities

Tools let Claude call functions and interact with external systems. Think of tools as "superpowers" you give to Claude.

Types of Tools

TypeWhere It RunsExamples
Server toolsAnthropic's serversWeb search, code execution, web fetch
Client toolsYour applicationCustom functions you define

Web Search — Real-Time Information

JavaScript
const response = await client.messages.create({ model: "claude-sonnet-4-6", max_tokens: 1024, tools: [{ type: "web_search_20250305", name: "web_search", max_uses: 5 // Limit searches per request }], messages: [{ role: "user", content: "What's the current stock price of Apple?" }] });

Claude will:

  1. Decide it needs to search
  2. Execute the search
  3. Read the results
  4. Respond with cited sources

Web Search Options

JavaScript
tools: [{ type: "web_search_20250305", name: "web_search", max_uses: 5, allowed_domains: ["reuters.com", "bbc.com"], // Only these sites blocked_domains: ["spam-site.com"], // Never these sites user_location: { // Localize results type: "approximate", city: "New York", country: "US" } }]

Custom Tools (Client-Side)

Define your own tools that Claude can call:

JavaScript
const response = await client.messages.create({ model: "claude-sonnet-4-6", max_tokens: 1024, tools: [{ name: "get_weather", description: "Get current weather for a location", input_schema: { type: "object", properties: { location: { type: "string", description: "City name, e.g., 'New York'" }, unit: { type: "string", enum: ["celsius", "fahrenheit"], description: "Temperature unit" } }, required: ["location"] } }], messages: [{ role: "user", content: "What's the weather in London?" }] }); // Claude responds with a tool_use block: // { type: "tool_use", name: "get_weather", input: { location: "London" } } // YOU execute the function and send the result back

The Tool Use Loop

  1. You send a message with tool definitions
  2. Claude decides if it needs a tool and returns a tool_use block
  3. You execute the tool and return a tool_result
  4. Claude uses the result to form its final response

Pricing

  • Web search: $10 per 1,000 searches + normal token costs
  • Client tools: Same as normal API pricing

Next up: Structured Outputs — guarantee valid JSON responses.