Guide · Incident
Leaked OpenAI or Anthropic API key? What to do, and how to notice next time
Keys leak through public repos, frontend bundles, logs and screenshots. Someone else then uses your account for their own traffic, and you find out when the invoice arrives. Here is what to do now, and how to find out the same day next time.
Right now
- Revoke the key. Delete it in the provider's dashboard (OpenAI: API keys; Anthropic Console: API keys). Rotating means creating a new key and deleting the old one. Just creating a new one does nothing.
- Check where the spend came from. Both dashboards break usage down by key, project or workspace and by model. Note the time range and the models used: that's what support will ask for.
- Find the leak before you deploy the new key. Search your git history (not just the latest commit), client-side code (anything shipped to the browser, such as
NEXT_PUBLIC_variables), CI logs and error trackers. - Contact the provider's support and explain that the usage was unauthorized. Whether you get a refund is up to them, so don't count on it, but you can't get one if you don't ask.
Make the next leak less likely
- Keep keys server-side only. If a browser needs AI, put a small backend route in between.
- Turn on GitHub secret scanning and push protection, which block many provider key formats before they reach a public repo.
- Use one key per app or environment, so you can revoke one without taking everything down, and so usage by key tells you where a spike came from.
- Set the provider's own spend limit as a ceiling.
Notice the same day
A monthly limit stops spend at a ceiling, but a leak usually looks like a sudden jump: a day at 10× or 100× your normal. An anomaly alert catches that while the damage is still small. billshock reads your daily spend from the provider's billing API every hour and alerts Slack or Discord when a day is far above your recent average:
ALERT openai: $41.20 spent on 2025-10-07, 8.3x the 7-day average of $4.95
It runs in your own GitHub Actions with a separate admin key for cost data (not the key your app uses), stored in your repo secrets. Setup guides: OpenAI, Anthropic.
npx billshock init creates the config and an hourly GitHub Actions workflow. Free and open source. Prefer a hosted version? Join the waitlist.