Leaked an AI API key? What to do in the next 10 minutes
Steps for a leaked AI API key: revoke it, check usage for charges, cap spend and clean up GitHub or your app. For OpenAI, Anthropic, Gemini and 12 more.
Free. Runs in your browser. No sign-up.
What to do now, for OpenAI
Revoke the key now
Delete the key on the API keys page (the bin icon). OpenAI keys can't be rotated in place, so create a new one. Do this first: until it's revoked, anyone who copied it can keep spending. OpenAI disables keys it finds on the public internet, including public GitHub repos.
Keep the new key on the server
Put the new key only in a server-side secret: your host's environment settings, your builder's secrets, or Supabase function secrets. Never in a variable starting NEXT_PUBLIC_, VITE_ or EXPO_PUBLIC_, which are sent to every visitor.
Check usage for charges that weren't yours
The usage page can show one key at a time: Filters, then API keys. Note the time the key leaked and the time you revoked it.
Cap what any key can spend
Set a budget under Limits and switch on “Enforce a hard limit”; without it you only get alerts. Budgets cover a project or the whole organisation, not one key, and take a little while to kick in. Auto-reload is on by default when you first buy credits, so switch it off or give it a monthly limit.
Clean up the repo, after revoking
Remove the key from the code and the git history, but only once it's revoked: anyone who cloned the repo, or a fork, still has it. Then turn on push protection, so GitHub blocks the next key you try to push.
If someone ran up charges, ask for them back
Open a chat from any page of OpenAI's help centre. OpenAI says credits already used can be refunded only for confirmed unauthorised use. Say when the key leaked, when you revoked it and which usage wasn't yours.
Checked in OpenAI's own docs. Sources: account security, usage dashboard, spend limits, help centre article. Dashboards move, so if a link is out of date, look for the same setting under account or organisation settings.
Then find every other copy, with your coding agent
Find every place an API key or other secret is exposed in this project, and fix it. Search the code, env files, config and local settings files (such as .claude/settings.local.json), the full git history (with gitleaks or a similar scanner) and the built browser bundle. Flag any secret in a variable with a public prefix such as NEXT_PUBLIC_, VITE_ or EXPO_PUBLIC_, and any AI provider called from browser code. Move every AI call into a server route or function that reads its key from a server-only variable, add .env and local settings files to .gitignore, and list each key that was exposed and where, so I can revoke it. Don't rewrite git history.
Why minutes count
- Public repos are scanned constantly. Security researchers have watched keys pushed to public GitHub repos get used within five minutes.
- A key in browser code is public from the first visit. Anyone can read it in the developer tools, and every visitor downloads it.
- A prepaid balance isn't a cap if auto-reload is on. OpenAI switches auto-reload on by default when you first buy credits, and OpenRouter warns that a key with no limit can spend your whole balance, top-ups included.
One builder on r/vibecoding found their whole ElevenLabs balance gone, 121,000 credits (ElevenLabs' unit of usage) in a single day, from a key in a committed settings file.
Which providers stop a leaked key for you
GitHub scans public repos for many providers' keys and reports them to the provider, which may disable the key. Some providers only email you, and some aren't scanned at all. Either way, revoke it yourself.
| Provider | Key pushed to public GitHub | Spend cap that stops requests |
|---|---|---|
| OpenAI | Disabled for you | Yes, once “Enforce a hard limit” is on |
| Anthropic | Deactivated for you | Yes, per organisation or workspace |
| Google Gemini | Reported to Google; not blocked on push | Yes, project spend cap |
| xAI | Disabled for you | Prepaid balance; no spend cap |
| Mistral | Not reported to Mistral | Yes, per organisation or workspace |
| DeepSeek | Not reported to DeepSeek | Prepaid balance; no spend cap |
| OpenRouter | Emailed only; not disabled | Yes, per key |
| ElevenLabs | Unclear: not on GitHub's list | Yes, per key |
| Replicate | Disabled for you | Prepaid credit; no spend cap |
| fal | Not scanned by GitHub | Prepaid credit; no spend cap |
| Groq | Reported to Groq; no stated action | Yes, per organisation |
| Together AI | Not scanned by GitHub | Prepaid credit; no spend cap |
| Hugging Face | Revoked for you, per GitHub | Team and Enterprise organisations only |
| Perplexity | Not reported to Perplexity | Prepaid credit; no spend cap |
| Cohere | Not reported to Cohere | Yes, monthly spending limit |
From each provider's docs and GitHub's list of scanned keys, checked 15 Nov 2026. A prepaid balance stops requests when it runs out, as long as auto-reload is off.
Stop the next one
- Call AI providers only from your server. Most leaked AI keys start as a call made from the browser.
- Turn on GitHub push protection for your repos, so a key is blocked before it's pushed. It doesn't catch Google or Gemini keys, so check those yourself.
- Give every key a limit where the provider allows it, and keep prepaid balances small with auto-reload off.
The security checklist has a prompt for each of these, plus the database and server checks that keep the rest of your app safe.
Questions
Is deleting the key from GitHub enough?
No. Anyone who cloned the repo already has it, and copies can survive in forks. GitHub's own advice is to revoke and replace the key first, then clean the history.
Will the provider disable it for me?
Sometimes. OpenAI, Anthropic, xAI and Replicate disable keys found in public GitHub repos. OpenRouter only emails you, and GitHub doesn't report Mistral, DeepSeek or fal keys to those providers at all. Revoke it yourself either way.
How fast do leaked keys get used?
Fast. Security researchers have seen keys pushed to public GitHub repos used within minutes. Treat a leak as an emergency, not a to-do.
Is a key in my frontend code really public?
Yes. Anything your app sends to the browser can be read in the browser's developer tools. Next.js, Vite and Expo all put variables starting NEXT_PUBLIC_, VITE_ or EXPO_PUBLIC_ into the code every visitor downloads.
Will I get my money back?
Not always. OpenAI says used credits can be refunded only for confirmed unauthorised use, and Google reviews charges from compromised keys case by case. Most others have no stated policy. Contact support quickly, with the dates and the usage that wasn't yours.
Related free tools
- Security checklist20 security checks for vibe-coded apps, each with a prompt for your coding agent.
- AI launch checklistThe AI-specific checks that generic vibe-coding checklists skip.
- Real cost per result calculatorWhat each AI result really costs, what you waste a month, and what to charge in credits.