OpenAI & Anthropic API keys in client code: the new #1 leak
A new leak at the top of the list
For years the classic leaked secret was a cloud or payments key. The shape has shifted. With nearly every product bolting on an AI feature, keys from OpenAI, Anthropic and similar providers have climbed to the top of the leak charts — not because they are special, but because of where they end up: in the browser.
Why these keys end up client-side
The pull is purely about speed. You want a chat box, a summarizer, a 'generate' button. The provider's quickstart shows a few lines of JavaScript, you paste in your key, and it works on the first try. The AI assistant building your app does the same — it writes the feature you asked for, calling the API directly from the component, because nobody asked it to add a backend. The AI writes the code you asked for, not the security you didn't mention.
That code is then bundled and served to every visitor. The key sits in your JavaScript, readable by anyone who opens the network tab — and by the bots that scan fresh deployments for known key formats. LLM provider keys have recognizable prefixes, so they are easy to spot at scale.
Why an LLM key is worth grabbing
A leaked AI key is not abstract risk; it is a direct line to your wallet.
- It bills your account. Every call made with your key is charged to you. A leaked key gets drained through automated abuse, often reselling your quota to others.
- The bill arrives fast. Usage-based pricing means a busy abuser can run up a serious charge before the next invoice — sometimes before you even notice.
- It can reach your data. Depending on setup, the key may also reach fine-tuned models, files or assistants tied to your account.
This is normal hygiene to get right, not a scandal — but the cost of getting it wrong is unusually concrete here.
The fix is the standard one
- Put the call behind your own endpoint. The browser calls your server; your server holds the key and calls the provider. The key never ships to the client.
- Add your own guardrails. Once the call is server-side you can rate-limit, cap spend, and require your user to be authenticated — none of which is possible from the frontend.
- Use provider spend limits. Set a hard monthly cap on the key as a backstop, so a mistake cannot become an unbounded bill.
- Rotate anything that was public. If a key ever shipped in client code, revoke it and issue a new one. Assume it was found.
Check whether your key is reachable
The hard part is that you cannot eyeball a built bundle to confirm a key is hidden. An automated scan reads your pages and scripts the way a bot would and tells you if an AI provider key is exposed. Scan your site and find out before the meter starts climbing.