PatternsTools & Utilities

Claude Web Search Tool

Loading pattern preview

Loading preview…

Problems solved

Technical challenges this implementation handles out of the box.
  • Search the web with Claude's built-in webSearch tool
  • Stream citation-backed answers with sendSources
  • Use Anthropic provider-native tools inside streamText

Use cases

Products and workflows this pattern is designed to support.
  • Research assistants on Claude
  • Fact-checking chats with source links
  • News monitoring agents
  • Competitive intelligence lookups

Setup

Requirements, wiring steps, and what this pattern adds to your project.

Getting started

Pick how you want to pull this pattern in — then wire env vars and routes the same way.

  1. 1

    Install from the preview toolbar

    Shadcn Icon

    Copy the install command above and run it in your project — Pro patterns include a short-lived token.

  2. 2

    Add environment variables to .env.local

    CLAUDE_API_KEY

  3. 3

    Point client fetches at your API routes

    Replace preview `/view/.../api/...` paths with `/api/...` in the installed files.

  4. 4

    Customize the agent and tool files

    Adapt prompts, tools, and stop conditions for your product — Copy for AI in the toolbar helps seed that work.

  5. 5

    Run your dev server and open the pattern route

    Install dependencies if needed, then start the app and verify responses.

Environment variables

Capabilities

AI SDK APIs

streamTexttoolconvertToModelMessagesgenerateText

Providers

anthropic

Files added

6 files
  • app/page.tsx
  • app/layout.tsx
  • app/api/websearch-claude/route.ts
  • components/websearch-demo.tsx
  • lib/request-utils.ts
  • README.md

Dependencies

7 total

npm packages

6
AISDKlucide-reactNext.jsReactsonnerZod

Shadcn IconRegistry components

1
empty

Critical files

  • websearch-claude/route.ts

    API route demonstrating Claude's built-in web search tool via anthropic.tools.webSearch. Shows the provider-native tool integration pattern with streamText and sendSources.

Requirements

Complexity
Beginner
Setup time
~10 minutes
Node
24+
Memory
512MB
Upstash Redis for rate limiting