Search API Practices

Testing a search API on your own tasks: 30 queries, two numbers, one cost figure

Every search API arrives with a benchmark, and every one of those benchmarks measures somebody else's queries: chosen for breadth, usually English, usually the United States, at whatever moment the run happened. Your traffic is narrower and stranger, which is why a vendor's headline accuracy figure says nothing about your 30 hardest tasks.

What you can do in an afternoon is build your own small task set and take two numbers from it: how often the top three results answer the question, and what one answered question costs.

Why borrowed benchmarks do not transfer

Three things differ between a published benchmark and your traffic, and each one moves the score.

A fourth difference matters more: what counts as correct. A benchmark settles that in its own code, and only you can settle it for your questions.

Thirty tasks, taken from your own traffic

Do not write 30 plausible-sounding queries. Pull them from where real ones live: production logs, your support inbox, the tasks in your product spec. If nothing has shipped yet, write the 30 questions the product is supposed to answer, in the words a user would use.

Before running anything, write a pass line for each task - one sentence, decidable, checkable by somebody who is not you.

Then cover the work you actually do, with a few tasks in each bucket: long tail (a precise, low-frequency string), local (the answer depends on place), freshness (only a recent source is correct), and non-English. Thirty is a working size - big enough to show a difference, small enough to re-run after every change.

Number one: useful hits in the top three

Run the set. For each task, read the first three results and apply the pass line you wrote before you saw them. The task is a hit when at least one of those three satisfies it.

Two things decide whether that number means anything.

The judge. Either a second person applies the frozen pass line, or the pass line is written so a script can apply it. "Relevant" cannot be scripted; "carries a date inside the last 30 days" can.

The drift. When one person writes the pass lines, judges the runs and fixes the retriever, the number climbs for reasons unrelated to retrieval: a borderline result reads as a near miss one week and a hit the next. Freeze the pass lines and edit them only between runs, in a commit you can point at.

The control run: do it with the book closed

Now answer the same 30 tasks with retrieval switched off - same model, same prompt, no search results in the context - and count how many the model gets right from what it already knows.

This step is always skipped and always worth the hour: it splits your headline number into what the model knew and what the search added. Suppose the closed-book arm answers 14 of 30 and the retrieved run answers 18: search contributed four tasks, and a two-point move is noise. It also identifies weak items, because a task the model answers from memory is not testing your retriever.

Number two: cost per answered task

Cost per thousand calls is a vendor metric; cost per answered task is yours, and it is the one a budget conversation needs. Build it from the calls themselves, because a task is not a call.

The denominator is therefore charged credits rather than attempts, and the cleanest gate is a field the response already carries: credits_charged. A number means charged, 0 means not charged, and null means the charge has not settled yet. Keep those rows out of the total, because reading them as zero understates cost (checked 2026-11-26, /docs/billing-and-credits).

Capacity belongs in the same model, and it is per account, not per key: every key, product and gateway under one account draws on the same QPS limit, and adding keys does not raise it. A refusal over the limit comes back as 1029 with a Retry-After and is not charged (checked 2026-11-26, /docs/api-keys).

Divide total charged credits by the number of tasks that met their pass line. That is cost per answered task. Call whichever endpoint your product would call: the catalog showed 39 callable and 10 paused on the day of writing, and price is set per endpoint (checked 2026-11-26, /products).

Empty results are a first-class outcome

An agent can receive an empty list, a list of near misses, or an error, and the three drive different behaviour.

Reserve slots for tasks whose correct answer is "nothing exists", and score them separately: a pass line like "must find X" applied to something that does not exist measures your retriever's ability to fail.

Two documented details help you tell the shapes apart. A successful response is status 0, and no_results by itself is not proof of a 404, so "found nothing" and "the resource is missing" are separate states. And only some non-zero codes are worth resending: the rate-limit and service-side ones, while an invalid request or a missing key must be fixed first (checked 2026-11-26, /docs/responses-and-errors).

What to log for reproducibility

Per call, record the query as sent, the endpoint, credits_charged, latency, the number of results, and the top three domains. Domains are the part people leave out and the part that explains a quiet decline: if the score drops while result counts hold steady, the sources that answer have changed.

Then version the eval set. An edited pass line, or a field whose meaning changed, makes this month's score a different measurement from last month's even when both carry the same label, so put the version in every row.

Three ways this goes wrong

A 30-line harness

The skeleton below records the fields the previous sections asked for and returns both numbers.

import json, os, time, urllib.request

URL = "https://api.serpbase.dev/google/search"
KEY = os.environ["SERPBASE_API_KEY"]
EVAL_SET_VERSION = "2026-11-26.1"

def search(task):                      # one credited call, fully recorded
    body = json.dumps({"q": task["q"], "gl": task["gl"], "hl": task["hl"]}).encode()
    req = urllib.request.Request(URL, data=body, headers={
        "X-API-Key": KEY, "Content-Type": "application/json"})
    t0 = time.monotonic()
    with urllib.request.urlopen(req, timeout=60) as resp:
        env = json.loads(resp.read())
    organic = env.get("organic") or []
    return {"id": task["id"], "query": task["q"], "endpoint": "google/search",
            "status": env["status"], "charged": env["credits_charged"],
            "ms": int((time.monotonic() - t0) * 1000), "n": len(organic),
            "top3": [x.get("display_url") for x in organic[:3]]}

def evaluate(tasks, retrieve=True):
    rows = [search(t) if retrieve else
            {"id": t["id"], "charged": 0, "n": 0, "top3": []} for t in tasks]
    charged = [r["charged"] for r in rows if isinstance(r["charged"], int)]
    by_id = {t["id"]: t for t in tasks}
    hits = [r["id"] for r in rows if by_id[r["id"]]["pass"](r)]
    return {"version": EVAL_SET_VERSION, "rows": rows,
            "hit_rate": len(hits) / len(tasks),
            "credits_per_task": sum(charged) / len(tasks),
            "credits_per_hit": sum(charged) / max(len(hits), 1)}

pass is the frozen pass line as a function, which is why the judging rule has to be written down before the first run. Bump EVAL_SET_VERSION whenever a pass line or a field's meaning changes. The closed-book arm is evaluate(tasks, retrieve=False), and the gap between the two calls is what retrieval is actually paying for.

The billing rules, the rate-limit behaviour and the response codes quoted above are documented at https://serpbase.dev/?utm_campaign=ops-222e35a2a81a&utm_medium=outreach&utm_source=opsbot