Web Search API for AI Agents: Four Engines Compared
A web search API for an AI agent takes a query and returns ranked results as JSON: a title, a URL and a snippet per result. Perceptlayer has four engines behind one key (Google, Brave, Bing and DuckDuckGo), each at 1 credit per successful search. Their responses use different field names, so this post compares what each recorded response contains, then shows a short Python function that turns all four into one result shape an agent can read.
What does an agent need from a search result?
An agent needs three things from each result: a title to judge relevance, a URL to cite or fetch, and a snippet to answer from without another call. Position helps it weigh results, and the engine name helps when you merge engines. Everything else in a search response is optional context that costs tokens every time the model reads it.
That's the case for normalising. If your tool hands the model the raw response, the model sees link from one engine and url from another, and nested local_results it may not need. A fixed, small shape keeps the tool description short and the context window clear. Trim API Responses for LLM Context covers trimming in general; here the job is narrower: four engines, one shape.
If you want a primer on what a results page contains before comparing engines, SERP API: What It Returns and What a Query Costs covers it. This post assumes you know the idea and need to pick and wire an engine.
How do the four search endpoints compare?
The four endpoints share a price and a purpose but differ in parameter names, response nesting and the extras they return. The table below comes from the catalogue and the recorded responses: field names are the ones that appeared in each recording, not a full schema.
| Brave | Bing | DuckDuckGo | ||
|---|---|---|---|---|
| Endpoint | GET /v1/google-search/search |
GET /v1/brave/search |
GET /v1/bing/search |
GET /v1/duckduckgo/search |
| Query parameter | query |
query |
query |
q |
| Results array | organic_results |
organic_results |
data |
data.organic_results |
| URL field | link |
link |
url |
link |
| Snippet field | snippet |
snippet |
description |
snippet |
| Paging parameters | start, page |
page |
page, num |
start |
| Paging info in recording | pagination[] with start values |
results_count |
results_on_page |
pagination.has_more, next_start |
| Extras in recording | related_questions, related_searches, local_results, filters |
related_questions with answer and link, related_searches |
domain per result |
knowledge_graph.ai_answer |
| Other parameters | gl, hl, location, safe, tbs, tbm, device and more |
language, include_html |
site, filetype, safe, hl, include_html |
kl, df, safe |
| Credits per call | 1 | 1 | 1 | 1 |
Google's search endpoint takes the longest parameter list by far, and the Google Search API has six more endpoints, including AI Overview and AI Mode. The other three engines have one endpoint each.
What do the recorded responses look like?
Each engine returns JSON with a results array, but the arrays sit at different paths and the fields have different names. These are trimmed excerpts of the recorded responses, with … where we cut. Where a recorded result named a person or a competing product, its title and snippet are cut too.
curl "https://api.perceptlayer.com/v1/google-search/search?query=best+restaurants+in+Berlin&hl=en&safe=off" \
-H "X-API-Key: $API_KEY"
{
"search_information": {
"query_displayed": "best restaurants in Berlin",
"organic_results_count": 6
},
"organic_results": [
{
"position": 1,
"title": "The Best Restaurants in Berlin - Food Guide & Map",
"link": "https://andershusa.com/best-restaurants-berlin-germany-guide/",
"displayed_link": "https://andershusa.com › best-restaurants-berlin-german...",
"snippet": "Dec 3, 2025 — …",
…
},
…
],
"related_questions": [
{
"question": "What is the coolest restaurant in Berlin?",
…
},
…
],
"local_results": {
"places": [
{
"position": 1,
"title": "BLESS Restaurant",
"rating": 4.8,
"reviews": 2400,
"price": "€20–70",
"address": "Hausvogteipl. 10, 10117 Berlin, Germany",
…
},
…
],
…
},
…
}
The local_results.places block matters for agents: a question like "where should I eat in Berlin" gets ratings, review counts and addresses without a second call.
Brave
{
"search_information": {
"query_displayed": "best web scraping api"
},
"organic_results": [
{
"position": 1,
"title": "…",
"link": "…",
"displayed_link": "…",
"snippet": "…",
"source": "…"
},
…
],
"related_questions": [
{
"question": "…",
"answer": "…",
"link": "…",
"title": "…"
},
…
],
"results_count": 20,
"engine_used": "brave",
…
}
Brave's result fields line up with Google's: position, title, link, snippet. Its related_questions entries carry an answer and the link it came from, which an agent can quote with a citation.
Bing
{
"data": [
{
"position": 2,
"title": "BEST | English meaning - Cambridge Dictionary",
"description": "BEST definition: 1. of the highest quality, or being the most suitable, pleasing, or effective type of thing or…. Learn more.",
"url": "https://dictionary.cambridge.org/dictionary/english/best",
"domain": "dictionary.cambridge.org"
},
…
],
"results_on_page": 10,
"source": "bing"
}
The recorded Bing request was the same query as Brave's, "best web scraping api", and the two results in the recording are about the word "best", not about scraping APIs. That's what came back at the time of the call. It's a reason to have the agent check relevance from the title and snippet before it answers, whichever engine you use.
DuckDuckGo
{
"success": true,
"data": {
"search_parameters": {
"q": "…",
"kl": "us-en",
"safe": true,
"start": 0
},
"organic_results": [
{
"position": 1,
"title": "…",
"link": "…",
"snippet": "…",
"display_url": "…",
"favicon": "…"
},
…
],
"pagination": {
"current": 1,
"has_more": true,
"next_start": 10,
"next": 2
},
…
},
"meta": {
"duration_ms": 2169,
"endpoint_family": "web_search"
}
}
DuckDuckGo nests results one level down, under data. Its pagination block gives has_more and next_start, so a paging loop can pass next_start back as start. One recorded snippet contained & rather than &, so unescape HTML entities before the model reads it.
How do you normalise four engines into one result shape?
Write one function per engine that reads only the fields seen in the recordings, then return a list of dicts with the same five keys. The agent's tool calls a single web_search(query, engine) function and never sees engine-specific names. Any field the recordings didn't show is treated as unknown and read with .get().
import html
import os
import requests
BASE = "https://api.perceptlayer.com"
HEADERS = {"X-API-Key": os.environ["API_KEY"]}
ENGINES = {
"google": ("/v1/google-search/search", "query"),
"brave": ("/v1/brave/search", "query"),
"bing": ("/v1/bing/search", "query"),
"duckduckgo": ("/v1/duckduckgo/search", "q"),
}
def _rows(engine, body):
if engine in ("google", "brave"):
return body.get("organic_results", []), "link", "snippet"
if engine == "bing":
return body.get("data", []), "url", "description"
return body.get("data", {}).get("organic_results", []), "link", "snippet"
def web_search(query, engine="google", limit=5):
path, param = ENGINES[engine]
resp = requests.get(BASE + path, params={param: query}, headers=HEADERS, timeout=60)
if resp.status_code != 200:
err = resp.json().get("error", {})
return {"error": err.get("code"), "engine": engine}
rows, url_key, snippet_key = _rows(engine, resp.json())
results = []
for row in rows[:limit]:
results.append({
"engine": engine,
"position": row.get("position"),
"title": html.unescape(row.get("title") or ""),
"url": row.get(url_key),
"snippet": html.unescape(row.get(snippet_key) or ""),
})
return {"results": results, "credits_used": resp.headers.get("X-Credits-Used")}
if __name__ == "__main__":
for r in web_search("best restaurants in Berlin")["results"]:
print(r["position"], r["title"], r["url"])
Errors come back as an HTTP status and a JSON body with error.code, so the function returns the code instead of raising. The model can then read rate_limited or source_error and decide whether to try another engine. The errors docs list every code, and Handle Web Data API Errors in Python covers retries and timeouts.
Should the agent fall back to another engine?
A fallback chain is cheap because failed calls are free. If Google returns a source_error, calling Brave next costs 1 credit for the successful call and nothing for the failed one. Keep the chain short (two engines is enough) and cap it in code, not in the prompt. For 429 responses, wait for the seconds in Retry-After instead of switching engines, because the rate limit is per account and applies to all four.
Should the agent merge results from two engines?
Merging two engines gives the agent a second set of sources for 2 credits per question. Deduplicate on url after normalising, keep the better position, and pass the engine name through so the model can see where each result came from. It's worth it for research questions where one engine's top results may be thin; for a quick factual lookup, one engine is enough.
What does a search cost an agent?
Every search costs 1 credit on success and 0 on failure, so an agent's search bill is its number of successful searches. The free tier gives 100 credits after you verify your email, and paid credits come in prepaid packs from 10,000 credits upward. X-Credits-Used and X-Credits-Remaining come back on every successful response, so the tool can report spend as it goes.
Worked examples:
- An agent that answers 300 questions a day with one search each: 300 × 30 days × 1 credit = 9,000 credits a month, inside the Starter pack's 10,000.
- The same agent merging two engines per question: 300 × 2 × 30 × 1 credit = 18,000 credits a month, inside the Build pack's 50,000.
- A fallback that fires on 5% of questions adds about 450 credits a month at 300 questions a day, and only for the fallback calls that succeed.
Free accounts get 1 request a second and paid accounts at least 5, shared by every key on the account. See pricing for what credits cost and the rate limits docs for the headers.
Which search engine should your agent use?
Pick by the question your agent answers most, because the four differ in extras and parameters more than in the basic result. Every verdict below costs the same, 1 credit per successful search.
- General question answering and citations: Google. The recorded response carries organic results plus
related_questionsandrelated_searches, and the endpoint takesgl,hlandlocationfor country and language. - Local questions (restaurants, shops, services near a place): Google.
local_results.placesreturnsrating,reviews,price,phoneandaddressin the same call. - Answers with a cited source: Brave's
related_questionspair ananswerwith thelinkit came from. - Queries that need the
siteorfiletypeparameter: Bing is the only one of the four with those parameters. - Paging until results run out: DuckDuckGo's
pagination.has_moreandnext_startmake the loop condition explicit. - A second opinion: run Google plus one other engine, normalise, and deduplicate on
url, for 2 credits per question.
Through MCP, the agent doesn't need your wrapper at all: search_endpoints and get_endpoint find and describe these endpoints for free, and call_endpoint runs them. The AI agents docs cover setup. To compare the engines on your own queries first, run each one in the playground on the Google Search API, Brave Search API, Bing API and DuckDuckGo API pages, then get a free API key.
APIs in this post
Frequently asked questions
How much does a web search API call cost?
Each of the four search endpoints costs 1 credit per successful call. A failed call costs nothing and returns X-Credits-Used: 0. Every account gets 100 free credits after verifying an email address, which is 100 searches. Credits beyond that come in prepaid packs; the pricing page has what they cost.
Do the four engines return the same results?
No. The recorded responses differ in fields as well as in which pages come back. Google, Brave and DuckDuckGo use link and snippet, Bing uses url and description. Results are returned as found at the time of the call, so test your agent's typical queries on each engine before you pick one.
Which parameter holds the search query?
Google, Brave and Bing take query as a required parameter. DuckDuckGo takes q instead, also required. A request that fails for any reason costs nothing. If you wrap the engines in one function, map the parameter name per engine, as the ENGINES table in the normaliser above does, so the agent only ever passes a query string.
Can an AI agent call these search endpoints over MCP?
Yes. The MCP server at https://perceptlayer.com/mcp exposes search_endpoints and get_endpoint, which look up the catalogue for free, and call_endpoint, which runs an endpoint and spends credits only on success. The agent can find all four search endpoints that way. How to Add an MCP Server to Claude Desktop and Cursor covers client setup.
What happens when a search is rate limited?
The call returns 429 with a rate_limited error code, a Retry-After header giving the seconds to wait, and no charge. Limits are per account, shared by every key, so switching to another engine doesn't help. Wait the given seconds and retry. HTTP 429 Too Many Requests covers backoff patterns.