How to check if your AI-built app is leaking API keys
AI app builders are brilliant at one thing: getting a working app in front of you fast. But "fast" and "make it work" often means an API key gets pasted somewhere it should never live — your app's frontend, where anyone can read it. If you've built with Lovable, Bolt, Replit or v0, there's a real chance a key is sitting in your code right now, in plain sight. Here's how keys leak, which ones actually hurt, and how to check yours.
Where API keys leak in AI-built apps
An API key is a password for a service — OpenAI, Stripe, your database. The golden rule is simple: secret keys belong on a server, never in the browser. The moment a key lands in your frontend code, it gets bundled into the JavaScript your app ships to every visitor. Anyone can open their browser's developer tools and read it.
The most common leaks are all variations of the same mistake:
- Hardcoded in client code — a key typed directly into a component to "make the call work," then shipped to the browser.
- Baked into the JavaScript bundle — even if you didn't paste it visibly, a build step can embed a server key into public files.
- Committed to a public repo — the key sits in your GitHub history for anyone (and every bot) to scrape.
The keys that actually cost you money
Not all leaked keys are equal. Some are meant to be public (like a Supabase anon key or a Google Maps key). Others hand a stranger your wallet or your database. Ranked by how much they hurt:
AI provider keys
OpenAI (sk-…), Anthropic (sk-ant-…), OpenRouter (sk-or-…) and friends. The single most common leak in AI-built apps — the app talks to an AI, and the key ends up in the browser. Whoever finds it runs your model on your dime until the bill (or your credits) is gone.
Payment keys
A Stripe secret key (sk_live_…) exposed in the frontend can be used to create charges, refunds or read customer data. Rare, but catastrophic when it happens.
Database & backend keys
A Supabase service_role key or open Firebase rules give full read/write access to your users' data. We break this one down in detail in Exposed Supabase keys: anon vs service_role.
Some keys are supposed to be public and are safe in the browser — a Supabase anon key (with database rules on), a Google Maps AIza… key, a Stripe publishable key. The danger is the secret ones. Telling them apart is the whole game.
Why it happens more with AI-built apps
When you ask an AI to "connect this to OpenAI" or "add payments," it writes code that works — and the quickest working version often puts the key right in the frontend. The AI isn't trying to expose you; it's optimizing for "it runs." And if you're not a developer, there's no obvious sign that a key which works in the preview is also visible to the whole internet.
How to check if your keys are exposed
A rough manual check you can do right now:
- Open your live app, then your browser's DevTools → Sources (or "view source"), and search the files for key-shaped strings:
sk-,sk-ant-,sk_live_,AIza, or a longeyJ…token. - Check the Network tab while using your app — if a request carries a secret key in plain sight, it's exposed.
- If your code is on GitHub, search the repo (and its history) for the same patterns.
Real bundles are minified and split across many files, keys are easy to miss, and it's genuinely hard to tell a harmless public key from a dangerous secret one by eye. It's the kind of check that's easy to get wrong — and "I looked and didn't see anything" is not the same as "it's safe."
Not sure if your app is leaking a key?
Paste your app's URL and our free scan checks it in about 10 seconds — across your database, AI provider and payment keys.
Scan your app free →What to do if you find one
- Rotate it immediately. Roll the key in the provider's dashboard and treat the old one as compromised — assume a bot already has it. Leaked keys get scraped within minutes.
- Move it to the backend. A secret key belongs in server-side code only — an API route, an Edge Function, a server environment variable. Your frontend should call your server, and your server holds the key.
- Cap the damage. Set spend limits and usage alerts on AI and payment accounts, so a leak can't run up an unlimited bill.
- Check again. After rotating and moving keys server-side, re-scan to confirm nothing is still exposed.