As of October 7, 2026, Shifter has the largest pool of live US IPs, more than Oxylabs and Bright Data, at a fraction of the cost.Shifter now has the largest pool of live US IPs

See benchmarks

Knowledge

How to Use a SERP API: Google SERP API Integration and API Key Setup Guide

Set up a Google SERP API step by step: get and store an API key, make your first search, localise results, handle errors and track rankings with tested Python.

Matt Brown

October 18, 2026 · 6 min read

A SERP API runs a search engine query for you and returns the results page as structured JSON: organic results with their positions, ads, featured snippets, local results and more. Instead of building scrapers for Google and keeping them working, you send one request and read the fields you need.

This guide walks through setting one up from scratch: getting and storing an API key, making your first search, getting results for the right location and device, handling errors, and turning results into a ranking check. It uses Shifter’s SERP API as the example; most SERP APIs work the same way.

Step 1: get your API key

Every request carries an API key. In Shifter’s panel, open SERP API, then API Keys, and copy an active key.

Treat the key like a password:

  • Keep it out of code and repositories. Store it in an environment variable or a secrets manager.
  • Use separate keys for development and production where you can, so a leaked test key cannot affect production.
  • Rotate a key if it might have been exposed, and update it everywhere it is used.
export SHIFTER_SERP_KEY="your-key-here"

The API is a single endpoint, https://serp.shifter.io/v1. Choose the search engine with engine and pass the query as q:

curl "https://serp.shifter.io/v1?engine=google&api_key=$SHIFTER_SERP_KEY&q=residential+proxies"

The response is JSON. For a Google search, organic_results holds the ordinary results, each with a position, title, link, displayed_link and snippet. Other sections, such as ads and local results, appear when the results page has them.

The same endpoint covers other search engines and Google surfaces: change engine to bing or yandex for those search engines, or to google_maps, google_news or google_shopping for other Google results. The rest of this guide applies to all of them; only the fields in the response change.

Step 3: get results for the right place and device

Search results differ by location, language and device, often a lot. A ranking check that does not fix all of them measures a different results page every time.

ParameterWhat it setsExample
locationWhere the search is made fromAustin,Texas,United States
glThe country of the resultsus
hlThe interface languageen
deviceDesktop, mobile or tablet resultsmobile

Spell out the location fully (city, region, country), because short names such as “Springfield” are ambiguous. Our guide to geo-targeted SERP APIs for local SEO explains why location precision matters so much.

Step 4: handle errors

Requests can fail for reasons that pass and reasons that do not:

  • Retry rate limits and temporary server errors, with a pause that grows each time.
  • Stop and fix authentication and malformed-request errors; retrying them only repeats the failure.
  • Set a timeout on every request, so one slow search cannot hold up a whole run.

Putting it together

The helper below reads the key from the environment, always sends location, language and device, retries the errors worth retrying, and includes a function that finds where a domain ranks in the organic results:

import os
import time
from urllib.parse import urlparse

import requests

API = "https://serp.shifter.io/v1"
RETRY = {408, 429, 500, 502, 503}


def google_search(query, location, gl="us", hl="en", device="desktop", session=None, attempts=3):
    """One Google search as seen from `location`, returned as parsed JSON."""
    session = session or requests.Session()
    params = {"engine": "google", "api_key": os.environ["SHIFTER_SERP_KEY"], "q": query,
              "location": location, "gl": gl, "hl": hl, "device": device}
    for attempt in range(1, attempts + 1):
        response = session.get(API, params=params, timeout=60)
        if response.status_code == 200:
            return response.json()
        if response.status_code not in RETRY or attempt == attempts:
            raise RuntimeError(f"{query!r}: HTTP {response.status_code} {response.text[:200]}")
        time.sleep(2 * attempt)


def rank_of(serp, domain):
    """Position of the first organic result on `domain`, or None if it is not there."""
    for result in serp.get("organic_results", []):
        host = urlparse(result["link"]).netloc.lower()
        if host == domain or host.endswith("." + domain):
            return result["position"]
    return None

Checking where a site ranks for two keywords, as seen on mobile in Austin:

from serp import google_search, rank_of

keywords = ["emergency plumber", "water heater repair"]
for keyword in keywords:
    serp = google_search(keyword, location="Austin,Texas,United States", device="mobile")
    print(keyword, rank_of(serp, "example-plumbing.com"))

We tested the helper’s request parameters, retries, error handling and ranking lookup against simulated responses.

Step 5: turn it into ranking tracking

One search is a snapshot. Tracking means running the same searches on a schedule and storing the results:

  1. Fix the keyword list and the location, language and device for each one.
  2. Run on a schedule, daily or weekly depending on how much rankings move in your market.
  3. Store each full response with its time and settings, not just the position, so you can look back at what changed.
  4. Alert on changes that matter: a drop out of the top three, a competitor appearing above you, a featured snippet lost.

Our guide to automating daily keyword position monitoring covers scheduling and storage in more depth. If rank tracking is a core part of your work, our SEO monitoring page covers the wider set-up.

Common setup mistakes

  • No location set. Results then come from a default location that is probably not your market.
  • Mixing desktop and mobile between runs, which makes rankings jump for no real reason.
  • Matching by exact URL instead of domain, so a ranking page that changed path looks like a lost ranking.
  • Storing only positions. Without the full response you cannot tell why a position changed.
  • Hard-coding the key, which ends up in a repository sooner or later.

FAQ

What is a SERP API?

A service that runs search engine queries for you and returns the results page as structured data, such as organic results with positions, ads, featured snippets and local results, so you do not have to scrape and parse search pages yourself.

How do I get a SERP API key?

Sign up with a SERP API provider and create a key in its dashboard. In Shifter’s panel, the keys are under SERP API, then API Keys. Store the key in an environment variable rather than in your code.

Why do my SERP API results differ from what I see in Google?

Usually because the location, language, device or personalisation differ. Your own searches are personalised and come from your location; set the API’s location, language and device explicitly to match the market you want to measure.

How often should I check rankings?

Daily for competitive keywords and fast-moving markets, weekly for most others. Keep the settings identical between runs so changes reflect the results, not the measurement.

The bottom line

Setting up a SERP API takes a few steps: store the key safely, send the query with the engine, location, language and device fixed, retry only the errors that can pass, and read the positions from the structured results. Run the same searches on a schedule, keep the full responses, and you have a ranking tracker that measures the same results page every time.

Ready to get started?

Try Shifter's residential proxies, 205M+ IPs, 195+ countries, from $0.10/GB.

Get Started