# Google SERP & AI Mode API — Search Results & Citations (`gauravlabs/google-serp-api`) Actor

Search Google for organic results, ads, local packs, People Also Ask and AI Overviews. Switch to Google AI Mode for answers and citations. Batch keywords, location targeting, pagination and domain rank tracking.

- **URL**: https://apify.com/gauravlabs/google-serp-api.md
- **Developed by:** [Gaurav Kumar Choudhary](https://apify.com/gauravlabs) (community)
- **Categories:** SEO tools, AI, Developer tools
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $1.50 / 1,000 successful google serp pages

This Actor is paid per event. You are not charged for the Apify platform usage, but only a fixed price for specific events.

Learn more: https://docs.apify.com/actors/running/actors-in-store.md#pay-per-event

## What's an Apify Actor?

An Actor is a serverless cloud program that runs on the Apify platform. It has two run modes.
In Batch mode, an Actor accepts a well-defined JSON input, performs an action which can take anything from a few seconds to a few hours,
and optionally produces a well-defined JSON output, datasets with results, or files in key-value store.
In Standby mode, an Actor provides a web server which can be used as a website, API, or an MCP server.

Apify vocabulary and the platform model are defined once, in the agent quickstart at https://apify.com/agents.md.

## How to integrate an Actor?

If asked about integration, you help developers integrate Actors into their projects.
You adapt to their stack and deliver integrations that are safe, well-documented, and production-ready.

Do not guess an integration path. Every one of them is in the agent quickstart at https://apify.com/agents.md: the Apify MCP server, Agent Skills with the Apify CLI, the JavaScript and Python clients, the REST API, and the account-free path for an agent with no human to sign in. It also carries the rule on stating cost before the first paid run.

For examples already wired to this Actor's own input schema, see the [API](#api) section below.

Each client library has reference documentation the quickstart does not restate: [JavaScript/TypeScript](https://docs.apify.com/api/client/js/docs.md) (`npm install apify-client`) and [Python](https://docs.apify.com/api/client/python/docs.md) (`pip install apify-client`).

# README

## Google SERP & AI Mode API — Search Results & Citations

### At a glance

- Collect: Google SERP pages or AI Mode responses; optional deferred AI Overview completion.
- Input: use the runnable example below or the prefilled Input form.
- Output: the default dataset supports JSON/CSV/Excel export; see output modes below.
- Billing: $1.50 per 1,000 SERP pages/non-empty AI responses; $0.75 per 1,000 completed optional Overview follow-ups. No startup fee. Platform usage may be additional.
- Limits: AI answers/citations are not guaranteed. Rank absence means not found on fetched pages, not absent from Google.

Search Google in two modes from one Actor. Use **SERP** for organic rankings, ads, local packs, People Also Ask, related searches and available AI Overviews. Use **AI Mode** for Google's dedicated AI answer, source citations and available shopping cards.

No Google API key, login or proxy configuration is required. Batch keywords and export JSON, CSV or Excel, or call the Actor through the Apify API from n8n, Make or your own application.

### Launch pricing — $1.50 per 1,000 main requests

| Delivered output | Price per 1,000 | Billing unit |
| --- | ---: | --- |
| Google SERP | $1.50 | Successful search result page, including all returned sections |
| Google AI Mode | $1.50 | Non-empty AI response, including text blocks and citations |
| Optional deferred AI Overview completion | $0.75 | Completed non-empty follow-up response |

No startup fee, subscription or per-link charge. Inline AI Overviews, domain-rank calculations, available ads, local packs and People Also Ask are included with the SERP page. Deferred completion is opt-in and charged separately only when content is delivered. Failed fetches and empty AI Mode responses have no Actor request fee; valid empty SERP pages remain billable. For example, 100 successful one-page searches cost $0.15 in Actor request fees. See the live Pricing tab for current rates and any applicable platform charges.

### Quick start: standard Google search

```json
{"mode":"serp","queries":["python tutorial"],"maxRequests":1,"gl":"us","hl":"en"}
```

### Google AI Mode

```json
{"mode":"ai_mode","queries":["python vs javascript for beginners"],"maxRequests":1,"gl":"us","hl":"en"}
```

AI Mode returns structured `text_blocks`, `references`, `shopping_results` and a convenient `answerText`. Google does not supply AI content for every query. An empty response produces a row with `status: "unavailable"`, succeeds without an Actor request charge, and is counted separately in SUMMARY. AI Mode has no SERP pagination or strict language/country/time filters. Availability and citations vary between requests.

### Domain rank tracking and pagination

```json
{"mode":"serp","queries":["web scraping tools"],"targetDomains":["apify.com"],"maxPagesPerQuery":3,"maxRequests":3,"cache":false}
```

`domainRanks` reports matching organic URLs, page positions and `bestRank` for each fetched page. Rank is the starting offset plus the page position. Subdomains match their parent domain; unrelated suffixes do not. This is observed SERP position, not a universal or guaranteed ranking. Google redirect links that cannot be resolved may prevent a domain match. A missing domain is only absent from the fetched pages.

Pages are requested sequentially using offsets 0, 10, 20, up to 100. Desktop pagination stops when Google omits the next link or returns no organic results; mobile pagination uses offsets because next links are usually absent. `maxRequests` caps attempted requests, not result rows. Each dataset row contains one page or AI response, with its nested sections preserved. No automatic historical comparisons are promised.

### Localization and filters

Set `gl` for the country perspective and `hl` for interface language. Optional `location` accepts Google's canonical names, for example `New York,New York,United States`; send a matching `gl`. `uule` takes precedence. Invalid or unsupported locations can be ignored by Google. Regional domains and mobile layout are supported.

SERP-only filters include strict language `lr`, strict country `cr`, `time_period`, spelling correction `nfpr`, and omitted-results `filter`. SafeSearch works in both modes. Leave SERP-only filters blank when using AI Mode. Fresh searches are the default; cached SERPs can be enabled with `cache: true`.

### AI Overview versus AI Mode

An AI Overview is a panel within a standard search page; AI Mode is a separate answer surface. Inline AI Overviews are included with SERP output when available. A deferred panel is marked `state: "deferred"`. Enable `resolveAiOverview` to attempt its completion immediately. This adds a separate follow-up request when available and counts toward `maxRequests`; set the limit accordingly. Completed follow-ups are separate `mode: "ai_overview"` rows. An unavailable follow-up is uncharged. Follow-up errors preserve the successful SERP and appear as warnings in SUMMARY.

### Billing and output

See the live Pricing tab for active rates. SERP pages use `serp-request`; non-empty AI answers use `ai-request`; completed deferred panels use `overview-request`. There is no startup event. All sections delivered with a page are included; there is no per-link fee. Valid empty SERP pages are billable. Failed fetches and empty AI Mode responses are not charged by this Actor. Platform usage charges, if applicable, are separate. Set Apify's maximum total charge and `maxRequests` to control spending.

The dataset preserves structured sections, timestamps, locale and per-page domain ranks. SUMMARY contains attempted/successful/billable request counts, organic counts, unavailable AI responses, warnings and safe errors. Raw HTML and service session identifiers are not exposed. Fields can be empty or absent when Google does not supply them.

### Support

Open an Actor issue with your run ID and non-sensitive input, or contact the developer through the profile for custom workflows and additional data sources. Never post credentials. Independent tool; not affiliated with or endorsed by Google. Results are point-in-time observations and AI answers can be inaccurate.

### Minimal API example

Store your own Apify token in `APIFY_TOKEN`; never paste it into public input or code. This example uses the same small input as the prefilled form.

```python
import os
import requests

response = requests.post(
    "https://api.apify.com/v2/acts/gauravlabs~google-serp-api/run-sync-get-dataset-items",
    headers={"Authorization": "Bearer " + os.environ["APIFY_TOKEN"]},
    json={"queries":["python tutorial"]},
    timeout=300,
)
response.raise_for_status()
print(response.json())
```

For large batches, start an asynchronous run with `/runs`, wait for its final status, and retrieve its default dataset. HTTP success when starting a run does not prove the extraction succeeded.

#### Minimal output shape (illustrative)

The following shows one documented field, not a fresh result or a promised yield. Inspect the output reference above for the complete schema.

```json
{
  "mode": "serp"
}
```

### Practical workflow and accuracy notes

SERP example: `{"queries":["python tutorial"],"mode":"serp","maxRequests":1}`. AI Mode example: `{"queries":["how to choose a laptop"],"mode":"ai_mode","maxRequests":1}`. Optional Overview follow-up example: `{"queries":["what is machine learning"],"mode":"serp","resolveAiOverview":true,"maxRequests":2}`. Overview/AI availability varies. Use the documented mode field and stop/status metadata to distinguish an absent answer from a request failure.

# Actor input Schema

## `mode` (type: `string`):

AI Mode is a separate Google search surface. AI Overviews are optional panels within normal SERPs.

## `queries` (type: `array`):

1–1000 keywords. Duplicates are skipped. Maximum requests limits the run.

## `maxRequests` (type: `integer`):

Counts all attempts, including optional AI Overview follow-ups. This is a per-run cap.

## `maxPagesPerQuery` (type: `integer`):

SERP only. Each successful page is a billable request. AI Mode requires 1.

## `start` (type: `integer`):

0, 10, 20, …100. Final offset cannot exceed 100. AI Mode requires 0.

## `hl` (type: `string`):

Examples en, de, fr, hi. Interface language differs from the strict lr filter.

## `gl` (type: `string`):

Lowercase two-letter code, for example us, gb, in, de. Set this together with location.

## `google_domain` (type: `string`):

Examples google.com, google.co.uk, google.de. Regional availability varies.

## `device` (type: `string`):

Mobile SERPs may not report total result counts or next-page links.

## `location` (type: `string`):

Example New York,New York,United States. Must match Google's location name; also set gl.

## `uule` (type: `string`):

Encoded Google location. Takes precedence over location.

## `targetDomains` (type: `array`):

Up to 100 domains, e.g. example.com. Returns observed organic positions in SERP mode. Not-found means absent from fetched pages, not absent from Google.

## `cache` (type: `boolean`):

SERP only. False requests fresh results. Cached and fresh pages have the same Actor price.

## `resolveGoto` (type: `boolean`):

SERP only. Best-effort destination URLs; unresolved links may remain Google redirects.

## `resolveAiOverview` (type: `boolean`):

SERP only. May add one separately billable follow-up per deferred panel. Counts toward maxRequests. AI availability is not guaranteed.

## `safe` (type: `string`):

Use Google's default or request adult-content filtering in either mode.

## `lr` (type: `string`):

Example lang_en or lang_de. Leave empty in AI Mode.

## `cr` (type: `string`):

Example countryUS or countryDE. Leave empty in AI Mode.

## `time_period` (type: `string`):

Restrict SERP results by recency. Leave empty for AI Mode.

## `nfpr` (type: `boolean`):

Prevent automatic query correction. Leave false for AI Mode.

## `filter` (type: `string`):

Control Google's similar and omitted-results filtering. Leave empty for AI Mode.

## `requestTimeoutSecs` (type: `integer`):

At least 60 seconds. No automatic Actor retries; failed fetches are not billed by this Actor.

## Actor input object example

```json
{
  "mode": "serp",
  "queries": [
    "python tutorial"
  ],
  "maxRequests": 10,
  "maxPagesPerQuery": 1,
  "start": 0,
  "hl": "en",
  "gl": "us",
  "google_domain": "google.com",
  "device": "desktop",
  "cache": false,
  "resolveGoto": true,
  "resolveAiOverview": false,
  "safe": "",
  "time_period": "",
  "nfpr": false,
  "filter": "",
  "requestTimeoutSecs": 90
}
```

# Actor output Schema

## `results` (type: `string`):

No description

## `summary` (type: `string`):

No description

# API

You can run this Actor programmatically using our API. Below are code examples in JavaScript, Python, and CLI, as well as the OpenAPI specification and MCP server setup.

## JavaScript example

```javascript
import { ApifyClient } from 'apify-client';

// Initialize the ApifyClient with your Apify API token
// Replace the '<YOUR_API_TOKEN>' with your token
const client = new ApifyClient({
    token: '<YOUR_API_TOKEN>',
});

// Prepare Actor input
const input = {
    "queries": [
        "python tutorial"
    ]
};

// Run the Actor and wait for it to finish
const run = await client.actor("gauravlabs/google-serp-api").call(input);

// Fetch and print Actor results from the run's dataset (if any)
console.log('Results from dataset');
console.log(`💾 Check your data here: https://console.apify.com/storage/datasets/${run.defaultDatasetId}`);
const { items } = await client.dataset(run.defaultDatasetId).listItems();
items.forEach((item) => {
    console.dir(item);
});

// 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/js/docs

```

## Python example

```python
from apify_client import ApifyClient

# Initialize the ApifyClient with your Apify API token
# Replace '<YOUR_API_TOKEN>' with your token.
client = ApifyClient("<YOUR_API_TOKEN>")

# Prepare the Actor input
run_input = { "queries": ["python tutorial"] }

# Run the Actor and wait for it to finish
run = client.actor("gauravlabs/google-serp-api").call(run_input=run_input)

# Fetch and print Actor results from the run's dataset (if there are any)
print(f"💾 Check your data here: https://console.apify.com/storage/datasets/{run.default_dataset_id}")
for item in client.dataset(run.default_dataset_id).iterate_items():
    print(item)

# 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/python/docs/quick-start

```

## CLI example

```bash
echo '{
  "queries": [
    "python tutorial"
  ]
}' |
apify call gauravlabs/google-serp-api --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,gauravlabs/google-serp-api"
        }
    }
}
```

The hosted server signs you in with OAuth on first connect, so no API token belongs in this config. Clients without OAuth support can send an `Authorization: Bearer <APIFY_API_TOKEN>` header instead, using a token from API & Integrations in Apify Console (https://console.apify.com/settings/integrations).

## OpenAPI specification

Download the OpenAPI definition: https://api.apify.com/v2/actors/V5MxGZIXJFoJ50pfH/builds/r27oNDTXi6n7wpXED/openapi.json
