Google SERP API Integration With SerpBase: JSON to Drop-In
One HTTP endpoint, three output formats (json, markdown, raw), and a drop-in route if you already have SerpApi code in production. Most developers integrating a SERP API today fall into one of two camps: either you are
One HTTP endpoint, three output formats (json, markdown, raw), and a drop-in route if you already have SerpApi code in production.
Most developers integrating a SERP API today fall into one of two camps: either you are wiring live Google Search into an AI Agent / RAG pipeline, or you are trying to lower the monthly invoice on an existing SEO/e-commerce scraper without rewriting 40 parsers. Below is a practical integration walkthrough using SerpBase (49 catalog endpoints, 39 currently available, 500 free no-card credits on signup).
1. Native POST /google/search (Structured JSON, 1 Credit)
For rank tracking, SEO dashboards, or structured extraction, hit POST https://api.serpbase.dev/google/search with your API key in the X-API-Key header (never embed keys in query strings or client bundles):
const res = await fetch("https://api.serpbase.dev/google/search", {
method: "POST",
headers: {
"X-API-Key": process.env.SERPBASE_API_KEY!,
"Content-Type": "application/json",
},
body: JSON.stringify({
q: "typescript orm benchmark 2026",
gl: "us",
hl: "en",
device: "desktop",
}),
signal: AbortSignal.timeout(60_000), // Docs recommend 60s timeout
});
const data = await res.json();
if (data.status !== 0) {
throw new Error(`SERP error status=${data.status}, retryable=${res.headers.get("X-SerpBase-Retryable")}`);
}
console.log("Organic results:", data.organic?.length ?? 0);
console.log("People Also Ask:", data.people_also_ask?.length ?? 0);
Notice two SerpBase specifics that trip people up on day one:
-
HTTP 200 does not guarantee success: always check the JSON envelope's
status === 0, and inspectX-SerpBase-Retryable(true/false) before retrying1502/1504upstream errors. Failed calls are automatically refunded. -
Field names: the People Also Ask array is
people_also_ask(notrelated_questions), and organic results live underorganic.
2. Switching to format: "markdown" for LLM & RAG Pipelines
If the consumer of your SERP API is an LLM rather than a SQL table, parsing nested JSON and stripping snippets wastes both code and context tokens. Passing "format": "markdown" on /google/search costs the exact same 1 credit as JSON, but returns clean text/markdown directlyβwithout a JSON envelope:
import os
import requests
resp = requests.post(
"https://api.serpbase.dev/google/search",
headers={"X-API-Key": os.environ["SERPBASE_API_KEY"]},
json={"q": "postgres partial index best practices", "format": "markdown"},
timeout=60,
)
# Important: format=markdown returns text/markdown directly (no JSON wrapper)
if resp.status_code == 200 and "markdown" in resp.headers.get("Content-Type", ""):
markdown_context = resp.text
print(markdown_context[:400])
I actually broke our own TypeScript wrapper the first time I tested format: "markdown" because the shared helper blindly called await res.json() on every 200 response. Checking Content-Type before parsing fixes it cleanly.
3. Unwrapping Redirects & Checking Balance for 0 Credits
Two utility endpoints cost 0 credits and save real engineering time:
-
POST /google/resolve(0 credits,30 req/min, up to50links per call): unwraps Google'sgoogle.com/gotoand/urlredirect wrappers back into clean destination URLs. -
GET /account/credits(0 credits,60 req/min): returnscredits,permanent_credits,expiring_credits, andexpiring_expires_atfor automated low-balance alerts.
4. Already on SerpApi? The One-Line Drop-In Route
If you already maintain production code calling https://serpapi.com/search.json, you don't need to rewrite your parser to test SerpBase's pricing ($0.50/1k on the $10/20k never-expire Starter pack, $0.40/1k on $50/125k Growth, down to $0.25/1k on the $100/mo Pro Monthly plan).
Swap the base URL to https://api.serpbase.dev/google/serpapi/search.jsonβit supports 25 engines (google, google_images, google_news, google_shopping, google_maps, google_ai_mode [3 credits], amazon, walmart, youtube_video_transcript, etc.) with SerpApi's GET parameters and response schema:
import os, requests
# Before: "https://serpapi.com/search.json"
url = "https://api.serpbase.dev/google/serpapi/search.json"
params = {"engine": "google", "q": "rust async runtime", "gl": "us", "hl": "en"}
r = requests.get(url, params=params, headers={"X-API-Key": os.environ["SERPBASE_API_KEY"]}, timeout=60)
print(len(r.json().get("organic_results", [])))
Do verify the compatibility edge cases before cutting over: output=html is only supported on engine=google, Google Maps place details should use native POST /google/maps/detail (3 credits, feature_id), and SerpApi's async/archive endpoints aren't mirrored.
5. Production Guardrails Before You Ship
Before pointing a cron job or multi-agent worker at any SERP API, lock down three defaults:
- Keep HTTP client timeouts at
60s(server max is30s; you can also pass a per-requesttimeoutof1β30son Google search endpoints if you want an uncharged1504fast-fail for interactive UX). - Throttle concurrency to your account's shared QPS tier (
2 QPSon$10Starter,5 QPSon$50Growth,10 QPSon$100Pro Monthly, up to50/500 QPSvia cumulative prepaid spend) and honorRetry-Afteronstatus: 1029. - Store
credits_chargedas a nullable integer (nullorcharge_status: "UNKNOWN"means an interrupted/timed-out request is still settling asynchronously).
All 39 active endpoints, OpenAPI specs (/openapi.json), /llms.txt, and the official MCP server (serpbase-mcp) are documented in the SerpBase Docs.
Originally published by Dev.to AI. Aggregated on AIWithGhost for educational purposes β full credit and traffic to the original publisher.