What should I do if my API key leaked?

Make a new key and turn the old one off now, then check its usage, move the new one to a server, and find out how it leaked.

An API key is a long password your app uses to prove who it is to another service. If it leaked, revoke and replace it at the provider. GitHub says to rotate an affected credential immediately, and notes that scrubbing Git history (the saved record of every change to your code) is often unnecessary once the key is revoked.

Then check the provider's request logs for activity you do not recognise, put the new key in server-side secrets (a hidden store where visitors cannot look) without a VITE_ or NEXT_PUBLIC_ prefix, and search your project for other exposed keys. Those prefixes copy a setting into the code every visitor downloads.

Write down what you did and when, so you can answer questions from the provider or your users later.

Sources

Each source below was read on 2026-11-16. Documentation changes over time, so check the source for the current wording.

  • GitHub documentation, About secret scanning, accessed 2026-11-16
  • Stripe documentation, API keys, accessed 2026-11-16