PatchPaste · Guides

Last updated 13 November 2026

OpenAI API key in my Lovable or Bolt frontend: how to check, revoke and move it

You added ChatGPT or an OpenAI call to a Lovable, Bolt, Cursor or v0 app, and now you are not sure whether the secret key shipped to the browser. Here is a 2-minute check, what OpenAI says to do if the key is already public, and where the new key should live.

Short answer: an OpenAI API key must not be in frontend code. OpenAI's API key safety guide says never to deploy your key in client-side environments like browsers or mobile apps, because someone can take it and make requests on your behalf, which may lead to unexpected charges. If it is already live, delete the key first, review usage, then put a new key only on the server (a Supabase Edge Function secret, a Lovable Secret, or a server route) and redeploy.

Why this happens

AI builders often suggest VITE_OPENAI_API_KEY or NEXT_PUBLIC_OPENAI_API_KEY, or paste the key into a component so the demo works. Variables with those prefixes are copied into the JavaScript every visitor downloads. That is not a safe "environment variable". See are VITE_ variables secret? and Cursor shipped an API key in my frontend.

The official openai-node SDK will not run in a browser unless you set dangerouslyAllowBrowser: true. Its README says this “exposes your secret API credentials in the client-side code”. If your AI editor added that flag, treat the key as public.

A 2-minute check

  1. Open your live app (the published URL, not only the editor preview).
  2. Open DevTools → Sources (or Network, then a .js file) and search for sk-, sk-proj-, OPENAI_API_KEY and dangerouslyAllowBrowser.
  3. If you find a key, assume it is already in other people's hands. Do not only remove it from the code.

Or paste the URL into the scan form at the bottom of this page. PatchPaste searches the live JavaScript for OpenAI keys and shows any it finds masked.

If the key is already live

OpenAI's account security guide, under "Revoke an exposed API key", says:

  1. Delete the affected key through the API key dashboard.
  2. Review your API usage for unexpected activity and keep the details.
  3. Contact OpenAI Support.

The same guide says that when OpenAI detects an API key on the public internet, or leaked inside an app in an app store, the key is disabled immediately. Do not wait for that. Delete it yourself, then create a replacement only after you have a server place to put it.

The safety guide also recommends setting monthly spend limits with hard enforcement, so a leaked key cannot run up an unlimited bill. Spend alerts alone do not stop API traffic, and enforcement is not instantaneous, so recorded spend may slightly exceed the limit.

Where the new key should live

OpenAI says requests should always be routed through your own backend server, and that you should use environment variables or a key management service rather than putting the key in source code or a client-side app. In a typical AI-built stack that means:

Then remove the old frontend variable and any dangerouslyAllowBrowser setting, redeploy, and run the 2-minute check again.

Fixes to refuse

A prompt to paste into Lovable, Bolt, Cursor or v0

An OpenAI API key may be in the frontend (look for VITE_OPENAI_API_KEY, NEXT_PUBLIC_OPENAI_API_KEY, sk- or sk-proj- values, or dangerouslyAllowBrowser). Do not leave a secret key in browser code. 1) Show me every file that reads an OpenAI key. 2) Move the OpenAI call to a server-only path: a Supabase Edge Function secret (Deno.env.get, verify_jwt on), a Lovable Secret, or a Next.js Route Handler with no NEXT_PUBLIC_ or VITE_ prefix. 3) Remove the old frontend variable and any dangerouslyAllowBrowser setting. 4) Tell me exactly where to paste a new key, and how to confirm the old one is gone from the live JavaScript after deploy. I will delete the old key in the OpenAI dashboard myself.

Related: Are VITE_ variables secret?, Edge Function secrets, Cursor shipped a secret key, Is my Stripe key exposed? and pre-launch checklist

OpenAI API key FAQ

Is an OpenAI API key safe in a Lovable or Bolt app?

Not in the frontend. OpenAI's API key safety guide says: never deploy your key in client-side environments like browsers or mobile apps, because someone can take that key and make requests on your behalf, which may lead to unexpected charges or compromise of certain account data. Requests should be routed through your own backend, where the key can stay secret.

I put the key in a VITE_ or NEXT_PUBLIC_ variable. Is that secret?

No. Those prefixes copy the value into the JavaScript every visitor downloads. Putting an OpenAI key in VITE_OPENAI_API_KEY or NEXT_PUBLIC_OPENAI_API_KEY is the same as publishing it. See the guide on VITE_ variables.

What should I do first if the key is already live?

Revoke it. OpenAI's account security guide says: if you think an API key has been compromised, delete the affected key through the API key dashboard, review your API usage for unexpected activity and keep the details, and contact OpenAI Support. Then put a new key only on the server, redeploy, and confirm the old key is gone from the live JavaScript.

Will OpenAI disable the key for me?

Sometimes. OpenAI's account security guide says that when it detects an API key on the public internet, or leaked inside an app in an app store, the API key is disabled immediately. Do not wait for that. Delete it yourself.

Where should the new key live?

In a server-only secret: a Supabase Edge Function secret, a Lovable Secret, or a Next.js server route environment variable that is not prefixed with VITE_ or NEXT_PUBLIC_. The official advice is to use environment variables or a key management service, and never to commit the key to a repository.

Can PatchPaste find this?

Yes, if the key is in the JavaScript your live site sends to visitors. The free scan searches that JavaScript for OpenAI keys (and Stripe, Anthropic, AWS, GitHub and Supabase admin keys) and shows any it finds masked. It cannot see keys that live only on the server.

Think the key shipped? Check the live app for free

Paste your live URL for a free A to F report. PatchPaste searches the JavaScript your site sends for OpenAI, Stripe, Anthropic, AWS, GitHub and Supabase admin keys (shown masked), and also checks whether common Supabase tables answer to your public anon key, plus exposed .env/.git/source maps and missing headers. It cannot see keys that live only on the server. Fix prompts for that report are a one-off £9 (or £29 for 10). Scans are free to rerun after each change.

Free. No login. No code access.

Want to see one first? View a sample report.

Sources (checked 13 Nov 2026): OpenAI Help Centre Best practices for API key safety (never deploy your key in client-side environments; route requests through your own backend; environment variables and key management; rotate and set spend limits with hard enforcement); OpenAI Help Centre Keeping your OpenAI account secure (do not ship your API key; keys found on the public internet are disabled immediately; revoke an exposed key: delete it, review usage, contact Support); openai-node README (dangerouslyAllowBrowser exposes secret API credentials in client-side code). Key management: platform.openai.com/api-keys.