Site icon DataForSEO

How to Authenticate with DataForSEO Google Search SERP API: API Key Setup and Code Examples

If you’re here for a Google Search API key example, you’re in the right place. The setup is simpler than the words around it suggest, even if API key, token, Basic Auth, and Base64 sound intimidating when you’re not a developer. Authentication is one of the easier parts of working with our APIs. You set up one credential pair, encode it once, and use it in whichever tool you’ve already got open: Make, n8n, Custom GPTs, scripts, AI agents. This guide walks you through finding your credentials, encoding them, and getting them into that tool.

Setting up Google Search API authentication: what you need to know

When you’re searching for “Google Search API,” you’re probably looking for DataForSEO Google Organic SERP API. It’s a live source of Google search results, including featured snippets, AI Overviews, and other SERP features. We’ll use it as the example throughout this article, though DataForSEO authentication works the same across all our APIs. Set it up once, and you’re done.

A quick glossary first, so the rest of the post reads cleanly.

That’s the vocabulary out of the way. Here’s the actual setup.

Step 1 — Get your API credentials from the dashboard

Create a free account on our website. New accounts get a $1 trial credit, and the SERP Google Organic Live Advanced endpoint costs $0.002 per call, so the trial covers around 500 live Google SERPs before you spend a cent. Enough room to set things up and run a few tests.

Once you’re logged in, open the API Access tab in the dashboard sidebar. Two things most teams trip on here:

Now you have your login (the email you signed up with) and your API password (the one our system generated). The next step is to combine them into a format that an HTTP request can carry.

Step 2 — Encode your Google Search API key (your DataForSEO credentials) with Base64

The fastest path is the dashboard itself. For the first 24 hours after registration, the API Access tab displays a ready-made, Base64-encoded string of your login:password. Copy it once, and you’re done. The string disappears after 24 hours for the same security reason your API password does.

If you missed that window, three fallback paths take about as long.

Most no-code tools handle this step for you behind the scenes. You paste the raw login and password into two fields, and the tool encodes the result before sending the request.

Worth saying twice: Base64 is encoding, not encryption. The encoded string is reversible by anyone who copies it, so don’t paste it into public chat channels, public repos, or shared docs. Treat it the way you’d treat a password.

Step 3 — Plug the credentials into your environment

The same Basic Auth pattern works the same way in every environment. The credential doesn’t change. Only the field you paste it into does. Here’s what that looks like across the four most common paths.

Make.com

In your Make scenario, add an HTTP module and set the method to POST. Under Credentials, create a new Basic Auth connection. Paste your DataForSEO email into Username and your API password into Password. Make handles Base64 encoding for you and adds the right Authorization header to every request. Save the connection and reuse it across scenarios.

n8n

Add an HTTP Request node to your workflow. Set the method to POST and paste the DataForSEO endpoint URL. Under Authentication, select Generic Credential Type, then choose Basic Auth in the Generic Auth Type dropdown. Enter your email as the username and your API password as the password. n8n encodes Base64 for you. For a no-code workflow built on this pattern, see our walkthrough on automating keyword research with n8n and DataForSEO.

Custom GPTs (ChatGPT Actions)

In your Custom GPT’s Actions configuration, click Authentication, select API Key, and set Auth Type to Basic. In the API Key field, paste your Base64-encoded login:password string from Step 2. For the full walkthrough, including the OpenAPI schema, see our guide on connecting DataForSEO to ChatGPT.

Direct API call with cURL

If you’re sending the HTTP request yourself, from a script, a Google Apps Script in a Sheet, or a Claude Code workflow, the snippet below is the smallest working example. It hits our Google Organic Advanced SERP API endpoint and returns top ten Google organic results along with any SERP features Google returned for the query.

# Instead of 'login' and 'password' use your credentials
# from https://app.dataforseo.com/api-access
login="your_email@example.com"
password="your_api_password"
cred="$(printf "%s" "${login}:${password}" | base64)"

curl --location --request POST "https://api.dataforseo.com/v3/serp/google/organic/live/advanced" \
  --header "Authorization: Basic ${cred}" \
  --header "Content-Type: application/json" \
  --data-raw '[
    {
      "keyword": "best serp api",
      "location_code": 2840,
      "language_code": "en"
    }
  ]'

Endpoint used: api.dataforseo.com/v3/serp/google/organic/live/advanced. See the Live SERP API docs for the full parameter list.

A successful call returns JSON structured like this:

{
  "version": "0.1.20200214",
  "status_code": 20000,
  "status_message": "Ok.",
  "time": "7.7156 sec.",
  "cost": 0.002,
  "tasks_count": 1,
  "tasks_error": 0,
  "tasks": [
    {
      "id": "02171509-1535-0139-0000-fa36a0ff59c6",
      "status_code": 20000,
      "status_message": "Ok.",
      "cost": 0.002,
      "result_count": 1,
      "path": [ ... ],
      "data": { ... },
      "result": [
        {
          "keyword": "best serp api",
          "type": "organic",
          "se_domain": "google.com",
          "location_code": 2840,
          "language_code": "en",
          "check_url": "https://google.com/search?q=best+serp+api&...",
          "items_count": 100,
          "items": [ ... ]
        }
      ]
    }
  ]
}

The top-level status_code: 20000 indicates that the request itself was accepted. The same code in the tasks array means your specific task succeeded. The cost field shows what you were charged, which is useful to watch while you’re testing.

Common authentication mistakes (and how to fix them)

Five issues cover most “why won’t it work” cases. Each one is fixable in under a minute.

One last thing before you go live

Authentication at DataForSEO uses a single credential pair: your API login plus your API password, encoded with Base64 and pasted into the auth field of your environment. The same credentials work across all DataForSEO APIs.

Before you start driving real traffic to the API, validate everything in our sandbox at zero cost. Just swap the hostname in your request from api.dataforseo.com to sandbox.dataforseo.com.

Try for free

Exit mobile version