Launch pricing: 78% of pool capacity allocated. Rates rise as it fills. Lock in today's rate →
Skip to content

Web search API for AI agents: give your agent live Google results

By SerpWiz · · 3 min read

Language models don't know what happened after their training cut-off, and they can't check a price, a ranking or an opening time. Give your agent a search tool and it can. Here are the two ways to do it, and what it costs.

What an agent needs from a search API

  • Live results, not a cached index, so answers about prices, news and rankings are current.
  • Structured JSON, so the agent reads titles, URLs and snippets instead of HTML.
  • Low cost per call. Agents search a lot, often 3 to 10 times for one answer, so the price per search matters more than for a person.
  • No failure charges. Agents retry. You shouldn't pay for the failed attempts.

The SerpWiz Google Search API returns the live Google results page as JSON for $0.15 per 1,000 searches ($0.1125 with a year prepaid), and failed requests are free. The Google Maps API does the same for places.

Option 1: MCP (no code)

The Model Context Protocol lets an assistant use tools from a server. SerpWiz runs a hosted MCP server with two tools, google_search and google_maps. Add it to Claude, ChatGPT, Cursor or VS Code, sign in, and your assistant can search Google.

In Claude Code, for example:

claude mcp add --transport http serpwiz https://api.serpwiz.com/mcp

Setup for every client is in the MCP docs.

Option 2: tool calling in your own agent

If you're building an agent, describe the search as a tool and run the call yourself. The schema is the same idea in every framework:

{
  "name": "google_search",
  "description": "Search Google and return live results as JSON. Use for anything recent or factual.",
  "input_schema": {
    "type": "object",
    "properties": {
      "q": {"type": "string", "description": "Search terms, as typed into Google"},
      "gl": {"type": "string", "description": "Two-letter country code, e.g. us"}
    },
    "required": ["q"]
  }
}

When the model calls the tool, run the search and return a compact version of the results:

import os, requests

def google_search(q, gl="us"):
    r = requests.get(
        "https://api.serpwiz.com/v1/google/search",
        params={"q": q, "gl": gl},
        headers={"X-API-Key": os.environ["SERPWIZ_API_KEY"]},
        timeout=60,
    )
    data = r.json()
    if "error" in data:
        return {"error": data["error"]["message"]}   # the model can retry or rephrase
    return [{"title": x["title"], "url": x["url"], "snippet": x.get("description", "")}
            for x in data["results"][:8]]

A ready-made schema for each endpoint is in the AI agents docs, along with the OpenAPI spec.

Keep the context small

A full results page is a few thousand tokens. Most agents only need the title, URL and snippet of the top results, as above. That keeps each search cheap in tokens as well as in API cost, and leaves room for the agent to fetch the one page it actually needs.

What it costs per answer

If your agent averages 5 searches per answer, 10,000 answers a month is 50,000 searches: $10 a month on a monthly plan, or $7.50 a month annual. At the $5 per 1,000 that Google charged for its Custom Search JSON API, the same volume would cost $250.

Plans also set your throughput, from 1 request per second on the $10 plan, so pick one that covers your agent's peak rate.

Try it

You get 1,000 free queries a month, no card required. Connect over MCP, or create an API key and add the tool above.

More from the blog

This post as Markdown: /blog/web-search-api-for-ai-agents.md