Skip to content

Latest commit

 

History

3 Commits

Folders and files

Repository files navigation

Google SERP API by ScrapeBadger

Get API key Docs MCP server Pricing

Google SERP API

Get Google Search results as JSON with one HTTP request. The Google SERP API returns organic results, ads, AI Overviews, People Also Ask, the knowledge graph, local results, top stories and related searches, for any country, language, city or device. A cheaper Light endpoint returns organic results only. This repo has a runnable Python, Node.js and cURL example for each and the real response each one returned.

What does a Google SERP API do?

A Google SERP API runs a Google search for you and returns the search engine results page (SERP) as structured data: each organic result's position, title, link and snippet, plus ads, AI Overviews, People Also Ask, the knowledge graph and local results. SEO teams use it for rank tracking and keyword research, and AI apps use it to ground answers in fresh results. You send a query, country and language and get JSON back.

Contents

Quick start

  1. Create a free ScrapeBadger account. You get 1,000 free credits, no card needed.

  2. Copy your API key from the dashboard and export it:

    export SCRAPEBADGER_API_KEY="your_api_key"
  3. Make your first request: search Google.

cURL

curl -sS --max-time 120 -G "https://scrapebadger.com/v1/google/search" \
  -H "X-API-Key: $SCRAPEBADGER_API_KEY" \
  --data-urlencode 'q=tesla model y' \
  --data-urlencode 'gl=us' \
  --data-urlencode 'hl=en' \
  --data-urlencode 'ai_overview=true'

Python (pip install requests)

import json
import os

import requests

API_KEY = os.environ["SCRAPEBADGER_API_KEY"]

response = requests.get(
    "https://scrapebadger.com/v1/google/search",
    headers={"X-API-Key": API_KEY},
    params={
        "q": "tesla model y",
        "gl": "us",
        "hl": "en",
        "ai_overview": True,
    },
    timeout=120,
)
response.raise_for_status()
print(json.dumps(response.json(), indent=2, ensure_ascii=False))

Node.js (18+, no dependencies)

const params = new URLSearchParams({
  q: 'tesla model y',
  gl: 'us',
  hl: 'en',
  ai_overview: 'true',
});

const response = await fetch(`https://scrapebadger.com/v1/google/search?${params}`, {
  headers: { 'X-API-Key': process.env.SCRAPEBADGER_API_KEY },
  signal: AbortSignal.timeout(120000),
});
if (!response.ok) {
  throw new Error(`HTTP ${response.status}: ${await response.text()}`);
}
console.log(JSON.stringify(await response.json(), null, 2));

Every endpoint below has the same three versions in examples/, and the real response it returned is in output-samples/.

Endpoints

Base URL: https://scrapebadger.com. Authenticate with the X-API-Key header. Credits are charged only for successful requests.

Endpoint What it returns Credits per request Docs
GET /v1/google/search Google web search 20 Docs
GET /v1/google/light/search Google Light web search 10 Docs
POST /v1/google/resolve Resolve Free Docs

Common parameters

Parameter Description Default
q The search query. Google operators such as site:, intitle: and quotes work.
gl Country of the search, e.g. us, gb, de. us
hl Interface language, e.g. en, de, fr. en
location City-level location, e.g. Austin, Texas, United States, for local results.
start Result offset for pagination (0, 10, 20...). 0

Examples by endpoint

Each example prints the JSON response. The Python versions are below; Node.js and cURL versions are linked under each one.

Search Google

Search Google and get structured results (organic, ads, KG, AI overview, PAA).

GET /v1/google/search · Credits: 20 · Docs

Parameter Required Type Default Description
q Yes string Search query (supports Google operators)
gl string us Country code
hl string en Language code
location string City-level geo-targeting
device enum desktop Device target: desktop, mobile, iphone, android, tablet One of desktop, mobile, iphone, android, tablet.
num integer 10 Results per page
start integer 0 Page offset (0, 10, 20...)
tbs string Time filter (e.g. qdr:d)
safe string off active to filter explicit results, off to keep them
ai_overview boolean false Chase deferred AI Overview page_token with a follow-up fetch and merge the result. Adds ~1s when the SERP defers the overview; the request price is unchanged.
udm string 14 for the plain web results view, 18 for forums
output enum json json (parsed results) or html (the raw results page)
domain string google.com Google domain to search, e.g. google.com, google.co.uk, google.de

Plus 36 more parameters in the docs.

import json
import os

import requests

API_KEY = os.environ["SCRAPEBADGER_API_KEY"]

response = requests.get(
    "https://scrapebadger.com/v1/google/search",
    headers={"X-API-Key": API_KEY},
    params={
        "q": "tesla model y",
        "gl": "us",
        "hl": "en",
        "ai_overview": True,
    },
    timeout=120,
)
response.raise_for_status()
print(json.dumps(response.json(), indent=2, ensure_ascii=False))

Node.js · cURL · Output sample (36 KB)

