Your OpenAI key is visible to anyone. Here is how bots find it
API keys shipped in frontend code end up in the browser, where scrapers collect them within hours. Move them behind your server.
Admin
Founder, Debug Ninjas

You added an AI feature to your app. It works, users love it, and then your OpenAI bill arrives with usage you do not recognize. In most cases we see, the cause is the same: the API key was sitting in the website's code, and someone took it.
How the key ends up in public
Modern web apps send a bundle of JavaScript to every visitor's browser. Anything inside that bundle is public, even if it is "hidden" in an environment variable.
Frameworks make this easy to get wrong. Variables that start with VITE_, NEXT_PUBLIC_ or REACT_APP_ are deliberately copied into the browser bundle. When an AI tool sets up your OpenAI call, it often puts the key in one of those, because it is the fastest way to get the feature running.
Anyone can then open the browser's developer tools, look at network requests or the JavaScript files, and copy the key. They do not need to hack anything.
Who is looking
It is rarely a person poking around your site. Automated scrapers crawl public websites and code repositories looking for strings that match the format of known API keys. Once a key is found, it can be used to run the scraper owner's own AI workloads on your account, or resold.
The same applies to keys for Anthropic, Google, Stripe, Resend, Twilio and any other paid API. If the browser can see it, so can everyone else.
How to check your own app
- 01Open your live site in Chrome, right-click and choose Inspect.
- 02Go to the Network tab and use the AI feature. Click the request it makes. If it goes straight to
api.openai.comfrom the browser, your key is exposed. - 03In the Sources tab, search the JavaScript files for
sk-. OpenAI secret keys start with that prefix. - 04Check your code for environment variables with public prefixes that hold secret values.
- 05If your code is on GitHub, check whether the repository is public and whether a key was ever committed, even in an old commit.
How to fix it
- 01Rotate the key first. Create a new key in the OpenAI dashboard and delete the old one. Assume the old key is already in someone else's hands.
- 02Move the call to your server. Your frontend should call your own endpoint, such as an API route, a serverless function or a Supabase Edge Function. That endpoint holds the key and talks to OpenAI.
- 03Check who is calling. Your endpoint should confirm the user is logged in before spending money on their request, and limit how often one user can call it.
- 04Set spending limits. Use the usage limits and alerts in your OpenAI account so a leak can never turn into an open-ended bill.
- 05Keep secrets out of Git. Store them in your hosting provider's environment settings, and add
.envfiles to.gitignore.
What it costs if you skip it
The obvious cost is the bill. The less obvious ones are that your provider may suspend the account, which takes your AI feature offline for real users, and that a stolen key tied to your account can be used for content that violates the provider's policies.
The short version
- If a key is in the browser, it is public. Environment variable names do not change that.
- Rotate exposed keys, move AI calls behind your own server, and set spending limits.
- Check every paid API, not just OpenAI.
Finding exposed secrets across your code, repository and live site is one of the first things we do in a Ninja Audit. Book an Audit if you want it checked properly.
Written by Admin
Founder of Debug Ninjas. Has audited dozens of AI-built apps and still double-checks who can see what data.
Keep reading
Oct 22, 2026
Thinking of rebuilding your MVP from scratch? Read this first
A full rebuild feels like a clean start, but it usually costs more and fixes less than you expect. Here is how to decide, and what to do instead.
StrategyOct 15, 2026
It worked with 10 users. Here is why it slows down at 1,000
Apps that feel instant in testing often crawl once real data piles up. Three common causes, and how to spot them before your users do.
Performance
Oct 8, 2026
Anyone can read your users' data: the Supabase setting most apps miss
Without row level security, the public Supabase key lets anyone read every row in your tables. Here is how to check and fix it.
Security
One useful fix a month.
Field Notes in your inbox. No spam, unsubscribe anytime.