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.

Lesson 46 of 69 · 10 min read · practice only with authorization

Diagram

How costs run away

Follow the path. One example at a time.

Step 1 of 4

Input

A public endpoint accepts very long inputs.

Illustration: Input
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.

  1. 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.
  2. 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.
  3. 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.

1 / 3

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.

Practice

  1. LabControl benchA failure is described. Choose the control that changes the outcome.

Glossary

  1. CardModel denial of walletAutomated calls run up a bill or exhaust a quota.