Search Google from a city

Search Google and get structured results (organic, ads, KG, AI overview, PAA). The same endpoint with a city-level location, so local results and their order match what a searcher in that city sees.

GET /v1/google/search · Credits: 20 · Docs

Parameter Required Type Default Description
q Yes string Search query (supports Google operators)
location string City-level geo-targeting
device enum desktop Device target: desktop, mobile, iphone, android, tablet One of desktop, mobile, iphone, android, tablet.
gl string us Country code
hl string en Language code

Plus 44 more parameters in the docs.

import json
import os

import requests

API_KEY = os.environ["SCRAPEBADGER_API_KEY"]

response = requests.get(
    "https://scrapebadger.com/v1/google/search",
    headers={"X-API-Key": API_KEY},
    params={
        "q": "coffee shops",
        "location": "Austin, Texas, United States",
    },
    timeout=120,
)
response.raise_for_status()
print(json.dumps(response.json(), indent=2, ensure_ascii=False))

Node.js · cURL · Output sample (28 KB)

Search Google (Light, organic results only)

Organic results and related searches only. Costs 10 credits per successful uncached request, compared with 20 credits for regular Google Search. Light always skips rich SERP blocks; mode and ai_overview cannot enable them.

GET /v1/google/light/search · Credits: 10 · Docs

Parameter Required Type Default Description
q Yes string Search query (supports Google operators)
gl string us Country code
hl string en Language code
location string City-level geo-targeting
num integer 10 Results per page
start integer 0 Page offset (0, 10, 20...)
tbs string Time filter (e.g. qdr:d)
safe string off active to filter explicit results, off to keep them
domain string google.com Google domain to search, e.g. google.com, google.co.uk, google.de

Plus 37 more parameters in the docs.

import json
import os

import requests

API_KEY = os.environ["SCRAPEBADGER_API_KEY"]

response = requests.get(
    "https://scrapebadger.com/v1/google/light/search",
    headers={"X-API-Key": API_KEY},
    params={
        "q": "python web scraping tutorial",
        "gl": "us",
        "hl": "en",
    },
    timeout=120,
)
response.raise_for_status()
print(json.dumps(response.json(), indent=2, ensure_ascii=False))

Node.js · cURL · Output sample (14 KB)

Example output

A real response from GET /v1/google/search, trimmed to the first items of each list. The full response is in output-samples/search.json.

{
  "search_information": {
    "query_displayed": "tesla model y",
    "total_results": 106,
    "time_taken": 0.42,
    "organic_results_state": "Results for exact spelling",
    "url": "https://www.google.com/search?q=tesla+model+y&gl=us&hl=en&num=10&oq=tesla+model+y&sourceid=chrome&ie=UTF-8"
  },
  "organic_results": [
    {
      "position": 1,
      "title": "QOTD: Do You Dig the New Tesla Model Y?",
      "link": "https://www.thetruthaboutcars.com/cars/question-of-the-day/qotd-do-you-dig-the-new-tesla-model-y-44511289",
      "displayed_link": "https://www.thetruthaboutcars.com › question-of-the-day",
      "snippet": "We've now seen the next Tesla Model Y. this one is pretty straightforward. Its $42,000 AWD Model Y After Nine Months",
      "highlighted_keywords": [
        "Its $42,000 AWD Model Y"
      ],
      "source": "thetruthaboutcars.com",
      "favicon": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABwAAAAcCAMAAABF0y+mAAAAb1BMVEX////sysvEOD3FP0Pv0dLGQ0e/GiG9ABHLWFzMXGDBJy3qw8TovL7JUVbhp6jfoKLdmpzKVFjAIynenqDAIii/Fx+8AAC+ChW+ERrmtbby2tu+CBTRb3LVgILITVHnuLq9AArZjY/25OT89f…",
      "sitelinks": [],
      "inline_sitelinks": [],
      "date": "Jan 13, 2025",
      "rich_snippet": null,
      "read_more_link": null,
      "rank": 1,
      "page_rank": 1,
      "link_token": null,
      "retry_after_seconds": null
    }
  ],
  "related_questions": [
    {
      "question": "How does the Model Y handle in snow?",
      "type": "ai_overview",
      "rank": 1,
      "title": null,
      "link": null,
      "snippet": null,
      "displayed_link": null,
      "source_logo": null,
      "text_blocks": null,
      "references": null
    }
  ],
  "knowledge_graph": {
    "title": "2026 Tesla Model Y",
    "type": "SUV",
    "description": null,
    "image": null,
    "source": null,
    "attributes": {
      "ev range": "294 to 357 mi battery-only",
      "dimension": "187-189″ L x 76-84″ W x 64″ H",
      "cargo volume": "29.03 to 30.2 ft³, 71.41 to 76.2 ft³ with seat area"
    }
  }
}

Use it with AI agents (MCP)

