Guides / Cost control

The bill arrives before the alert does. Cap the blast radius now.

In April 2026, a solo developer reported a bill of roughly $60,000, about 9 million yen, run up in 13 hours after a Google API key shipped in the frontend bundle of a Firebase and Gemini app with no restrictions on it. In June, a thread on r/Firebase reported a bill near $55,000 from 2.2 million requests against another abused client-side key. And on 11 July, Replit itself miscomputed checkpoint charges for about 6 percent of paying users before fixing the error and auto-refunding. Different failure modes, one lesson: nothing in the default setup stops the meter. Google's own documentation is blunt that budgets do not cap usage or spending, and that alerts can trail your costs by days. This guide does two things: locks down the keys that can spend your money, then sets the few real caps that actually exist, provider by provider.

How a bill runs away.

The most common route is a key with spending power sitting in public. AI coding tools reach for the path of least resistance: a config object in client code with the raw key in it, or an environment variable prefixed VITE_ or NEXT_PUBLIC_, which by design is inlined into the JavaScript your users download. Automated scrapers collect keys from public bundles and repos around the clock, and when one lands on a Google key with no restrictions, the attacker does not use it for your app's two Firestore reads. They point it at the most expensive API it can reach, which today is usually an LLM endpoint, and run it flat out. That is the whole mechanism behind the $60,000-in-13-hours report: exposed key, no application restriction, no API restriction, Gemini access.

The subtlety that traps Firebase apps specifically is that the web config's apiKey is public by design. Shipping it is normal. It is only safe when the key is restricted to your domains and your APIs and your data is guarded by security rules. An unrestricted key that can also reach paid AI APIs is not a config value, it is a blank cheque.

The second route is an open proxy: you did the right thing, moved the provider key server-side, and then exposed an endpoint that forwards requests without checking who is asking or how often. Attackers do not need your key if your endpoint will spend your money for anyone who posts to it.

The third route is your own software: a retry loop without backoff, an agent that calls a paid API inside a loop, a cron job running against production. And occasionally the meter itself is wrong. On 11 July 2026, Replit reported that a cost-calculation error had inflated checkpoint charges for roughly 6 percent of paying users for several hours; it fixed the error and refunded automatically. The lesson is not that platforms are careless, it is that invoices are software output and deserve the same scepticism as any other output: read them.

What makes all three routes expensive is the broken feedback loop. Firebase's own billing documentation warns that budgets and budget alerts do not cap your usage or charges, and that the alert email can arrive days after the costs were incurred. By the time a human reads the warning, the damage is done. So the plan is: shrink what a leaked key can do first, then put hard stops where the provider actually offers one.

Ten minutes on key lockdown.

  1. Restrict every Google API key twice. In Google Cloud Console, open APIs & Services, then Credentials. Every key needs an application restriction (which websites, IP addresses, or apps may use it) and an API restriction (which APIs it may call). Google rejects any request that does not satisfy the restrictions. A key locked to your domain and to the two APIs your app uses is a much smaller prize than an open one, whatever else goes wrong.
  2. Search what you actually shipped. Open the built, deployed JavaScript, not your source, and search for AIza, the prefix of every Google API key, and for sk-, the prefix of most LLM provider keys. Anything you find is public. A Google key with restrictions may be fine there; an LLM provider key never is.
  3. Rotate anything that shipped unrestricted. Assume it was harvested the day it went live. Rotation and the rest of the incident drill are in the leaked-key response plan; the short version is that the new key must not ship in the next bundle, which is what the next step prevents.
  4. Keep LLM keys server-side only, behind your own auth and rate limit. The client calls your endpoint, your endpoint holds the key and checks the user before forwarding. The proxy pattern is a dozen lines; the auth check and the rate limit are the two lines that keep the proxy from becoming route two above.

The caps that actually exist, provider by provider.

Anthropic has real caps. The Claude Console lets you set a monthly spend limit for the organisation, and a lower one per workspace. A workspace limit caps that workspace's monthly spending outright, which is exactly what you want: put your production key in its own workspace with a limit you can afford to lose. Note that you cannot set limits on the Default Workspace, which is one more reason not to run production from it.

OpenAI has per-project limits. The platform supports custom rate and spend limits per project, alongside a notification threshold that emails you at a dollar amount you choose. Every account also starts with an approved usage limit, from $100 per month, that rises with your usage tier. Keep production in its own project with its own limit, and set the notification threshold well below the number that would hurt.

Supabase has a Spend Cap. On the Pro plan it is a single toggle in the organisation's Cost Control settings: with the cap on, once you exceed the plan quota for a covered item, further usage of that item is disallowed until the next billing cycle instead of being billed. It covers the abuse-shaped items, egress, edge function invocations, active users, realtime, storage; it does not cover things you explicitly provision, like bigger compute or point-in-time recovery. The Free plan never charges at all, it just stops.

