How to Get a Google Search API Key and cx ID (2026 Guide)
To get a Google Search API key, pick a Google Cloud project, enable the Custom Search API, create an API key under APIs & Services > Credentials restricted to that API, then create a Programmable Search Engine and copy its Search engine ID (cx). The key is free and covers 100 queries a day, but Google has closed the Custom Search JSON API to new customers and ends it on January 1, 2027, so new projects should plan for an alternative.
Read this first: Google's Custom Search JSON API overview says the API "is closed to new customers", and existing customers have until January 1, 2027. If your organization already uses it, the steps below still work. If you are starting fresh, skip to "If Google will not give you access".
What you need
- A Google account and a Google Cloud project.
- A billing account, only if you need more than 100 queries a day.
- Two values for every request: an API key (
key) and a Programmable Search Engine ID (cx), plus your search text (q). Google's REST guide lists these three as required.
How to get a Google Search API key, step by step
- Pick a project. In the Google Cloud console, use the project picker to create a project or select one.
- Enable the API. Go to APIs & Services > Library, search for "Custom Search API" and click Enable. Its service name is
customsearch.googleapis.com. - Create the key. Go to APIs & Services > Credentials, click Create credentials, choose API key. Google's key docs say the console requires at least one API restriction: choose Custom Search API.
- Add an application restriction. IP addresses for a server, websites (HTTP referrers) for browser code. A key can have only one application restriction type at a time.
- Create a search engine. In the Programmable Search Engine control panel, add an engine. Since January 20, 2026, new engines must use "Sites to search", up to 50 domains (Google's announcement).
- Copy the cx. Open the engine; the Search engine ID is in the Basic section of the Overview page (Google help). That string is your
cx. - Set a quota. Before you turn on billing, set a daily cap on the API's quota page so a bug cannot run up a bill.
The same key from the command line:
gcloud services enable customsearch.googleapis.com
gcloud services api-keys create --display-name="search-key" \
--api-target=service=customsearch.googleapis.com
Test it with curl
curl "https://www.googleapis.com/customsearch/v1?key=YOUR_KEY&cx=YOUR_CX&q=lectures"
A working key returns HTTP 200 and JSON with items, each holding link, title and snippet. To keep the key out of URLs and logs, send it as a header instead; Google APIs accept X-Goog-Api-Key (system parameters):
curl "https://www.googleapis.com/customsearch/v1?cx=YOUR_CX&q=lectures" \
-H "X-Goog-Api-Key: YOUR_KEY"
Python example with paging
import os
import requests
KEY = os.environ["GOOGLE_API_KEY"]
CX = os.environ["GOOGLE_CX"]
def search(q, depth=30):
results, start = [], 1
# Google errors when start + num passes 100.
while start <= depth and start + 10 <= 100:
r = requests.get(
"https://www.googleapis.com/customsearch/v1",
headers={"X-Goog-Api-Key": KEY},
params={"cx": CX, "q": q, "num": 10, "start": start},
timeout=30,
)
if r.status_code == 429:
raise RuntimeError("Quota used up; try again after the daily reset")
r.raise_for_status()
data = r.json()
results += [(i["link"], i["title"]) for i in data.get("items", [])]
if "nextPage" not in data.get("queries", {}):
break
start += 10
return results
for rank, (link, title) in enumerate(search("standing desk"), 1):
print(rank, title, link)
Each loop is one billable query. A depth of 30 costs 3 queries per keyword.
Lock the key down
- Restrict it to the Custom Search API. Google says unrestricted keys are insecure, and an unrestricted key works with every API that accepts keys.
- Add an IP or website restriction. Google recommends setting both kinds.
- Keep it on the server. Browser code exposes the key to anyone who opens developer tools.
- Use one key per app and environment, so you can delete one without breaking the rest.
- If a key leaks, create a new one, switch your code, then delete the old key.
Common errors and fixes
| Status | Usual cause | Fix |
|---|---|---|
| 400 | Missing q or cx, a bad parameter, or start + num above 100 | Check the three required parameters; stop paging at 100 results |
| 403 | API not enabled in the key's project, key restricted to another API, request from an IP or site the key does not allow, or a project without access to this closed API | Enable the API in the same project as the key; review both restrictions |
| 429 | Daily quota used: 100 without billing, 10,000 at most with billing | Wait for the reset, raise your cap, or enable billing |
200 with no items | Your engine's "Sites to search" does not cover the query | Add the domains you expect results from |
Google's error guidelines map 403 to PERMISSION_DENIED and 429 to RESOURCE_EXHAUSTED, so the status field in the error body tells you which one you hit.
If Google will not give you access
A new project cannot become a Custom Search customer, so pick by job. For your own site, use the free Programmable Search Element or Vertex AI Search. For AI answers, use Grounding with Google Search in Gemini. For result lists, use a search results API. Prices for each are in Google Search API alternatives, and the full Custom Search price table is in Google Custom Search API pricing.
Doing it with ScrapeIO
A ScrapeIO key needs no Cloud project and no cx: sign up, copy the key from the dashboard, and send it as x-api-key. New accounts get 100 free credits, and the google search API costs 1 credit a call. The same key works for the Google ad library advertiser search API and every social endpoint on the platform pages.
curl "https://scrapeio.com/v1/google/search?query=standing+desk®ion=US" \
-H "x-api-key: YOUR_KEY"
FAQ
Is a Google Search API key free?
The key costs nothing, and existing customers get 100 free queries a day. Queries after that cost $5 per 1,000.
Where do I find my cx?
In the Programmable Search Engine control panel, open your engine; the Search engine ID is in the Basic section of the Overview page.
Can I use my Google Maps key for search?
Technically yes, if the Custom Search API is enabled in that project and the key has no API restrictions, but that is the unsafe setup. Create a separate key restricted to the Custom Search API.
Why does my new key return 403?
Most often the API is not enabled in the key's project, or a restriction blocks the call. For a project that never used the API, the cause can also be that Google no longer takes new customers.
Sources
Checked on 9 November 2026 from each vendor's own pages. Prices and limits change; follow the links before you decide.
- https://developers.google.com/custom-search/v1/overview
- https://developers.google.com/custom-search/v1/introduction
- https://developers.google.com/custom-search/v1/using_rest
- https://developers.google.com/custom-search/v1/reference/rest/v1/cse/list
- https://support.google.com/programmable-search/answer/12499034?hl=en
- https://programmablesearchengine.googleblog.com/2026/01/updates-to-our-web-search-products.html
- https://cloud.google.com/docs/authentication/api-keys
- https://cloud.google.com/apis/docs/system-parameters
- https://google.aip.dev/193
100 free credits, no card. Credits never expire.
Get API key