Skip to main content
友田 陽大
Running the app you built with AI
バイブコーディング
個人開発
Vercel
インフラ
AI

The bill spiked after launch — usage-billing incidents, and how to cap them

Why cloud and AI API costs run away after you launch an app built with AI, explained for non-engineers. The five patterns that spike, how to set caps on Vercel, Supabase and AI APIs, and how to add rate limiting.

Published
Reading time
8 min read
Author
友田 陽大
Share

Security incidents happen when someone attacks you. This one happens with nobody attacking at all. Your own bug is sufficient.

And you usually find out when the invoice arrives.


1. Why it spikes — usage billing has no ceiling

Old shared hosting was "1,000 yen a month, use as much as you like." Overuse just made the site slow; the bill didn't change.

Modern cloud services are the opposite. You are billed for what you use, and there is no ceiling unless you set one. Under load nothing slows down — it scales, and you are billed accordingly.

That is a benefit by design: a sudden traffic spike doesn't take your service down. The catch, and the subject of this article, is that "more traffic" isn't always legitimate traffic.


2. The five patterns that spike

Pattern 1: AI API calls

The most dangerous.

OpenAI and Anthropic APIs have a per-request unit cost orders of magnitude above other cloud services, and it grows with the length of the input.

Dangerous implementations AI tends to write:

  • Resending the whole conversation history every time — each call gets more expensive as the conversation goes on
  • No limit on the length of text a user can submit — one long paste is expensive on its own
  • No cap on retries — a persistent error repeats the same call
  • Usable without logging in — anyone can call it, without limit

The last one bites hardest. Opening an AI feature without login "so people can try it" creates a window through which anyone can use AI on your money.

Pattern 2: image and video conversion

Image optimisation, thumbnail generation, video encoding. These are heavy, and many services bill per conversion or by data transfer.

The problem is the same image being converted repeatedly. Without caching — reusing what was already produced — a conversion runs every time the page renders.

Pattern 3: infinite loops

The quietest and fastest way to spike.

[what happens]
- process A calls process B, and process B calls process A
- a process triggered by a data update updates data itself
- a process that retries on failure keeps failing and retrying

The third is especially common. Ask an AI to "retry if an error occurs" and, unless you specify a limit, it may write code that retries forever.

Loops are invisible to you. They spin quietly on the server.

Pattern 4: bot crawling

A published site attracts search-engine and AI crawlers. That is normal.

But if you have many pages that contain heavy processing, crawlers walk all of them.

  • Search-result pages generated endlessly (?page=1 through ?page=99999)
  • A calendar feature generating infinite future dates
  • Filter combinations exploding the URL space

These produce "infinitely many URLs with effectively the same content," and crawlers dutifully visit them all.

Pattern 5: the moment you exceed a free tier

Finally, an assumption problem.

"I'm on the free plan, so no bill can arrive" — this differs per service.

  • Exceed the free tier and the service stops → no bill (but the service is down)
  • Exceed the free tier and billing switches to usage-based automatically → a bill arrives

Check which behaviour applies before you launch. Some services move to the second the moment you register a card.


3. Countermeasure 1: set a hard spending cap (highest priority)

This comes first.

Why "billing alerts" aren't enough

Many people set a billing alert and feel safe. But an alert only tells you that you overspent — it doesn't stop anything.

Suppose an infinite loop starts at 2am. The alert arrives at 2:30. You notice at 7am. That four and a half hours is billed in full.

What you want is not a notification but a hard spending cap.

Where to set it, per service

Vercel — the Spend Management feature lets you configure what happens when a monetary threshold is reached. Beyond notification, you can choose to pause deployments. Check the official documentation for which plans and options apply.

AI APIs (OpenAI / Anthropic and others) — the dashboard lets you set per-key and per-organisation usage limits. Set these without exception. Specify an amount and it stops there. Separating development and production keys and capping each is safer still.

Supabase — check the per-plan limits and how overage is billed. If a spend cap setting exists, enable it.

Cloud generally (AWS / GCP) — budget alerts are configurable, but automatic shutdown is not included by default. Automating a stop requires additional machinery.

Two things to confirm

For every service, confirm:

  1. What happens when the cap is reached — does it stop, or keep billing
  2. If it stops, how do you recover — the procedure at 2am

A "stop" setting means, by definition, "the service goes down." For a solo project, an unbounded bill is almost always worse than downtime — but that is a choice you should make yourself.


4. Countermeasure 2: add rate limiting

Where a spending cap sets the ceiling on damage, rate limiting stops the volume happening at all.

Rate limiting restricts how many requests one person can make in a period — "10 per minute per person," for instance.

With only a cap, the service stops. With only rate limiting, there is no ceiling. Both together give you a service that neither goes down nor runs up a bill.

Where to apply it

Not everywhere. Only where the cost is high is enough.

  • Anything calling an AI API ← highest priority
  • Image and video conversion
  • Anything calling a paid external API
  • Sending email
  • Heavy aggregation or search

Requiring login alone helps

Simply putting AI features behind a login materially reduces indiscriminate abuse. The wish to "open it up free so people can try it" is understandable — but if you open it, pair it with a usage limit.


