Key RobotStart free

How to rotate API keys without breaking your app

Updated October 2026

Rotating a key safely means the new one works everywhere the old one did, before the old one dies. Flip that order and something breaks, usually a few days later when nobody remembers which key is which.

The order that actually works

  1. Make the new key. Name it something you will recognize in six months, not "key2."
  2. Put the new key everywhere the old one lived. Every server, every CI job, every teammate's local setup.
  3. Test with only the new key. Confirm the app works before the old key goes anywhere.
  4. Watch for a few days. Check the provider's usage logs for the old key. Zero traffic on it means every copy got updated.
  5. Kill the old key. Not before step 4. The whole point of waiting is catching a copy you missed while it still has a safety net.

Most manual rotations skip straight from step 2 to step 5, and that is the mistake. The new key existing is not the same as every place that needed it actually using it yet.

Why most providers let you hold two keys at once

Stripe's API key docs describe keeping both the old and new key active during a swap so nothing calling the old one goes down mid-rotation. AWS gives IAM users the same room on purpose. AWS's own guide to updating access keys says a user "can have a maximum of two access keys" and walks through creating the second one while the first stays live, checking its last-used date, then deactivating it before deleting it days later. That gap between deactivate and delete is the safety net. Two valid keys running at once is the design, not a shortcut.

What breaks when you skip the overlap

Not every provider gives you that overlap window for free. Neon's own docs say resetting a database role's password "takes effect immediately," with the old password dead on the next connection. There is no grace period there, so the overlap has to come from somewhere else, like holding two roles and switching between them instead of resetting one in place. See how to rotate a Neon password for the exact steps.

Where people actually lose track of a copy

The old key usually survives in one of four places nobody checked:

Grep your codebase for the old key's prefix before you call the rotation done. If you cannot find every copy with confidence, that is not a sign you need to try harder. It is the actual argument for rotating on a schedule instead of hunting for copies by hand each time.

Doing this on a schedule instead of once

A key rotated once, carefully, is safe until the day everyone forgets to do it again. That day arrives faster than anyone plans for. Key Robot runs the same order above automatically, from your own GitHub Actions, on a schedule (weekly by default, daily on Vercel). It makes the new key, checks your app still works with it, and only then deletes the old one. If the check fails, it puts the old key back on its own, so a bad rotation never takes your app down waiting for someone to notice. The one exception is Turso, which cannot bring an old token back, so there the robot keeps the new token and tells you.

On October 24, 2026, we ran this on our own demo app with two keys at once, Neon and Resend. The robot replaced both, checked the app, and confirmed both old keys dead in 27.7 seconds of robot time, the same order every time, with no step skipped because someone was in a hurry.

Keys are locked in your browser before anything is sent, and saved as encrypted GitHub Actions secrets in your own GitHub account. Key Robot's own server only ever sees names, dates and results. Today this covers 16 services, including OpenAI, AWS, Stripe webhooks, Neon and Supabase, for apps on Netlify, Vercel, Render, Railway or Cloudflare Workers. Free for one app, no card.

If a key has already leaked, do not start with these steps. Go straight to what to do when you leak an API key first, then come back here for the rotation itself.

Questions

What is the single biggest mistake when rotating an API key?

Killing the old key before every place it lives has the new one. The new key existing is not the same as every server, function and teammate's machine actually using it yet.

Should I rotate the old key or just add a new one?

Add the new one first, test with it, then remove the old one. Two valid keys at once is the safe middle step most manual rotations skip.

How do I know every copy of the old key is gone?

Grep your codebase for the old key's prefix, check CI secrets, hosting environment variables and any local .env files, then watch the provider's usage logs for a few days to confirm the old key sees zero traffic before you delete it.