Skip to content
prune.

OpenAI or Claude API key leaked: what to do right now

Revoke first, cap second, investigate third. Then make sure the next key never sits in your code.

Quick answer

Delete the leaked key now; a deleted key stops working and cannot be restored. Create a new one and deploy it. Turn on a hard spend limit (OpenAI project or organization, Anthropic organization or workspace) so another leak cannot run up the bill. Then check usage by key, purge the key from git history, and report unauthorized charges to support.

1. Revoke the key

OpenAI: API keys page, delete the key. Anthropic: Claude Console, API keys, the three-dot menu next to the key, Delete API key. Do this before anything else, even before you know how it leaked. Note the time; support will ask for it.

Both providers may disable an exposed key on their own. OpenAI says publicly exposed keys may be disabled when detected, and Anthropic works with GitHub secret scanning to deactivate keys found in public repos. Do not wait for it.

2. Put a ceiling on spend

OpenAI has hard spend limits per organization and per project. Make sure "Enforce a hard limit" is on; a spend alert only sends an email. Anthropic lets you set your own spend limit below your tier's monthly cap under Settings, Billing, and a lower limit per workspace. Both are monthly and neither is instant, so treat them as the floor of your protection, not the whole of it.

3. Find out what was spent

OpenAI's Usage page and Anthropic's Cost and Usage report both filter by API key. Look for models you do not use, traffic at hours you are asleep, and spikes that start right after a commit or deploy. Export the rows; they are your evidence. Then contact support about the unauthorized usage with the key, the window, and when you revoked it.

4. Find the leak, then purge it

  • Git history, old branches, forks and gists. Deleting the file does not delete the commit.
  • Frontend bundles and mobile apps. A key in client code is a public key.
  • CI logs, notebooks, screenshots, pasted errors in issues, Slack and Discord.
  • Third-party tools you pasted the key into.
find-leak.sh
# Find every secret in the full history, not just the latest commit
gitleaks git .      # or: trufflehog git file://. --only-verified

# OpenAI keys start with sk- (project keys sk-proj-), Anthropic with sk-ant-.
# Check built bundles too: anything shipped to a browser is public.
grep -rnE "sk-(proj-|ant-)?[A-Za-z0-9_-]{20,}" dist/ build/ .next/ 2>/dev/null

Rotate first, then rewrite history so the old key is not copied again:

purge-key.sh
# After rotating the key: remove it from every commit
pip install git-filter-repo
echo 'sk-proj-YOUR_LEAKED_KEY==>REMOVED' > replacements.txt
git filter-repo --replace-text replacements.txt
git push --force --all

5. Stop keys from leaking next time

  • Call the model from your server. Never put a provider key in browser or mobile code.
  • One key per app and environment, so you can revoke one without taking down the rest.
  • Keys in a secret manager, never in .env files that can be committed.
  • Turn on GitHub secret scanning and push protection for every repo.

Where Prune fits

With Prune, your OpenAI and Anthropic keys live in Prune's encrypted vault (AES-256-GCM) and your code only holds a Prune key. If that leaks, you revoke it in the dashboard; the provider key never left the vault, so you do not have to rotate it or redeploy every service that used it.

Shield adds the controls the providers do not have per key: a daily spend cap and spike detection on every Prune key, an IP allowlist (a call from anywhere else gets 403 ip_blocked), and allowed models and providers per key. New accounts start on Balanced ($200 a day). Every blocked call carries an X-Prune-Shield-Code header, listed on error codes.

With a single line of code, Prune cuts your AI bill and protects your team from runaway spend, leaked keys and dangerous calls.

Related

Have an account? Sign in · PyPI.