What is API Key?
Updated: Oct 28

An API key is a value supplied with a request to an application programming interface (API). The service uses it to recognise an application, project or account and apply its configured rules. Depending on the provider, the key may identify usage, act as a credential, or form one part of a wider access control system.
An API key is often a long string created in a provider's dashboard. If it grants access or incurs charges, anyone who obtains it may be able to use it. Keep it protected and check exactly what it can do. The label “API key” does not tell you, on its own, whether it identifies a user, proves an application's identity or grants permission to private data.
How an API key works
A weather application, for example, might request forecast data from a provider. The provider issues a key linked to the application's account. When the application makes a request, it includes the key using the method specified by that provider, often an HTTP header. The service checks the key and applicable restrictions before processing the request.
The illustration shows a simplified API key request: an application sends a key, the API checks it, the service applies its configured permissions, and the owner protects and monitors the key.

Create a key in the provider's management system and identify its intended application.
Restrict its use where the provider supports suitable restrictions.
Send it with requests over an encrypted HTTPS connection using the provider's documented method.
The API checks the key, account status and applicable rules.
The service allows or rejects the request and records usage according to its configuration.
This is a general model. A particular provider may require a separate access token, signature or other credentials, and a valid key does not guarantee that every request will succeed.
What can an API key be used for?
Use | What the key can help the provider do | Important limitation |
|---|---|---|
Project identification | Associate requests with an application or project | It may not identify the individual user |
Usage measurement | Record activity against an account or plan | Records depend on the provider's logging |
Quotas and rate limits | Apply configured request limits | Limits may not be exact or instantaneous |
Access to a service | Check whether a key is accepted for a particular API | The key's actual permissions depend on the provider |
Billing attribution | Associate chargeable requests with an account | A leaked key can result in unexpected usage or costs |
The API rate limits article explains why providers may restrict request rates. A key can help associate those limits with an application, but it is not automatically a complete security system.
Does an API key authenticate a user?
Not necessarily. A key can identify a project or application without proving which person is making the request. Some services use secret API keys as bearer credentials to authenticate a client or account. Others use a key only for identification, quota or billing and require a separate mechanism to protect sensitive data.
For example, Google Cloud distinguishes standard API keys from authorisation keys: a standard key associates requests with a project, while an authorisation key authenticates as a service account.
A bearer credential can generally be used by whoever possesses it, subject to the provider's restrictions. That is why an exposed key may be dangerous even when it does not contain a username or password. A service should not assume that possession of a shared application key proves the identity of a particular person.
Authentication and authorisation answer different questions. Authentication checks a claimed identity or credential. Authorisation decides whether the resulting request is permitted. The API provider determines which checks apply to its own keys.
For example, Amazon API Gateway's usage plan documentation says its usage plan API keys should not be used as the authentication or authorisation mechanism for controlling access. That is specific guidance for that product, not a claim that every service handles keys in the same way.
API key, OAuth token and client secret
Item | Typical purpose | What to check |
|---|---|---|
API key | Identifies or authenticates a client, project or account, depending on the service | Whether it grants access, its restrictions and how it is sent |
OAuth access token | Represents access granted for a protected resource | Intended API, granted access, expiry and validation rules |
Client secret | Helps a confidential client authenticate to an authorisation server | Whether the application can actually keep a secret |
Session cookie | Maintains an authenticated web session | Cookie security, session lifetime and server-side checks |
OAuth is an authorisation framework that can support limited access on behalf of a user. A long-lived shared API key generally does not provide the same delegated user permissions, consent or token lifecycle. Some services support both, while others offer only one approach.
Where should an API key be stored?
A secret key belongs in a location appropriate to the deployment, such as a managed secrets service or protected server-side configuration. Restrict who and what can read it, and avoid storing it directly in source code or public repositories. Environment variables can be useful for configuration, but they are not automatically safe if process access, logs, crash reports or deployment settings expose their contents.
Never assume that a secret embedded in a browser application or mobile app remains secret. Users can inspect downloaded code or application packages and the requests those applications make. A server-side component can keep a secret away from the user's device, provided the server itself is secured and access is controlled.
Some providers offer publishable or browser-facing keys intended to be visible. Treat them according to that provider's documentation, apply supported restrictions, and do not use a public key where a secret credential is required. Domain or application restrictions can reduce misuse, but their strength and limitations depend on the provider.
Google Cloud's API key security guidance recommends restrictions, separate keys, monitoring and rotation. It also recommends avoiding query parameters for Google APIs because URLs can be exposed in logs and other places. Follow the specific API's current instructions for the correct header or client library.
How to restrict an API key
Start by asking what the application actually needs. Depending on the service, restrictions may include which APIs can be called, which environments or projects can use the key, which operations are allowed, or whether requests originate from specified IP addresses, websites or applications.
Use separate keys for different applications and environments where possible.
Give each key only the permissions and API access required for its purpose.
Apply supported source restrictions and understand how reliably the provider enforces them.
Set suitable usage alerts and review activity for unusual patterns.
Keep a record of the owner, purpose, location and rotation process for each key.
Remove unused keys after confirming that no active application depends on them.
Restrictions reduce the potential impact of misuse, but none should be assumed to be foolproof. A request that carries a valid key may still require additional identity checks and resource-level permissions.
A practical UK example
Imagine a UK support business connecting its customer portal to a third-party status API. This is an illustrative example, not a tested configuration or a claim about a particular provider.
The portal's server holds a dedicated key for the status service. The key is restricted to the required API and, where supported, the server's outgoing IP addresses. The business sets alerts for unexpected use and keeps a separate key for its test environment.
Situation | Intended response | Check |
|---|---|---|
Portal requests an approved status update | Process the request if all checks pass | Key, API access and account rules |
Key is used from an unexpected source | Reject it where the configured restriction applies | Provider enforcement and actual source address |
Usage suddenly increases | Investigate and contain potential misuse | Logs, alerts, application changes and billing |
Engineer leaves the business | Review their access and affected credentials | Account permissions and key ownership |
The API key identifies or authenticates the integration as defined by the provider. The portal still needs its own user authentication and checks before showing one customer's information to another user.
What happens if an API key is exposed?
Treat a potentially exposed secret as compromised. Removing it from a public page or repository does not make copies disappear. Follow the provider's incident process, restrict or revoke the key, create a replacement and update dependent applications. The safest order depends on the potential harm and whether a planned overlap is possible: a key exposed to active abuse may need immediate revocation even if that interrupts the service.
Review provider logs, usage and billing for the relevant period. Investigate how the key was exposed, including source control, deployment files, support tickets and logs. Consider whether additional credentials or data were exposed and follow the organisation's incident response process.
For routine rotation, create and restrict a replacement, update authorised applications, test it and retire the old key according to the provider's instructions. Some providers permit an overlap; others require a different procedure. Check that rollback and monitoring are in place, and never paste a live key into a public troubleshooting request.
Common API key problems
A rejected key may be incorrect, expired, revoked or associated with the wrong environment.
A valid key may lack access to the requested API or operation.
An IP restriction may fail after a deployment changes its outgoing address.
A browser-facing request may be rejected because its configured application restriction does not match.
A quota or rate limit may have been reached, or the account may have a billing issue.
An API may require a separate token or additional permissions even when the key is accepted.
Use the provider's error codes and documentation to identify the failing check. Record non-sensitive request identifiers and timestamps, but redact keys and other credentials from logs and support messages. A key appearing valid does not prove that the user or resource access is authorised.
Key takeaway
An API key connects a request to an application, project or account under a provider's rules. Its security role varies by service. Understand what the key grants, protect any secret value, restrict and monitor its use, and use additional authentication and authorisation where needed.
Frequently asked questions
What is an API key?
An API key is a value sent with an API request so the provider can identify or authenticate an application, project or account and apply its configured rules.
Is an API key the same as a password?
Not exactly. A secret API key can act like a bearer credential, but its purpose, ownership and permissions depend on the service. Protect it as a secret whenever it can grant access or incur charges.
Does an API key identify the user?
Not necessarily. It may identify only an application or project. The provider may require a separate mechanism to authenticate an individual user.
Can I put a secret API key in JavaScript?
Do not rely on browser-delivered JavaScript to keep a secret. Users can inspect the code and network requests. Use a suitable server-side design or a provider's deliberately public, restricted key where appropriate.
What should I do if an API key is leaked?
Follow the provider's incident process, contain or revoke the exposed key, replace it, update affected applications and investigate usage and billing. Deleting it from a page or repository does not invalidate copies already taken. Check where the key was used, remove the exposure, review affected services and verify that the replacement works while the old key is rejected.
Do API keys expire?
Some do and some do not. Expiry and rotation depend on the provider and key configuration, so check the service's documentation and your own policy. A key that remains valid until revoked still needs a deliberate lifecycle. Record its owner and dependencies, use supported restrictions, and test replacement before an expiry or planned rotation disrupts dependent applications.
Does a valid API key grant access to every API?
No. Access depends on the provider, account, API configuration, restrictions and any additional authentication or authorisation checks.

