What is API key revocation?
An API key is a secret that proves a request is allowed. As long as it is valid, anyone who holds it can use it, whether that is the intended application, a learner who copied it, an agent that read it from a config file, or an attacker who found it in a public repository. Revocation ends that. Once the issuing service marks the key as revoked, every subsequent request using it fails.
Revocation is one of three ways a key stops working. It can expire at a time set when it was created, it can be rotated by replacing it with a new key, or it can be revoked on demand. Revocation is the emergency brake and the cleanup tool: it is what you use when a key may be compromised or simply should not exist any more.
Revocation is especially relevant for AI provider keys. A model key does not just grant access to data; it spends money with every request, and an agent or script using it can keep running unattended. A key left active after a lab or demo is both a security exposure and an open line of credit on your provider account.
How painful revocation is depends on how keys were issued. Revoking a single key shared across a team, a product and fifty lab templates breaks all of them at once. Revoking a key issued to one person for one session affects only that session.
Why API key revocation matters
API key revocation matters because a leaked or forgotten key keeps working until someone stops it.
- Limits damage from leaks: Revoking quickly reduces the window in which a stolen key can be abused.
- Stops runaway spend: For AI providers, an active key can keep consuming budget, so revocation is also a cost control.
- Enforces offboarding: Access ends when a contractor, learner or prospect no longer needs it.
- Supports audits: A clear record of issued and revoked keys shows that access was managed deliberately.
- Keeps environments clean: Keys tied to finished labs or POCs do not linger as forgotten liabilities.
- Answers security questionnaires: Enterprise buyers increasingly ask how credentials in customer-facing environments are issued and withdrawn.
How API key revocation works
Revocation involves a decision, an action at the issuer, and handling the consequences.
Trigger
Revocation is triggered manually, for example after a key is spotted in a screenshot, or automatically, for example when an environment is destroyed or a secret scanner detects a key in a public code repository.
Invalidation at the issuer
The service that issued the key marks it invalid, so validation fails on the next request. Where a gateway or proxy issues virtual API keys on top of a provider key, the gateway can revoke an individual virtual key without touching the provider key behind it.
Propagation
Some systems cache key validity, so revocation may take a short time to apply everywhere. Check how quickly your providers enforce it, and confirm the result by watching for rejected requests rather than assuming the change took effect.
Review
After revoking a key in response to an incident, review usage logs for the period it was exposed. Look for requests from unfamiliar locations, unexpected models or unusual volumes, and record what was found. For keys retired routinely at the end of a session, the review is simply confirming the key is gone and its usage has been attributed.
Reissue if needed
If the user should keep access, a new key is issued and delivered, ideally through automated credential injection rather than manual handoff.
API key revocation vs rotation vs expiry
Revocation, rotation and expiry all end a key's life, but they serve different purposes.
- Revocation: Ends a key immediately on demand, typically after a leak or when access should stop.
- Rotation: Replaces a key with a new one on a schedule or after an incident, keeping access continuous.
- Expiry: Ends a key automatically at a time set in advance, with no action needed.
- Combined use: Short-lived ephemeral API keys rely on expiry by default and on revocation as a backstop.
Common use cases
- Leaked key response: A key committed to a repository or shown on screen is revoked and replaced.
- End of a training session: Keys issued to learners are revoked when the lab is torn down.
- End of a POC: A prospect's evaluation key stops working when the evaluation closes.
- Abuse or overspend: A key showing unexpected usage is revoked to stop further cost.
- Personnel changes: Keys tied to departed staff or contractors are removed.
Best practices
- Issue one key per person, application or session so revocation is targeted.
- Never share a primary provider key; revoking it is disruptive and slow to recover from.
- Tie key lifetime to the environment or task, so most keys expire without manual action.
- Keep an inventory of who holds which key and why.
- Rehearse the response to a leaked key before it happens.
How Heropa helps
Heropa ties AI key lifecycle to the lab lifecycle. With AI Lab Keys, each user receives a virtual key minted for their environment, and you can revoke or reissue keys per environment or per user. Keys expire with the environment, and the provider key they came from remains untouched, so revoking a lab key never disrupts your other labs or applications.
AI Lab Keys run on the same credential management Heropa customers use for cloud accounts and other external systems, with isolated credentials per session and automatic revocation on teardown. Read more in how to put AI in virtual labs without sharing your API key.
Frequently asked questions
What should I do if an API key is leaked?
Revoke it immediately at the issuing service, issue a replacement to legitimate users, check usage logs for unexpected activity during the exposure window, and remove the key from wherever it leaked, such as a repository or document. Then review why it was exposed.
Is revoking an API key the same as deleting it?
In practice they usually have the same effect: the key stops working. Some services keep a revoked key's record for auditing, while deletion removes it entirely. What matters is that requests using the key are rejected.
Why does revoking a shared API key break everything?
Every application, script and lab that uses the shared key loses access at the same moment, so they all need a new key at once. Issuing separate keys per user or session avoids this, because revoking one leaves the others working.
Can I revoke a learner's AI key without ending their lab?
With per-user virtual keys, yes. Revoking one key stops that learner's AI calls while the lab environment keeps running. A replacement key can be reissued if they should continue, without affecting other learners.