← Blog

Claude API Search Engine Integration Guide

2026-11-13 · 5 min read · SubToAPI Team

Claude's API does not browse the web on its own. If you ask it about something that happened after its training cutoff, or anything requiring fresh data, it will either say it doesn't know or guess. Search engine integration solves this: you give Claude a "search" tool, let it decide when to call it, run the actual query against a real search provider, and feed the results back so Claude can write a grounded answer.

This guide walks through the full pattern — tool definition, the request/response loop, which search providers to use, and how to keep the integration fast and cheap. It applies whether you're calling Claude directly or through a proxy like SubToAPI.

Why you need a search tool at all

Claude's tool use (function calling) feature lets the model request external data mid-conversation instead of hallucinating it. For search, the flow looks like this:

  1. You send a user message plus a tool definition describing a web_search function.
  2. Claude decides the question needs fresh information and returns a tool_use block with a query string instead of a final answer.
  3. Your backend takes that query, calls a real search API (Google, Bing, Brave, Serper, Tavily, etc.), and collects the top results.
  4. You send those results back to Claude as a tool_result.
  5. Claude writes the final answer, citing or summarizing the retrieved pages.

This is the same architecture used for any tool integration — database lookups, calculators, internal APIs — search is just a specific case where the "tool" is an HTTP call to a search provider.

Defining the search tool

Here's a minimal tool schema you'd pass alongside your messages request:

{
  "name": "web_search",
  "description": "Search the web for current information. Use this when the user asks about recent events, prices, or facts that may have changed after your training cutoff.",
  "input_schema": {
    "type": "object",
    "properties": {
      "query": {
        "type": "string",
        "description": "The search query to run"
      }
    },
    "required": ["query"]
  }
}

The description matters more than people expect. Claude decides whether to call the tool based on it, so be explicit about when search should and shouldn't be used — otherwise you'll either get searches for trivial questions or missed searches for genuinely time-sensitive ones.

The request/response loop

async function askWithSearch(userMessage) {
  const tools = [{
    name: "web_search",
    description: "Search the web for current information.",
    input_schema: {
      type: "object",
      properties: { query: { type: "string" } },
      required: ["query"]
    }
  }];

  let messages = [{ role: "user", content: userMessage }];

  let response = await callClaude(messages, tools);

  while (response.stop_reason === "tool_use") {
    const toolCall = response.content.find(c => c.type === "tool_use");
    const results = await runWebSearch(toolCall.input.query);

    messages.push({ role: "assistant", content: response.content });
    messages.push({
      role: "user",
      content: [{
        type: "tool_result",
        tool_use_id: toolCall.id,
        content: JSON.stringify(results)
      }]
    });

    response = await callClaude(messages, tools);
  }

  return response.content;
}

runWebSearch is where you call an actual search provider. A common lightweight choice is Serper or Tavily (both return clean JSON), or Brave's Search API if you want results without going through Google's quota limits. Keep the payload you send back small — 5 to 8 results with title, URL, and a short snippet each is usually plenty. Dumping full page HTML back into the context wastes tokens and slows down the final response.

Calling Claude through SubToAPI

If you're routing requests through SubToAPI instead of hitting Claude directly, the tool-use loop is identical — you just swap the endpoint and auth header:

curl https://api.subtoapi.app/v1/messages \
  -H "Authorization: Bearer $SUBTOAPI_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "claude-3-7-sonnet-20250219",
    "max_tokens": 1024,
    "tools": [{"name": "web_search", "description": "...", "input_schema": {...}}],
    "messages": [{"role": "user", "content": "What is the current price of Bitcoin?"}]
  }'

SubToAPI issues sub_live_... application keys, handles streaming and usage metadata, and lets a team share one plan without juggling individual Claude accounts. The tool_use/tool_result mechanics stay exactly the same as calling Claude's API directly — see /docs/tools for the full reference and /docs/messages for the base request format.

Reducing latency and cost

Search integration adds a network round trip to the search provider plus a second model call, so it's naturally slower than a single-pass request. A few practical fixes:

Choosing a search provider

| Provider | Good for | Notes | |---|---|---| | Serper | Fast Google-quality results | Simple JSON API, per-query pricing | | Tavily | AI-agent-optimized search | Built specifically for LLM tool use | | Brave Search API | Independent index, no Google dependency | Generous free tier | | Bing Search API | Enterprise contracts | Being phased toward Azure AI integration |

Any of these work with the loop above — the integration code doesn't change, only the runWebSearch implementation and how you parse its response shape.

Getting started

  1. Pick a search provider and get an API key.
  2. Define the web_search tool schema and wire up the tool_use loop.
  3. Test with a handful of time-sensitive queries to confirm Claude triggers search when it should (and skips it for stable facts).
  4. Add caching and a query budget before shipping to production.

If you want the Claude side handled without managing provider auth and rate limits yourself, start a free trial at /signup and check /docs/quickstart — plans start at Solo for €9/month, with Team and Scale tiers for shared seats (see /pricing).

questions

Does Claude have built-in web search? No. The base API has no network access. Search is implemented entirely through tool use — you supply the search provider and the retrieval logic.

Which search API should I pair with Claude? Tavily and Serper are purpose-built for LLM pipelines and return clean JSON with minimal parsing. Brave Search API is a solid free-tier alternative if you want an independent index.

Can I limit how often Claude searches? Yes — control it through your tool description (tell it when search is appropriate) and by capping the number of tool_use iterations per turn in your application loop, typically 1–2 calls.

Turn your Claude access into an HTTPS API

SubToAPI gives you application API keys, streaming, tool use and usage insights on top of your existing Claude access — set up in minutes.

Start free  Read the quickstart →