LogicTrail
  • Trails
  • Check my app
  • Pricing
  • Sign in
  1. Trails
  2. /
  3. Money and secrets
  4. · 4 minutes · Free

The key in the bundle

Your OpenAI bill jumped from $40 to $3,900 overnight. Your app has 60 users.

This answers: Is my API key exposed in my frontend code? No coding needed. 3 quick decisions.

  • Keys and secrets
  • How a request travels

Step 1 of 3

You open your 's JavaScript in the browser and search for 'sk-'. What did you find?

_next/static/chunks/app/chat/page-3f9a.js
const client = new OpenAI({  apiKey: "sk-proj-8Hq…W2x",  dangerouslyAllowBrowser: true,});
Choose an answer

Pick one. You will see what really happens, and why.

Is my API key exposed in my frontend code?

If the key is in a variable with a such as NEXT_PUBLIC_, VITE_ or EXPO_PUBLIC_, or used in client code, it is in your and anyone can copy it. Revoke the key, create a new one, and call the paid from your server only.

Trail of the bug
  1. Browser
  2. Stranger
  3. AI provider

Breaks at Browser: Secret key shipped to every browser

How it works

Where your keys end upName it NEXT_PUBLIC_

Your server: private

OPENAI_KEY (secret)

Every visitor's browser: public

Publishable key (meant to be here)
The secret key stays on your server, where visitors can't see it. Only the publishable key, made for browsers, goes out.

Why AI tools write this bug

When a key is undefined in browser code, the quickest fix an AI suggests is adding a . The error disappears and the secret becomes public.

How to fix it

  1. Search your built JavaScript for the key's prefix, such as sk-.
  2. Revoke the leaked key immediately; renaming it is not enough.
  3. Move the call into a server route or server action.
  4. Keep secrets in variables without a .

Check your own app

Paste this into Lovable, Cursor or Claude Code:

Search this project for every environment variable with a public prefix (NEXT_PUBLIC_, VITE_, EXPO_PUBLIC_, PUBLIC_) and every API key or token string in the code. For each, tell me whether it is safe to be public. Flag any secret key that ends up in browser code.

Common questions

Does minifying my code hide the API key?
No. Minifying shortens variable names; the key stays a plain string anyone can search for.

Related scenarios

  • Works on my machinePro · 4 min
  • Invoice 105Free · 4 min
  • The save that saved nothingFree · 4 min

More on this trail

Money and secrets: Keys, payments, webhooks, and reading what your AI changed.

Want someone to look?

We check AI-built apps for this and three other common leaks, in plain English.

Check my app
Sign in