Leaked an API Key? What to Do in the First Hour (Rotate, Check, Fix)

A step-by-step plan for when an OpenAI, Stripe, AWS, Supabase, or GitHub key leaks: revoke and rotate it, check for misuse, clean up git history, and stop it happening again.

Updated 2026-11-04

Rotate first, clean up second

Once a key has been in public code, a public repo, or a public file, assume someone has a copy. Deleting it from your code does not take it back. The only fix that works is to make the old key stop working.

Rotating means creating a new key, putting it where your server reads it, and revoking the old one. Do it in that order so your app is down for as little time as possible.

Where to rotate common keys

Dashboard menus change, but these are the places to look. If you are not sure, search the provider's docs for "rotate API key".

  • OpenAI and Anthropic: the API keys page in the platform console. Create a new key, then delete the leaked one.
  • Stripe: Developers, then API keys. Roll the secret or restricted key. Publishable keys are meant to be public.
  • AWS: IAM, then the user's security credentials. Create a new access key, then deactivate and delete the old one.
  • Supabase: the project's API settings. Rotate the service_role or secret key. The anon or publishable key is meant to be public.
  • GitHub, Slack, SendGrid: revoke the token in the account or app settings and create a new one.

Check for misuse

  • Look at the provider's usage and billing pages for calls or charges you did not make.
  • For AWS, review CloudTrail and look for new users, keys, or servers you did not create.
  • For Stripe, look for refunds, payouts, or customers you did not create.
  • Set spend limits or budget alerts where the provider offers them.

Clean up the code and the history

Move the key into a server-only environment variable and call the provider from your server, never from browser code. If the key was committed to git, it is still in the history even after you delete it. Rotating already made that copy useless; rewriting history (for example with git filter-repo) is optional cleanup, not a fix.

A prompt you can paste into your coding agent

After you have rotated the key, paste this into Cursor, Lovable, or Claude:

A secret key leaked from this app and has been rotated. Find every place the old key or its environment variable is used. Make sure the key is only read on the server from a server-only environment variable (no NEXT_PUBLIC_ or VITE_ prefix), that browser code calls our own API route instead of the provider, and that .env files are in .gitignore.

Check your live app for free

After you redeploy, run Freedom Check's free scan on the live site to confirm the leaked key pattern is gone from the page and the scripts it loads. It looks for OpenAI, Anthropic, Stripe, AWS, GitHub, Slack, and SendGrid key patterns, private keys, and Supabase service_role keys, and redacts evidence in the report. It cannot see your git history or tell whether a key was already used.

The free scan shows how many issues turned up and explains the most serious one with a fix prompt. The full report is $19 one time, or $29/month for unlimited.

Run a free scan →See pricing