DEV Community

Cover image for One Unprotected AI Endpoint Can Drain Your Startup's API Budget Overnight

One Unprotected AI Endpoint Can Drain Your Startup's API Budget Overnight

𝗝𝗼𝗡𝗻 on December 01, 2026

I put a standard 20-requests-per-minute IP rate limiter in front of a prototype /api/summarize route and assumed my API credits were safe. To verif...
Collapse
 
nyaomaru profile image
nyaomaru The Startup CafΓ© •

Great article, John! πŸ˜ΈπŸ’š

Your article got me thinking about how we could manage token budgets across concurrent requests. Reserving an estimated budget before each LLM call and adjusting it based on actual usage afterward might be another interesting approach!

Thanks for sharing such a practical topic! 🐈

Collapse
 
johnnylemonny profile image
𝗝𝗼𝗡𝗻 The Startup CafΓ© •

Reserving an estimated token slice upfront and reconciling the delta once the response finishes is a smart way to keep concurrent calls from blowing past a shared budget. Glad the post resonated with you.

Collapse
 
murali_gour_13cd7a6a6db2c profile image
Murali Gour •

The one that gets people with agents is the retry loop. A tool errors, the model tries again, and every retry resends the whole context, so the bill grows fast. Cap steps per task and total tokens per run, not just requests per minute.

Collapse
 
johnnylemonny profile image
𝗝𝗼𝗡𝗻 The Startup CafΓ© •

Agent retry loops are brutal because every attempt replays growing history on top of an already expensive step. Putting a hard ceiling on steps and total run tokens stops an agent from quietly burning through a task budget in circles.

Collapse
 
gautamtalksdev profile image
Gautam K •

Great that you tested it instead of trusting it. The 20 per minute IP limit looking fine until all 10 requests came back 200 is exactly the kind of thing people only find on the invoice. Per user or per key limits plus a hard daily spend cap feel like the real floor here.

Collapse
 
johnnylemonny profile image
𝗝𝗼𝗡𝗻 The Startup CafΓ© •

Spot on. Seeing those 200s stack up locally saved me from a painful surprise later. Per-key or per-user tracking paired with a hard spend cap really is the baseline before anything goes public.

Collapse
 
robertpaschal profile image
Odinaka Robert Nnamani •

the user closes the tab and the server keeps generating tokens nobody reads. ten requests, 160,000 tokens, and the bill runs overnight.

Collapse
 
ric0c0derlab profile image
Ric0 C0der Lab •

Per-user quotas and a hard spending ceiling seem like a good combination here. Rate limits alone don't necessarily prevent a costly runaway workflow.

Collapse
 
aheadkit profile image
AheadKit •

The 10 requests β†’ 160k tokens test is the number that should scare people, because 20 RPM sounds perfectly safe until you do that multiplication. The abort-propagation half is the one I'd bet most people skip β€” in our own browser-agent runs I watched a single long-page read cost 25,958 tokens one run and 37,848 the next on the same unchanged page, just because the page was still settling. Nothing in a request-count limiter would have caught any of that. Do you cap per-session token totals too, or is the output cap doing all the work?

Collapse
 
andrii_0308f2a18c503d78ec profile image
Andrii •

One important detail: the input validation happens after req.json() has already consumed and parsed the request body. Unless the hosting layer enforces a payload limit, a massive JSON request can still consume significant server memory before reaching the validation logic. I'd enforce a strict body-size limit at the gateway or framework level, rather than relying solely on prompt-length validation. Are you handling this at the infrastructure level or directly inside the application?

Collapse
 
paullovelace profile image
Paul Lovelace •

The orphaned generation bit is the one that got me β€” the user closes the tab and the server just keeps minting tokens nobody reads. I've wired AbortSignal through before and the annoying part was the SDK swallowing it halfway. Does yours actually propagate the abort, or did you have to drop down to raw fetch to make it stick?

Collapse
 
the_daily_flare profile image
The daily flare •

How did I miss that ten requests in 30 seconds could burn 160,000 tokens while every response still returned 200 OK?