I found my OpenAI API key in my frontend code. Now what?

Anything in your JavaScript bundle is public, and a key there can be copied and billed to your account within minutes of a crawler finding it. Fix it in this order.

How to fix it

  1. Revoke the key at platform.openai.com → API keys, before anything else.
  2. Check Usage for calls you didn't make, and set a monthly budget limit.
  3. Create a new key and store it only as a server-side environment variable (for example in Vercel → Settings → Environment Variables), with a name that does not start with NEXT_PUBLIC_ or VITE_.
  4. Move the OpenAI call into a server route (a Next.js route handler, a Supabase Edge Function or a serverless function) and have the browser call that route.
  5. Redeploy, then scan again to confirm the key is gone.

Common questions

Is it safe if the repo is private?

No. The bundle served to browsers is public whatever the repo is.

Why did my AI tool put it there?

Variables whose names start with NEXT_PUBLIC_ or VITE_ are compiled into the browser bundle on purpose. If the key was given one of those names, it ended up in your public JavaScript.

Can I just hide it with an environment variable?

Only on the server. A variable read by browser code is copied into the bundle when you build, so anyone can read it.

Fixed it? Scan again to confirm.

Scan your app for leaks