Skip to main content
The Google API uses API key authentication to verify your identity and authorize access to resources on your behalf. Every request you make must include a valid API key passed as a Bearer token in the Authorization header. API keys are tied to specific scopes that control which operations they can perform, giving you fine-grained control over what each integration is permitted to do. Before you can make your first request, you need to generate a key from your account settings — a process that takes under a minute and only needs to be done once per integration.
Never commit API keys to source control. Even in private repositories, exposed keys are a security risk. Always load your keys from environment variables or a dedicated secrets manager such as AWS Secrets Manager, HashiCorp Vault, or your CI/CD platform’s secret store.

Generate an API Key

You can create as many API keys as you need — one per application, environment, or integration is a recommended practice. Follow the steps below to generate your first key.
1

Open API Key Settings

Log in to your Google account and navigate to Settings → API Keys in the left-hand sidebar. This page lists all active keys associated with your account along with their creation date, last-used timestamp, and assigned scopes.
2

Create a New Key

Click New Key to open the key creation dialog. Give your key a descriptive name (for example, production-search-service or dev-local) so you can identify it later. Then select the scopes this key requires — choose only the scopes your integration actually needs to follow the principle of least privilege. Available scopes are read, write, and admin.
3

Copy Your Key Immediately

After clicking Create, your full API key is displayed exactly once. Copy it to your clipboard right away — once you close or navigate away from this dialog, the key value is no longer retrievable and you will need to generate a new one if you lose it.
4

Store the Key Securely

Paste your key into your application’s environment configuration. In local development, use a .env file (and ensure .env is listed in your .gitignore). In production, use your platform’s secret management tooling. Never hardcode the key value directly in your source code.

Using Your API Key

Pass your API key as a Bearer token in the Authorization header of every request. The header value must follow this exact format:
The example below demonstrates a basic authenticated search request using cURL:
You can use the same pattern in any HTTP client or language. The code samples below show equivalent implementations in Python and JavaScript:
Create separate API keys for each environment — development, staging, and production. This makes it easy to rotate or revoke a compromised key in one environment without disrupting others, and lets you apply different scope restrictions per environment (for example, a read-only key for staging).

API Key Scopes

When you create an API key, you assign it one or more scopes that determine which API operations it is permitted to perform. Requests made with a key that lacks the required scope for an operation will receive a 403 Forbidden response.
The write scope implicitly includes all read permissions. Similarly, admin encompasses both read and write. You only need to select the highest scope your integration requires — there is no need to add lower scopes separately.

Authentication Errors

If authentication fails, the API returns one of two status codes depending on the nature of the problem. Understanding the distinction helps you diagnose issues quickly.

401 Unauthorized

Your request is missing an Authorization header, the header is malformed, or the API key value is invalid (for example, it was deleted or never existed). Double-check that the header is formatted as Bearer YOUR_API_KEY and that the key value matches what was generated in your settings.

403 Forbidden

Your API key is valid and recognized, but it does not have the scope required to perform the requested operation. Review the scopes assigned to your key in Settings → API Keys and regenerate the key with the correct scopes if needed.
Both error responses follow the standard error envelope described in the API Overview: