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!
Freelance fullstack developer creating fast, modern, and refined applications. I focus on simplicity, performance, and real value for users. I also write tech-related articles here.
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.
AI/ML Product Marketer & Manager building enterprise AI agent platforms that connect messy real-world tools (SAP, Salesforce, ERP) to LLMs without the usual integration headaches.
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.
Freelance fullstack developer creating fast, modern, and refined applications. I focus on simplicity, performance, and real value for users. I also write tech-related articles here.
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.
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.
Freelance fullstack developer creating fast, modern, and refined applications. I focus on simplicity, performance, and real value for users. I also write tech-related articles here.
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.
I measure AI coding claims in public. LGTM β Let's Get the Measurements: real runs, real numbers, receipts. Every article is an experiment I actually ran. Books & packs: aheadkit.gumroad.com
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?
Full-stack & Shopify developer building fast, conversion-focused stores and custom web apps with Liquid, React, and Node.js. Sharing what I learn along the way.
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?
I research AI tools, APIs & agents β comparing specs, pricing and real user reports β then publish honest rankings so you don't waste money. Research-first, never sponsored fluff.
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?
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! π
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.
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.
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.
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.
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.
the user closes the tab and the server keeps generating tokens nobody reads. ten requests, 160,000 tokens, and the bill runs overnight.
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.
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?
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?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?
How did I miss that ten requests in 30 seconds could burn 160,000 tokens while every response still returned 200 OK?