← Glossary

What Is an API Key?

An API key is a credential string issued by an API provider that a client sends with each request so the provider can identify the calling application or project, apply quotas and decide whether to serve the call.

Updated:

An API key is a credential string that an API provider issues to a client and that the client sends with each request. The provider uses it to identify the calling application or project, enforce quotas, attribute usage for billing and decide whether to serve the call. API keys usually support software access: an app, script, account or project registered with the service. The exact identity and permissions behind a key depend on the provider.

Most keys used for privileged server access are secrets. Some providers also issue publishable keys deliberately intended for client-side code, with limited capabilities. Possessing a valid key proves that the request comes from someone who holds that key, nothing more. Whether a key also carries authorization depends on the provider's design, and many systems combine API keys with a separate authorization model. The sections below cover how an API authentication key moves through a request, how permissions, storage and rotation are managed, and how keys differ from passwords and OAuth tokens.

How an API Key Is Used

The lifecycle begins in the provider's console or management API, where a developer creates a key for a project. The key commonly includes an unpredictable value; the provider stores a record or verification data linking it to the relevant account or project, permissions and creation date. The developer then places the key in the application's configuration.

On each request, the client includes the key. Providers accept it in different places: a dedicated header such as x-goog-api-key, the Authorization header, or a query parameter. The OWASP REST Security Cheat Sheet advises against the query form, because URLs are captured in server logs, proxies and browser history, and recommends headers instead. The server looks the key up, checks that it is active and permitted for the requested API, applies the project's quota and processes the call. When a client exceeds its allowance, the usual response is HTTP 429.

This flow gives the provider two things: attribution and control. Attribution means an accepted call can be tied to a registered credential, which supports metering and abuse investigation. Control means the provider can throttle, restrict or disable one project without affecting others. OWASP notes that keys issued to third-party clients are relatively easy to compromise, so they protect against accidental overuse better than against a determined attacker.

Permissions, Storage and Rotation

Restricting What a Key Can Do

An unrestricted key can grant substantially more access than an integration needs, subject to the provider's own rules. Google's documentation describes two kinds of limits: API restrictions, which name the services a key may call, and application restrictions, which limit the websites, IP addresses or mobile apps that may present it. Google states that unrestricted keys are insecure and recommends setting both kinds. The underlying principle is least privilege: a key created for a geocoding feature should not be able to reach a billing API.

Storing API Credentials

Secret API credentials belong outside published source code and client bundles. A common architecture has the browser call the developer's server, which adds a server-side key. Publishable keys are a separate category: Stripe, for example, allows its limited publishable key in client code while reserving privileged keys for servers. The OWASP Secrets Management Cheat Sheet recommends a dedicated secrets store, warns that environment variables can be exposed through child processes, diagnostic access, logs or crash dumps, and recommends scanning repositories and commits for leaked secrets. Each application and team member should ideally hold a separate key, so a leak can be traced and revoked without disrupting everyone.

Key Rotation and Revocation

Key rotation replaces a working key on a schedule: create a new key, update every consumer, verify that traffic has moved, then delete the old one. Rotation shortens the window in which a copied key remains useful. Revocation is the emergency form. OWASP's incident guidance is to revoke the exposed key immediately, then rotate and remove the exposed copies from code and logs. Restarting an application does not invalidate a stolen credential; revocation or expiry must take effect at the provider. Usage monitoring, such as alerts on calls from unexpected IP ranges or user agents, can reveal a leak before a scheduled rotation would.

API Keys vs Passwords and OAuth Tokens

Three credential types are often confused because all three are strings sent with requests.

AspectAPI keyPasswordOAuth 2.0 access token
RepresentsAn application, account or projectAn account, often human-operatedA delegated grant from a user or service to a client
LifetimeProvider-defined; may expire or need rotationUntil changedOften short-lived; issuer-defined
How obtainedCreated in a developer consoleChosen by the userIssued by an authorization server through a supported grant
ScopeProvider-defined restrictionsSubject to account permissions and other checksScopes and audience embedded in the grant

RFC 6750 describes how OAuth bearer tokens travel, recommending the Authorization header and discouraging query parameters for the same logging reasons that apply to keys. The important difference is provenance. An API token in the OAuth sense exists because a user, or a service account acting as a principal, authorized a specific client for specific scopes, and the resource server can verify audience and expiry. API keys are commonly provisioned directly rather than through an OAuth grant. Google's standard key identifies a project without authenticating a principal; another provider can bind a key to an account with substantial permissions. Neither behavior defines all API keys.

Typical Use Cases

API keys fit many software integrations, from usage metering to privileged server operations. Public data services such as maps, weather or translation use them to track usage per project. Automation and scraping pipelines use keys to call the APIs of proxy providers, cloud browsers, CAPTCHA services or storage back ends, with the key kept on the server that orchestrates the jobs. Server-to-server integrations use keys when the user context is irrelevant. For actions that depend on who the end user is, providers typically require OAuth or a signed session alongside the key.

Limitations

An API key does not prove which person is currently operating the software. Even a key associated with a named account can be copied or shared. A secret key copied from a public repository, mobile app binary or browser bundle must be treated as exposed. Application restrictions reduce misuse but can be bypassed, and Google warns that mobile app restrictions in particular should be combined with API restrictions and monitoring. OWASP advises against relying exclusively on API keys to protect sensitive, critical or high-value resources. Keys also provide no non-repudiation: if several developers share one key, logs cannot show who made a call. Review the permissions behind each key rather than assuming it is only an identifier. Some keys can read data, change resources or trigger billable operations, so a leak can carry the authority of the entire integration.

Frequently asked questions

Can an API key identify a user?

Some providers bind keys to individual accounts; others identify only a project or application. Even an account-specific key proves possession of that credential, not which person is using it at that moment. Shared or stolen keys therefore weaken attribution unless the service applies additional checks.

Should a key appear in a public URL?

A secret key should not be placed in a public URL: query strings can reach logs, history and copied links. Use the provider's documented authentication header over HTTPS. Publishable client keys are different, but should still be limited to their intended operations and configured according to the provider's restrictions.

How is a compromised key revoked?

Disable or delete it through the provider's console or management API, then check when revocation takes effect. Replace affected integrations and remove exposed copies from code and logs. A provider may cache credentials or offer delayed expiry, so verify that the old key is actually rejected; restarting your app is insufficient.

Is an API key the same as an API token?

Providers use these labels differently. OAuth access tokens are issued through an authorization flow and carry provider-defined access rights and lifetimes. API keys are commonly provisioned directly, but can also have scopes or expiry. Read the service's documentation rather than inferring permissions or security from the name.

How often should API keys be rotated?

There is no universal interval. Choose a lifecycle based on permissions, exposure and the provider's features, and automate replacement where practical. Suspected compromise calls for prompt revocation and replacement. A secret embedded in distributed software needs an architectural fix as well; regularly issuing another extractable secret does not solve the exposure.