error object that identifies the problem. Start there before reaching for this guide. The sections below walk you through the most frequent issues developers encounter, explain what triggers them, and give you exact steps to resolve them.
Reading the error response
Every error response follows the same shape:error.code (the HTTP status), error.errors[0].reason (the machine-readable cause), and error.message (the human-readable description). All three are needed to narrow down the issue.
400 Bad Request — Missing or invalid parameter
What causes it
A400 response means the API could not parse or validate your request. The most common triggers are:
- Missing
q— Every request must include a non-emptyqparameter. - Missing
cx— Every request must include a valid Search Engine ID. - Invalid
numvalue —nummust be an integer between 1 and 10. - Invalid
startvalue —startmust be between 1 and 91. - Malformed URL — Special characters in
qmust be percent-encoded.
How to fix it
Confirm q and cx are present
q and cx appear as query parameters. A minimal valid request looks like this:URL-encode your query
+ or %20 and encode special characters. Most HTTP client libraries handle this automatically if you pass q as a named parameter rather than concatenating strings manually.Validate numeric parameters
num is between 1–10 and start is between 1–91. Values outside these ranges produce a 400.Inspect the error message
error.message field usually names the offending parameter. For example: "Invalid value for: num must be between 1 and 10".401 Unauthorized — API key invalid or missing
What causes it
A401 means the API rejected your authentication credentials. Typical causes:
- The
keyparameter is absent from the request. - The API key was deleted or regenerated in the Cloud Console and the old value is still in use.
- The key belongs to a different Google Cloud project than the one with the Custom Search API enabled.
- The key was copy-pasted with leading or trailing whitespace.
How to fix it
Check that key is in the request
key query parameter is present on every request. The API does not accept keys passed in headers.Verify the key in the Cloud Console
Check the key's project
Copy the key again
403 Forbidden — Quota exceeded or key restriction
What causes it
A403 response covers several distinct situations. Check error.errors[0].reason to distinguish them:
- rateLimitExceeded
- billingNotProjected
- keyInvalid / accessNotConfigured
- requests from this referer are blocked
- Wait until midnight Pacific Time for the quota to reset.
- Enable billing on your Cloud project to raise the limit to 10,000 queries/day.
- Add caching to your application so repeated identical queries don’t consume quota. See Rate Limits and Quotas for detailed strategies.
429 Too Many Requests — Rate limit exceeded
What causes it
A429 differs from a 403 rateLimitExceeded in that it indicates you’ve exceeded a per-second or per-minute throughput limit rather than the daily quota. The Custom Search API enforces a burst limit to prevent sudden spikes from degrading service for all users.
How to fix it
Implement exponential backoff
429, wait and retry with increasing delays. Start with a 1-second delay, then 2 s, 4 s, 8 s, and so on, with a small random jitter to avoid thundering-herd effects.Spread requests over time
Check for runaway loops
Empty results — No items returned
What causes it
A successful200 response can still contain no results (items is absent or empty). This happens when:
- The search engine scope is too narrow — Your Programmable Search Engine is scoped to specific sites that don’t contain pages matching the query.
- The query is over-constrained — A combination of
exactTerms,excludeTerms,fileType, andsiteSearchleaves no matching documents. - The
startvalue is too high — Google typically returns far fewer than 100 results for many queries; ifstart=81yields no items, the result set is simply exhausted. - SafeSearch is filtering aggressively — For certain queries,
safe=activeremoves all results.
How to fix it
Test the query in the Control Panel
Check your engine's site scope
Simplify the query
exactTerms, fileType, dateRestrict) to identify which constraint is eliminating all results.Check the totalResults field
items is empty, searchInformation.totalResults tells you how many results Google found in total. A value of "0" confirms no matches exist; a non-zero value suggests the start offset exceeds what Google will return.Try safe=off
safe=off to see if results appear. Then decide whether to adjust your engine’s SafeSearch settings.Unexpected results — Wrong pages appearing
What causes it
Your results include pages from sites you didn’t intend, are missing results from sites you expected, or the ranking seems wrong. Common causes:siteSearchmisconfigured — PassingsiteSearchFilter=e(exclude) instead ofi(include), or vice versa.- Engine scope overrides the
siteSearchparameter — If your engine is already restricted to specific sites, asiteSearchthat tries to include a different site may return nothing. - Wrong
cxvalue — The request is targeting a different engine than intended. orTermsbroadening results unexpectedly —orTermsadds alternative terms to the query withORlogic, which can surface unrelated pages.
How to fix it
Confirm the cx value
cx value your application is sending. Copy it and paste it into the Programmable Search Engine control panel to confirm it maps to the engine you expect.Verify siteSearchFilter direction
Remove orTerms temporarily
orTerms, try removing it and see whether results become more focused. orTerms operates as a union and can significantly widen the result set.Review engine boosted/buried sites
Quick-reference error table
500 errors during incidents. Before spending time debugging your code, check the Google Cloud Status Dashboard to rule out a platform-wide issue.