How to Use Anthropic’s New Web Search Tool

This past weekend I tried building my first ai project using ChatGPT’s API. I want to build an app that tells me what bands are playing on any given night in Austin, TX and includes Spotify embeds so I can listen to the bands music so I can decide if I want to go see them or not. This is something I can sort-of do on chatgpt.com, but when trying to do the same thing via OpenAI’s API, I wasn’t actually able to get it to work.

While I was a little deflated that my weekend project was a failure, fast forward a few days and Anthropic launched their new web search tool today! And sure enough, I tried giving Claude via the Anthropic API the same prompt I had given ChatGPT and Claude is able to tell me what bands are playing tonight in Austin, TX at Hotel Vegas, a cool venue by my apartment that has shows 7 days a week 365 days a year.

If you’re interested in using the new web search tool via the Anthropic API, make sure you set the model you’re using to claude-3-7-sonnet-20250219, and add “tools” block when you instantiate your Claude client:

import Anthropic from '@anthropic-ai/sdk';
const client = new Anthropic({
apiKey: 'YoUR-APi-KeY-GOEs-HeRE', // This is the default and can be omitted
});
async function main() {
const message = await client.messages.create({
max_tokens: 1024,
messages: [{ role: 'user', content: 'What bands are playing tonight at Hotel Vegas in Austin, TX?' }],
model: 'claude-3-7-sonnet-20250219',
// Enable Claude Web Search
tools: [{
type: "web_search_20250305",
name: "web_search",
max_uses: 5
}],
});
console.log(message.content);
}
main();
view raw websearch.js hosted with ❤ by GitHub
 

topherPedersen