News · Learn · November 19, 2026
How to rotate an AI API key without downtime
Swap an AI provider key in eight steps: make the new one first, move the apps over, then revoke the old one. A routine you can run in an afternoon.
DRIVE 369 DAO · 4 min read
To rotate an AI API key without downtime, create the new key first, move every app to it, check that calls succeed, and only then revoke the old one. It takes eight steps and an afternoon the first time. Providers recommend doing it on a schedule: Anthropic's key-safety guide, last updated 19 October 2026, says to rotate on a fixed schedule such as every 90 days, by creating new keys and deactivating old ones. Do it at once if a key may have leaked, such as after a gateway flaw like the LiteLLM one.
What the provider says
| Advice | Anthropic's guide (19 Oct 2026) | Our reading |
|---|---|---|
| Rotate on a schedule | Rotate keys on a fixed schedule, such as every 90 days, by creating new keys and deactivating old ones | A calendar reminder beats remembering |
| Separate keys | Use distinct keys for development, testing and production, so you can track usage by use case and disable only the affected one | One key per app and environment makes a leak a small job |
| Keep keys out of code | Load keys through environment variables or a cloud secret manager, and keep dotenv files out of version control | Never in a repository, a ticket or an email |
| Limit the damage | Set spend limits and rate limits; the guide calls them a safeguard against unexpected usage from leaked keys or errant scripts | A cap turns a bad night into a small bill |
| Watch usage | Review the Logs and Usage pages regularly | A sudden jump is the first sign |
| Scan for secrets | Turn on secret scanning in your source control and CI; GitHub scans public repositories for exposed Claude keys and Anthropic deactivates a key it finds | Scanning catches the mistake after it happens, not before |
| If you suspect a leak | Revoke the key at once in the Console | Rotate first, investigate second |
These are one provider's published recommendations. Other providers have their own consoles and names for the same steps; check yours. The eight steps below are our own routine, built on this advice.
The routine
- List where the key lives. Write down every app, script, CI job, gateway and teammate that uses it. If you cannot list them, that is the finding: the next key will be one per use.
- Create the new key, named for its job and environment, with the narrowest permissions your provider offers. Do not revoke anything yet.
- Store it properly. Put it in your secret manager or deployment secrets, not in a file in the repository and not in a chat. If a person has to receive it, send it as a link that opens once, not as a pasted message.
- Move one low-risk app first. Swap the key, deploy, and check that calls succeed and usage shows up under the new key.
- Move the rest, one at a time, in order of risk, lowest first. Both keys keep working during this, so nothing goes down.
- Watch the old key. When its usage drops to zero and stays there for a day, nothing still depends on it. Anything still using it will show up here.
- Revoke the old key. Delete or deactivate it in the console. If your provider offers deactivate and delete, deactivate first, wait, then delete.
- Write it down. Record the date, what moved and the next rotation date, so the schedule survives people leaving.
How to check it worked
- The provider's usage page shows traffic on the new key and none on the old one.
- A call made with the old key now fails with an authentication error. Test it once on purpose.
- Your monitoring shows no new errors in the hour after revoking.
- The old key is gone from every secret store and chat where it was shared.
If it goes wrong
If an app breaks after you revoke, you have found a place that held the key. Create another new key, fix that app and note it in step 1. If you rotated because of a leak, treat the old key as already stolen: look at the provider's usage and billing for spend you did not make, and set a spend limit before anything else.
Where Ghostdrive stands
Ghostdrive does not manage your provider keys for you and cannot see how your apps use them. Pass can keep a key as a sealed item on your device, and Send and Guard can send a new key to a colleague as a link that opens once and warn you before a key is pasted into an AI chat. Guard catches keys with a known shape, not everything. Neither replaces the routine above.
Limits
We checked Anthropic's published guide and wrote the routine ourselves. We could not read OpenAI's key-safety page from our tools, so we do not quote it; read your own provider's pages for exact button names, permissions and whether a deactivated key can be turned back on.
Academy: where AI keys should live · Ten guardrails every AI agent needs · LiteLLM: a fourth CISA-listed flaw in 2026
Questions
- How often should I rotate an AI API key?
- Anthropic suggests a fixed schedule, for example every 90 days, by creating new keys and deactivating old ones. Rotate at once if a key may have leaked, or if a tool that held it was reported as breached.
- Why create the new key before revoking the old one?
- So nothing breaks. Both keys work while you move each app over, you check that calls succeed on the new one, and only then do you revoke the old one. Revoking first means an outage.
- What if I cannot tell where a key is used?
- Revoke it on purpose, in a quiet hour, and watch what fails. The failures are your list of places that held it. This is why separate keys per app and per environment make rotation easy.