5. Countermeasure 3: remove the causes in advance

Caps and rate limiting exist so that an incident doesn't hurt. Some prevention is cheap to add too.

Cap retries. Decide "three times, with a delay." Never retry forever.

Limit what you send to an AI. Set a character limit, and send only the last N messages of history.

Cache conversion results. Don't reconvert the same image every time.

Narrow what crawlers see. Use robots.txt to exclude search-result pages and filter-combination pages. Not generating infinitely many URLs with effectively identical content is a design question too.

Set timeouts. Don't wait indefinitely on an external service — you are billed while waiting.


6. The instruction to paste into your AI tool

List every usage-billed service this app depends on and produce a table with,
for each one:

(1) What is billed (request count, data transfer, execution time, tokens)
(2) A concrete scenario in which cost spikes unexpectedly
(3) The caps and alerts available in its dashboard

Then read the code and check for these dangerous implementations.

- Retries with no upper limit
- No limit on the length of input sent to an AI API
- Sending the entire conversation history every time
- Conversions that run every time because nothing is cached
- Expensive operations callable without logging in
- External calls with no timeout
- Places where processes may call each other (the seed of an infinite loop)

Finally, implement rate limiting on the highest-cost endpoints. Explain in plain
language which endpoints you limited, to what values, and why. I cannot read code.

7. A checklist for right after launch

  • Listed every service in use, free tiers included
  • Confirmed, per service, what happens when the free tier is exceeded (stop or bill)
  • Set a hard spending cap wherever one is available
  • Set a per-key spending limit on AI APIs
  • Set billing alerts (alongside caps, not instead of them)
  • Added rate limiting to high-cost operations
  • Put AI features behind a login, or added a usage limit
  • Capped retries
  • Set timeouts on external calls
  • Excluded infinitely-generated URLs in robots.txt
  • Look at the billing page once a day for the first week after launch ← the most effective item

That last one matters more than it looks. A spike almost always begins as a small anomaly. Looking daily means noticing on day one.


Summary

  • Usage billing has no ceiling. It spikes from your own bug, with nobody attacking
  • Five patterns: AI APIs, image and video conversion, infinite loops, bot crawling, the automatic switch after a free tier
  • AI APIs are the most dangerous — high unit cost, more expensive with longer input. Per-key caps are mandatory
  • Billing alerts are after-the-fact notifications. Use a hard spending cap where available
  • Rate limiting is needed separately. A cap is the ceiling on damage; rate limiting stops it happening
  • Look at the billing page daily for the first week. Spikes start small

This is a "right after launch" item rather than a "before launch" one, but deferring it comes back as a painful expense. Once the four pre-launch items are closed, this is next.

Frequently asked questions

Do large bills really happen on solo projects?
They do. Usage-based services bill for what you consume and have no ceiling unless you configure one. An infinite loop repeating the same operation, bots crawling large numbers of pages, or an AI API called several times per request can all land you orders of magnitude away from what the free tier led you to expect. No malicious attack is required — your own bug is enough.
What should I watch most closely?
AI APIs such as OpenAI and Anthropic. The per-request unit cost is far higher than other cloud services, and it grows with the length of the input. An implementation that resends the whole conversation history every time gets more expensive per call as the conversation goes on. Set a per-key spending limit and cap input length in the app.
Are billing alerts enough?
They are not. An alert tells you that you have overspent; it does not stop anything. Billing continues while the notification travels and until you notice. A runaway that starts at 2am bills for every hour until morning. Where a service offers a hard spending cap, use that rather than a notification.
What is rate limiting, and why is it separate from a spending cap?
Rate limiting restricts how many requests one person can make in a given period. Where a spending cap sets the ceiling on damage, rate limiting stops the volume occurring at all. With only a cap, the service stops; with only rate limiting, there is no ceiling. Both together give you a service that neither goes down nor runs up a bill.
Am I safe as long as I stay inside the free tier?
Not necessarily. Many services either switch automatically to paid billing once the free tier is exceeded, or stop the service. Which of the two happens differs per service, so check before you launch. 'I'm on the free plan, so no bill can arrive' is a classic entry point to this kind of incident.

References

友田

友田 陽大

Developer of a METI Minister's Award–winning product. With TypeScript + Python + AWS, I deliver SaaS, industry DX, and production-grade generative AI (RAG) end to end — from requirements to infrastructure and operations — single-handedly.

“It works. But is it safe to launch?”

Twenty questions, no signup — a pre-launch self-check for the app you built with AI

You don't need to read any code. Answer yes / no / not sure to questions like “can only the person who logged in see their own data?” You get your risks ordered by severity, plus a fix instruction you can paste straight into Claude Code or Cursor. Nothing you type leaves your browser.

Available for both project-based (contract) and advisory engagements. Start with a free 30-minute consult.

最短ルート:カレンダーから直接予約

相談内容が固まっている方は、フォーム送信よりその場で日程を確定する方がスムーズです。下記から空き時間をお選びください。

  • 30分のオンライン無料相談
  • Google Meet / Zoom / Microsoft Teams
  • NDA 商談前締結可・無理な営業はいたしません
無料相談の空き枠を予約する

Also worth reading