Google, including Gemini and Firebase, has no native cap. This is the one to internalise, because it is where the biggest bills keep happening. A Google Cloud budget is a monitoring tool: its own documentation states that it does not cap usage or spending, it only alerts. The supported way to get a hard stop is to wire the budget's Pub/Sub notification to a small Cloud Run function that calls the Cloud Billing API and detaches billing from the project. Google documents this pattern, with a warning worth taking seriously: disabling billing shuts down all resources in the project and some may be irretrievably deleted. That is the correct trade for a side project or an early-stage app, where the worst case should be an outage, not a mortgage. Decide which one your app is before the meter decides for you.

Prepaid platform credits are a cap of a different kind. Lovable runs Cloud usage on workspace credits and pauses a project when the balance runs out, which bounds the damage by construction. Replit's effort-based pricing draws from your account in the same prepaid spirit. The residual risk on credit-metered platforms is metering bugs, which is what the 11 July incident was; the defence costs one minute a month: read the invoice.

If the bill has already landed: stop the burn first, rotate and restrict the key, or take the endpoint down. Screenshot the provider's usage pages before anything resets, so the abuse window is documented. Then contact the provider's billing support and ask for an adjustment, in writing, with the evidence attached. Providers have refunded abuse-driven bills, Replit refunded its own metering error unprompted, but none of them guarantee it, and your case is strongest when you can show the leak is closed and the usage pattern was plainly not yours.

A budget is a smoke alarm, not a sprinkler system Every provider will happily email you while your money burns. Only some of them will turn the gas off. Know which kind each of your providers is, set the real caps where they exist, and build the kill switch where they do not. The time to do it is before launch week, because the meter runs at machine speed and you read email at human speed.

Questions

Questions founders ask.

Does a Google Cloud budget stop my spending when I reach it?

No. Google's documentation states plainly that budgets do not cap usage or spending; they trigger alert emails, and those alerts can arrive days after the costs were incurred. If you need an actual stop, Google documents wiring the budget's Pub/Sub notification to a function that disables billing on the project, with the caveat that this shuts down every resource in the project and some may be irretrievably deleted. For a small app that is usually the right trade: better a dead project than a five-figure invoice.

The Firebase API key is in my frontend bundle. Is that a leak?

Not by itself. The Firebase web config's apiKey is public by design, and shipping it in the browser is normal. It becomes a leak the moment the key is unrestricted: anyone who copies it can then call whatever APIs the key can reach, on your bill. The fix is to give the key an application restriction limiting it to your domains and an API restriction limiting it to the APIs your app actually uses, and to protect the data behind it with security rules. A key that can reach paid AI APIs should never be in a bundle at all, restricted or not.

Can I set a hard monthly cap on OpenAI or Anthropic spending?

Yes, and you should. Anthropic lets you set monthly spend limits at the organisation level and per workspace, so a production workspace can be capped at a number you can afford. OpenAI supports custom rate and spend limits per project plus a notification threshold at a dollar amount you choose, and every account has an approved usage limit that starts at $100 per month and rises by tier. In both cases the useful move is isolation: production keys live in their own workspace or project, with their own limit, so a runaway integration cannot spend the whole account.

What should I do the morning a five-figure API bill lands?

Stop the burn before anything else: rotate and restrict the abused key, or take the open endpoint down, because the meter is still running while you read the invoice. Screenshot the usage and billing pages so the abuse window is documented before anything resets. Then write to the provider's billing support with the evidence and ask for an adjustment. Refunds for abuse and metering errors do happen, but no provider guarantees one, and your case is strongest when the leak is demonstrably closed and the traffic pattern is plainly not yours. Do not delete the project; it is your evidence.

Do prepaid credits on platforms like Lovable and Replit protect me?

Largely, yes. A credit balance is a cap by construction: Lovable pauses a Cloud project when the workspace balance runs out, and Replit's effort-based pricing draws from a balance in the same way, so the worst case is bounded by what you have loaded. The residual risk is the meter itself being wrong, which happened on 11 July 2026 when Replit miscalculated checkpoint charges for about 6 percent of paying users for several hours, then fixed it and auto-refunded. Credits change the failure mode from a surprise invoice to a drained balance, so the habit that remains essential is reading the usage breakdown each month.

Cost controls are production controls

A five-figure surprise bill is a production failure. Get ahead of it.

A production-readiness review covers the money paths along with the code: which keys ship to the browser and what they can reach, whether every provider has a spend cap or a kill switch, whether your proxy endpoints check auth and rate limits, and what the first hour of an abuse incident looks like, ranked alongside every other fix by the engineers who would do the work.