Skip to main content

Your OpenAI bill spiked overnight? 4 ways vibe-coded apps let strangers spend your AI credits

The key in your JavaScript is only cause #1. Open AI routes, no per-user caps and forgotten deploys cost just as much.

Updated 7 min readMarkdown

You added an AI feature to your vibe-coded app (a chat box, a summarizer, an image generator), shipped it, and a few days later the OpenAI or Anthropic dashboard shows usage you can't explain. Your own users didn't do that.

When this happens to an app built with Lovable, Bolt, Cursor, Replit or v0, it almost always comes down to one of four causes. The first is the famous one. The other three catch people who already "fixed" the first. Here's how to tell which one you have, what to do in the first hour, and how to stop it coming back.

First hour: stop the spend

Before diagnosing anything:

  1. Rotate the key at the provider. Create a new key, update your server-side environment variable, redeploy, then revoke the old key. Deleting it from your code isn't enough. Old deploys, caches and anyone who copied it still have it.
  2. Set limits so this can't run unbounded again. OpenAI's production guide says you can set spend alerts on the limits page, and set "custom rate and spend limits per project." Put the app on its own project with its own limit.
  3. Look at the usage breakdown for the time window and model. A spike from one key at odd hours points to cause 1 or 2 below.

Then work through the causes in order.

Cause 1: the key is in your public JavaScript

OpenAI's key safety guidance is explicit: "Never deploy your key in client-side environments like browsers or mobile apps." It warns this lets malicious users "make requests on your behalf – which may lead to unexpected charges." Requests "should always be routed through your own backend server."

In AI-built apps, the key usually ends up in the browser one of two ways:

  • it's stored in a variable with a public prefix (VITE_, NEXT_PUBLIC_, EXPO_PUBLIC_, REACT_APP_), which by design gets compiled into the code every visitor downloads
  • the builder wrote a "quick" fetch to the AI provider directly from a React component

How to check: open your live site, then DevTools → Sources → search all files for sk-, sk-proj-, sk-ant- and the provider's hostname (api.openai.com, api.anthropic.com). If the key or a direct call to the provider is in the bundle, that's your leak. There's a step-by-step version here: https://proofforge.live/guides/openai-api-key-leaked-in-frontend-bundle

Fix: move the call into a server route or edge function, keep the key in a server-only variable with no public prefix, and rotate it. Per-provider rotation steps:

Cause 2: your server route is a free AI proxy

This is the one that catches people who did cause 1 "right." The key is safely on the server, but the route that uses it, something like /api/chat or a Supabase Edge Function called generate, accepts requests from anyone:

  • no check that the caller is signed in
  • no limit on prompt length
  • no limit on how often one caller can hit it

Anyone who opens DevTools → Network on your site can see that route and call it in a loop. Your key never leaves the server, but your bill still climbs.

How to check: in a private window, signed out, copy the request your AI feature makes (DevTools → Network → right-click → Copy as cURL) and replay it from a terminal. If it returns an AI answer with no session cookie or token, it's open.

Supabase Edge Functions specifically: Supabase's docs say functions require a valid JWT by default (verify_jwt = true), and to "leave it on for user-facing functions." Turning it off to clear a 401 during development "removes the platform's check." It's common in AI-built apps to turn it off to make an error go away and never turn it back on. For user-facing functions, Supabase's own pattern is to use auth: 'user' so the handler requires a signed-in user's session and gets a client scoped to that user's RLS.

Fix: require a signed-in user on every AI route, then add the limits in cause 3.

Cause 3: no per-user caps

Even with sign-in required, open signup means anyone can create an account. Without caps, one throwaway account can cost you as much as an anonymous attacker.

What to add (all of it fits in the route you already have):

  • A maximum input length on prompts and uploaded text.
  • A maximum output length (max_tokens or the equivalent) on every request.
  • A per-user daily quota, stored in your database and checked before the AI call, not after.
  • Email verification before free credits, if you give any.
  • A rate limit per user and per IP on the route.

None of these are exotic. They're the difference between "a user tried the feature" and "a user scripted the feature."

Cause 4: a key you didn't know was live

Sometimes the spike isn't in your current app at all. Check:

  • Preview and staging deploys that still use the production key. Every branch preview is another public URL running your code.
  • An old deployment from before you fixed cause 1, still reachable at its unique deploy URL.
  • A key pasted into a chat, screenshot or public repo at some point. If you got an email from GitHub, OpenAI or Google about a leaked key, take it seriously, because they found it in public.
  • The same key shared across several apps. If one app leaks it, they all pay. Use one key per app, per environment.

After it's fixed: prove it from outside

Your dashboard tells you the spend stopped. It doesn't tell you what a stranger can still do. Two checks:

  1. Signed out, private window: search the live bundle again for sk- and provider hostnames, and replay the AI request without a session. The first should find nothing, and the second should be rejected.
  2. Scan the live URL. ProofForge's free scan checks the bundle for secret keys (OpenAI, Anthropic, Stripe, Supabase service_role and more), plus source maps, .env files and headers, from your URL alone: https://proofforge.live

The $9 math, honestly

Fixing this by prompting your AI builder tends to go: "move the key to the server" (build), "it broke, fix it" (build), "add auth to the route" (build), "now login is broken" (build). Every round is paid usage on Lovable credits, Bolt tokens or Replit checkpoints, and none of those rounds tells you whether the fix actually holds from outside.

ProofForge's free scan shows your grade, every finding's severity and impact, and the top fix in full. $9 once unlocks every finding with exact code fixes and ready-to-paste prompts for your builder, so it's one precise prompt per issue instead of a loop. If you're shipping changes all week, Fix + Guard ($29 once) adds deploy-hook rescans for 30 days, so a later prompt can't quietly put the key back in the bundle. There's a 14-day refund and no account: https://proofforge.live/pricing

Related fix guides:

Sources, checked December 1, 2026:

  • OpenAI Help Center, "Best practices for API key safety," help.openai.com/en/articles/5112595
  • OpenAI docs, "Production best practices" (spend alerts; per-project rate and spend limits), developers.openai.com/api/docs/guides/production-best-practices
  • Supabase docs, "Securing Edge Functions" (verify_jwt default, auth: 'user'), supabase.com/docs/guides/functions/auth
  • ProofForge tiers, proofforge.live/pricing.json

No comments yet. Be the first to comment.

More from this blog