ScrapeBadger runs a hosted MCP server, so Claude, Cursor, ChatGPT and other agents can call the Google Search endpoints as tools, with no code.

  • Claude (claude.ai or Claude Desktop): Settings → Connectors → Add custom connector → https://mcp.scrapebadger.com/mcp, then sign in. No API key needed.
  • Cursor, VS Code, Windsurf and other clients: add this server to your MCP config:
{
  "mcpServers": {
    "scrapebadger": {
      "url": "https://mcp.scrapebadger.com/mcp?apis=google",
      "headers": { "Authorization": "Bearer YOUR_SCRAPEBADGER_API_KEY" }
    }
  }
}

Then ask:

Search Google for "best project management software" in the US and the UK, and tell me which domains rank in the top 10 in both.

Setup guides for each client are in the MCP docs.

Use cases

Use case What you collect Endpoints
Rank tracking Your position and your competitors' for each keyword, by country, city and device Search Google, Search Google from a city, Search Google (Light, organic results only)
Keyword and content research People Also Ask questions, related searches and the pages that rank Search Google
AI Overview monitoring Whether an AI Overview appears and which sources it cites Search Google
Local SEO The local pack and organic results as a searcher in a given city sees them Search Google from a city
Grounding AI apps and agents Fresh organic results to feed an LLM, at the lowest cost per query Search Google (Light, organic results only)
Ad intelligence Which advertisers bid on a keyword, and their ad copy Search Google

Pricing

  • Each endpoint's credit cost is listed in the endpoints table.
  • Only successful requests are billed. Blocked, empty and failed results cost nothing.
  • New accounts get 1,000 free credits. After that, pay as you go or pick a monthly plan. Credits on pay-as-you-go never expire.

See ScrapeBadger pricing for the price per credit on each plan.

Errors

Errors come back as JSON with a detail field (and an error code on some).

Status Meaning What to do
400 / 422 A parameter is missing or invalid Check the parameter table for the endpoint
401 Missing, invalid or expired API key Send the key in the X-API-Key header
402 Out of credits Top up or upgrade in the dashboard
403 The key can't call this API, or the request came from an IP the key doesn't allow Check the key's scopes and IP allowlist
404 The item, page or profile doesn't exist (or is no longer public) Check the ID; not billed
429 Over your account's max concurrency Wait Retry-After (1 s) and retry; run fewer calls in parallel (concurrency)
502 / 503 / 504 The target site failed or timed out on this attempt Not billed. Retry with backoff

Long calls can run asynchronously: send Prefer: respond-async and poll the returned request_id (async requests).

FAQ

Is it legal to scrape Google Search results?

Search results are public, and collecting public data is generally lawful in most jurisdictions; US courts have so far sided with SERP scrapers when Google has sued them. Check the rules that apply to your use case and ask a lawyer if you're unsure.

What's in the response?

Organic results (position, title, link, displayed link, snippet, sitelinks), ads, AI Overview, People Also Ask, knowledge graph, local results, top stories, videos and related searches, whichever Google shows for the query. The Light endpoint returns only organic results and related searches.

How much does it cost?

Full search costs 20 credits and Light search 10 credits per successful request; failed requests are not billed. You get 1,000 free credits when you sign up, then pay as you go or pick a plan on the pricing page.

Which countries, languages and devices are supported?

Any country and language Google supports, via gl and hl, any Google domain via domain, city-level targeting via location, and desktop, mobile, iPhone, Android or tablet via device.

How fast is it, and are there rate limits?

Most searches answer in 2 to 4 seconds; Light is faster. There's no per-minute cap: you can run as many requests in parallel as your plan's max concurrency allows, and a request over it gets 429 without being billed.

Other languages

These examples use plain HTTP. Official SDKs wrap every endpoint with types and retries:

Language Repository Install
Python scrape-badger/scrapebadger-python pip install scrapebadger
Node.js / TypeScript scrape-badger/scrapebadger-node npm install scrapebadger
Go scrape-badger/scrapebadger-go
Java scrape-badger/scrapebadger-java
C# scrape-badger/scrapebadger-csharp
PHP scrape-badger/scrapebadger-php
Ruby scrape-badger/scrapebadger-ruby
Rust scrape-badger/scrapebadger-rust
Kotlin scrape-badger/scrapebadger-kotlin
Swift scrape-badger/scrapebadger-swift
Dart scrape-badger/scrapebadger-dart
C++ scrape-badger/scrapebadger-cpp

There is also a CLI (pip install scrapebadger-cli) and an n8n node.

Related scrapers

Learn more

Disclaimer

ScrapeBadger is an independent tool and is not affiliated with, endorsed by, or sponsored by Google LLC or any of its subsidiaries or affiliates. "Google" is a trademark of Google LLC, used here only to describe the platform this scraper works with. This repository only covers publicly available data. You are responsible for how you use the data you collect and for following the laws that apply to you.

License

MIT. The examples are free to copy into your own projects.