Your OpenAI API key is in the frontend: how to find it, revoke it and move the call server-side
Updated 27 November 2026
If your Lovable, Bolt, v0 or Vite app talks to OpenAI from the browser, the secret API key is in the JavaScript that every visitor downloads. That is already a leak, even if the app only has a handful of users. OpenAI's own docs say the key is a secret and must not be exposed in client-side code such as browsers or apps, and that requests should go through your own backend. This guide is the OpenAI-specific version of that check: how to confirm the key is in the live bundle, what to do first, and where the call should live instead.
Check your own app for this, free.
Paste your live URL. ShipCheck looks for leaked API keys in your page and JavaScript, exposed files like /.env and /.git, missing security headers, SSL certificate problems, domain expiry (custom domains only) and what Google sees without running JavaScript. You'll see your score without signing up.
Short answer
An OpenAI API key must never ship in the frontend. That includes sk-…, sk-proj-… and the other official secret formats. Putting it in VITE_OPENAI_API_KEY or NEXT_PUBLIC_OPENAI_API_KEY does not hide it: Vite and Next.js copy those values into the public bundle at build time. If you find one, revoke it first, then move the OpenAI call into a server function and store the replacement key only as a server-side secret. A key prefix check (nothing leaves your browser) will tell you whether the string starts like a secret OpenAI key. For the same check across other providers, see how to check for leaked API keys.
How to check the live app
Check the deployed URL, not only the editor preview.
- Search the JavaScript. Open the live site, press F12, go to Sources, and search all files (Ctrl+Shift+F, or Cmd+Option+F on a Mac) for
sk-proj-,sk-andapi.openai.com. Click the chat or AI feature first, because some chunks only load then. - Watch the Network tab. Use the AI feature. If the browser sends a request straight to
api.openai.comwith anAuthorization: Bearer …header, the secret key is in the frontend, even if the text search missed it. - Or grep the scripts linked from the page:
URL=https://your-app.com for js in $(curl -s "$URL" \ | grep -oE 'src="[^"]+\.js[^"]*"' | cut -d'"' -f2); do case "$js" in http*) u="$js";; /*) u="$URL$js";; *) u="$URL/$js";; esac curl -s "$u" | grep -oE 'sk-(proj-|svcacct-|admin-)?[A-Za-z0-9_-]{8,}' \ | cut -c1-14 | sort -u doneThis prints only the start of a match, so you are not pasting a full key into your terminal history. A clean result is not proof: it only covers scripts linked from the HTML, not code that loads later.
Not sure what you found? Type just the first few characters into the is this key safe? tool. Do not paste the whole key.
Why this happens in vibe-coded apps
The usual prompt is “add ChatGPT to my app” plus a key in an environment variable. Frontend build tools then bake any public-prefixed variable into the JavaScript:
- Vite (most Lovable and Bolt apps): variables starting with
VITE_are exposed in client-side source after the build. Vite's docs sayVITE_*variables should not contain sensitive information such as API keys, and recommend a backend or serverless/edge function for secrets. See Vite: Env Variables and Modes. - Next.js (v0, many Cursor apps): variables starting with
NEXT_PUBLIC_are inlined into the client bundle at build time. A variable namedOPENAI_API_KEY, without that prefix, stays on the server. See Next.js environment variables.
Renaming the variable, splitting the key, or “hiding” it in a client helper does not help. The browser has to send the real key to OpenAI, so anyone can copy it from the Network tab.
If the key already leaked, do this in order
- Revoke or delete the exposed key first. Pausing the app does not stop anyone: the key works without your site. In OpenAI, open the API keys page and delete the affected key. OpenAI says revocations take effect within a few seconds (API authentication). If OpenAI itself finds a key on the public internet, or leaked inside an app in an app store, it disables that key immediately (Keeping your OpenAI account secure).
- Review usage, then contact support if you see misuse. Check the Usage page for unexpected models, volume or start times. OpenAI asks you to delete the key, review usage, and contact support through help.openai.com (Best practices for API key safety). OpenAI does not promise a refund.
- Create a replacement with limits. OpenAI recommends giving project keys an expiry date and rotating them regularly. Set a monthly spend limit for the organisation or project and turn on hard enforcement. Spend alerts on their own do not stop API traffic. Hard enforcement can block legitimate requests, and recorded spend may slightly exceed the limit because enforcement is not instantaneous. See OpenAI's spend limits guide.
- Put the new key only on the server (next section). If you paste it back into a
VITE_orNEXT_PUBLIC_variable, it will leak the same way. Redeploy after you move the call, then confirm the old key returns 401:curl -s -o /dev/null -w "%{http_code}\n" \ https://api.openai.com/v1/models \ -H "Authorization: Bearer OLD_KEY"
If other secrets were in the same frontend or the same host incident, rotate those too, in priority order: which keys to rotate, and in what order.
The fix: the browser calls your function, not OpenAI
OpenAI's guidance is that requests should always be routed through your own backend, where you can keep the API key secure.
- Lovable or Bolt with Supabase: put the call in a Supabase Edge Function and store the key as a secret (Edge Functions → Secrets, or
supabase secrets set OPENAI_API_KEY=…). The function reads it withDeno.env.get("OPENAI_API_KEY"). - Next.js (v0, Cursor): use a Route Handler or Server Action and read
process.env.OPENAI_API_KEY— a variable without theNEXT_PUBLIC_prefix, set in your host's environment settings. - Anything else: a serverless or edge function on your host (Vercel, Netlify, Cloudflare) works the same way.
Then protect that function, or strangers will call it as a free proxy: require a signed-in user, add a per-user rate limit, choose the model and cap max_tokens (or the equivalent) on the server instead of trusting the browser, and keep OpenAI's hard spend limit as a backstop.
What ShipCheck checks (and what it doesn't)
The free scan fetches the raw HTML of your live URL and the same-origin JavaScript files linked from that HTML (and public source maps from those files, when they are available). It does not run JavaScript or click around the app. It flags an OpenAI API key in that HTML or those files as a critical finding. A key that only appears in a chunk loaded after you use a feature can be missed, so also use the DevTools and Network checks above. The scan does not call OpenAI with the key, does not revoke it, and does not check your spend limits. It does not probe Storage buckets, and it does not detect Next.js versions. The Supabase table-read test needs a free account that has verified it owns the app; the anonymous scan does not query tables. Paid plans re-scan weekly on Solo ($12/mo) or daily on Builder ($29/mo). Separately, paid plans also check once a day that the app URL returns a status below 400 (a 15 second timeout, with an email after two failed checks). That daily check is not a secrets test.
FAQ
Is VITE_OPENAI_API_KEY safe in a Lovable or Bolt app?
No. Vite exposes any VITE_ variable in the client bundle at build time, and Vite's own docs say those variables should not contain API keys. Store OPENAI_API_KEY as a server secret and call OpenAI from a Supabase Edge Function or another server function.
Is a sk-proj- project key safer to put in the frontend?
No. It is still a secret API key. Project keys can be given an expiry date and tied to a project with a hard spend limit, which reduces the damage after a leak, but they must still live only on the server.
The app only has a few users, or it is still on a preview URL. Does that matter?
No. Anyone who can load the URL can download the JavaScript and copy the key. Bots look for key-shaped strings on public sites. The risk is a stranger spending on your OpenAI account, not your current user count.
Can I hide or obfuscate the key in the client instead?
No. The browser has to send the real key to api.openai.com, so it will show up in the Network tab. OpenAI's docs say to keep the key on a backend server.
Does ShipCheck check for OpenAI keys?
Yes. The free scan searches the live HTML and the same-origin JavaScript linked from that page (plus public source maps it finds) and flags a matching OpenAI key as critical. It does not run JavaScript, so also search in DevTools if a feature loads code later. It will not revoke the key for you.
Run the same checks on your app.
A free scan takes under a minute. No card, and no sign-up to see your score and the list of issues.