Skip to main content
When the Custom Search JSON API cannot fulfill a request, it returns an HTTP status code in the 4xx or 5xx range and a structured JSON error body. Parse the error.code and error.status fields to identify the problem programmatically and surface a meaningful message to your users or alerting system.

Error Response Structure

Every error — regardless of status code — follows the same envelope format. Familiarize yourself with this shape before reading the per-code reference below.

Error Response Schema

object
required
Top-level error container. Always present when the HTTP status code is not 2xx.

Quick Reference


Error Code Details

400 Bad Request

A 400 means the request was structurally invalid before Google attempted to process it. The most common causes are a missing required parameter (key, cx, or q), a parameter value that falls outside the accepted range, or conflicting parameter combinations.error.status: INVALID_ARGUMENT

Example — Missing q parameter

Example — start value out of range

How to resolve

  1. Check that key, cx, and q are all present in the request.
  2. Verify that num is between 1 and 10 and that start is between 1 and 91.
  3. Ensure searchType, safe, imgSize, imgType, and other enum parameters use only documented values.
  4. URL-encode the q value — unencoded special characters can truncate or corrupt the query string.

401 Unauthorized

A 401 means the API key provided is not recognized by Google. This occurs when the key has been deleted, was never created, or contains a typo.error.status: UNAUTHENTICATED

Example — Invalid API key

Example — No key supplied

How to resolve

  1. Confirm the key query parameter is present and spelled correctly (key, not apiKey or api_key).
  2. Open Google Cloud Console → Credentials and verify the key exists and is not disabled.
  3. If you recently deleted the key, create a new one and update all references.
  4. Make sure you are not accidentally passing a different project’s key or a service account key (which is not valid here).
A 401 always means the key itself is unrecognized. If the key exists but lacks permission, the API returns 403 instead.

403 Forbidden

A 403 covers two distinct scenarios: permission problems (the key exists but is not allowed to make this call) and quota exhaustion (the key is valid but has hit a usage limit). Distinguish between them using error.status.

Scenario A — Permission denied

error.status: PERMISSION_DENIEDCommon causes: the Custom Search API is not enabled in the project, an API restriction blocks this API, or an application restriction blocks the caller’s IP/referrer/app.
How to resolve:
  1. Enable the Custom Search API for your project at console.developers.google.com/apis/api/customsearch.googleapis.com.
  2. If you have API restrictions on the key, ensure Custom Search API is in the allowlist.
  3. If you have IP or referrer restrictions, confirm the request originates from an allowed source.
  4. Wait up to 5 minutes after making changes for them to propagate.

Scenario B — Quota exhausted

error.status: RESOURCE_EXHAUSTEDThe project has consumed its daily or per-minute query budget.
How to resolve:
  1. The free tier provides 100 queries/day per project. If you need more, enable billing and purchase additional query capacity (up to 10,000 queries/day per project).
  2. Check your current usage at Cloud Console → APIs & Services → Quotas.
  3. Implement client-side caching to reduce duplicate queries.
  4. Distribute load across multiple projects (each has its own free tier quota) if your use case permits.
Quota resets daily at midnight Pacific Time. Design your application to gracefully degrade — return cached results or a friendly “search unavailable” message — rather than surfacing a raw 403 to end users.

404 Not Found

A 404 typically means the Search Engine ID (cx) you supplied does not exist, has been deleted, or belongs to a different Google account.error.status: NOT_FOUND

Example

How to resolve

  1. Log into programmablesearchengine.google.com and confirm the Search Engine ID shown in Setup → Basics → Search engine ID matches the cx value you are passing.
  2. Search Engine IDs are case-sensitive. Copy-paste the value rather than typing it manually.
  3. If you are using a cx created by another user, ensure they have shared it with your account.
  4. If you deleted the search engine, create a new one and update your configuration.

429 Too Many Requests

A 429 means you have exceeded the per-second or per-minute request rate limit, separate from the daily quota. This is a transient error — slow down and retry.error.status: RESOURCE_EXHAUSTED

Example

How to resolve

Implement truncated exponential backoff:
  1. After the first 429, wait 1 second and retry.
  2. After each subsequent failure, double the wait time (1 s → 2 s → 4 s → 8 s …).
  3. Add a small random jitter (e.g., ±500 ms) to prevent retry storms when many clients hit the limit simultaneously.
  4. Cap the maximum wait at 32–64 seconds.
  5. After 5–7 retries without success, surface an error to the user rather than retrying indefinitely.
If you regularly hit 429 errors, consider batching queries, caching results for repeated searches, or distributing load over multiple projects.

500 Internal Server Error

A 500 indicates a transient problem on Google’s infrastructure. The request was valid — the error is not caused by anything in your code. Retry with backoff.error.status: INTERNAL

Example

How to resolve

  1. Retry the identical request after a short delay (start with 2 seconds).
  2. Use the same exponential backoff strategy as for 429 errors.
  3. If 500 errors persist for more than a few minutes, check the Google Cloud Status Dashboard for an active incident affecting the Custom Search API.
  4. Log the full error body and the request parameters (excluding the API key) so you can file a support ticket if needed.
A 500 does not count against your daily quota. You will not be charged for requests that return 500.

Structure your error handling to branch on HTTP status code first, then on error.status for cases where a single status code covers multiple distinct problems (such as 403).

API Overview

Base URL, required parameters, and response shape for the Custom Search JSON API.

Authentication

How to create, pass, restrict, and rotate API keys. Includes credential error examples.