Model denial of wallet: runaway token spend and how to cap it
LLM features cost money per token, so abuse or loops become a billing incident. How to set per-user quotas, input and output limits, loop guards for agents, and spend alerts before the invoice arrives.
Diagram
How costs run away
Step 1 of 4
Input
A public endpoint accepts very long inputs.
POST /api/summarize body: 480,000 characters
The example on the open step is one illustration, or the fix you can paste into an application you own.
What this page is made of
3 pieces. Each one says what fails, who is affected, what you would notice, and what you change.
Unbounded input
- What fails
- Long inputs multiply cost and latency.
- Who is affected
- The budget, and other users through slowdowns.
- What you would notice
- No max length on prompt fields.
- What you change
- Cap input size and reject oversized requests early.
Agent loops
- What fails
- Agents can loop on errors, calling the model again and again.
- Who is affected
- The budget and downstream tools.
- What you would notice
- Conversations with hundreds of steps.
- What you change
- Set step and retry limits and stop on repeated errors.
Anonymous access
- What fails
- Free, unauthenticated endpoints get scripted.
- Who is affected
- The business paying for the tokens.
- What you would notice
- Spend from many new or anonymous accounts.
- What you change
- Require sign-in, rate-limit per account, and add abuse checks.
Alerting on spend
Provider dashboards update with a delay, so measure tokens at your own gateway. Alert on rate of change compared with a baseline, and give on-call a kill switch that disables the feature.
Check yourself
Recognition and the fix. Nothing here is a procedure.
Spend jumps 70x in an hour. What lets on-call stop it fastest?
Sibling techniques
Pages at the same depth, plus a lab and a glossary card for this one.
This page stands on its own. The lab and the glossary card are the next reading.