← sources

How I make sure a leaked Anthropic API key can't cost me more than $50

source: reddit (reddit:ClaudeAI)published 2026-10-20 07:35ingested 2026-10-21 02:36

retained text

After that $88k API key story, here's the boring setup that keeps my keys safe

That post scared me because I run an app where users bring their own Anthropic API key. So I spent a weekend making sure a leaked key can never turn into a five-figure bill. None of it is clever, all of it is boring:

1. Keys never touch the frontend. The browser only knows "a key is saved", never the key itself. Every AI call goes through the server.
2. Keys are encrypted at rest (AES-256-GCM), with the encryption key only in the server's environment. A database dump alone is useless.
3. Separate key per purpose. My own app features use their own key in their own Anthropic workspace, never my personal one.
4. Hard spend limit on that workspace ($50/month). Even if everything else fails, that's the worst case, not $88k.
5. No auto-reload on credits. If the balance runs out, things stop. Annoying, but stopping is the feature.
6. Rate limits plus a daily cap in my own database, so one person (or bot) can't burn through it in a night.
7. Never let an agent run unattended with a key that has no limit. That's the actual lesson from the original post.

The spend limit alone would have turned that story into a $50 story. If you do one thing tonight: open your provider's console and set a monthly limit on every key.

What else are people doing? Curious if anyone rotates keys automatically.

document fetched 2026-10-21 00:22 · canonical https://reddit.com/r/ClaudeAI/comments/1xalsld/how_i_make_sure_a_leaked_anthropic_api_key_cant