Securing AI applicationsMiddleLesson 1416 min read

Unbounded consumption: denial of wallet

Every model call costs money. Without limits, one attacker, one bot or one bug in a loop can burn your budget or take the feature down for everyone.

Lesson in motion

In 60 seconds

Unbounded consumption: denial of wallet

Every model call costs money. Without limits, one attacker, one bot or one bug in a loop can burn your budget or take the feature down for everyone.

1/4
In simple words
A park has a free water tap. If one person fills a tanker from it, others get nothing and the city pays the bill. An AI feature is a tap with a meter on it.
Each model call uses tokens, the small pieces of text the model reads and writes, and you usually pay for both. OWASP's LLM10 Unbounded Consumption covers what happens when use has no limits: huge bills (denial of wallet), slow or failed service for real users, and even attempts to copy a model's behaviour through very large numbers of queries.

How consumption gets out of control

PatternExampleControl
Huge inputsPasting a whole book or a giant file into the chatInput size limits; count tokens before calling the model
Huge outputs"Write a 100,000-word story"A maximum output token setting on every call
LoopsAn agent calls tools again and again; retries on every errorMaximum steps, maximum time, retry limits with backoff
Many requestsA script hammers your free chatbotSign-in, per-account rate limits, bot protection
Free general-purpose usePeople use your shop bot as a free all-purpose AIKeep the bot on topic; quotas per user
Expensive defaultsThe largest model and 20 retrieved chunks for every questionPick the model by task; cap retrieved chunks
Exposed keysModel API key inside the mobile app or web pageKeep keys on the server; call the model from your backend

Layers of limits

  1. 1

    Per request

    Max input size, max output tokens, timeout, max tool steps.
  2. 2

    Per user

    Requests per minute and tokens per day, per account.
  3. 3

    Per feature

    A monthly budget for each AI feature, tracked separately.
  4. 4

    Organisation-wide

    Spend alerts at set levels, and a hard cap if your provider supports it.
  5. 5

    Kill switch

    A tested way to turn the feature off or fall back quickly.
Python: simple per-request and per-user budget checkspython
MAX_INPUT_CHARS = 8_000
MAX_OUTPUT_TOKENS = 800
DAILY_TOKENS_PER_USER = 50_000
REQUEST_TIMEOUT_S = 30
MAX_AGENT_STEPS = 6

class BudgetExceeded(Exception):
    pass

def check_budget(user_id: str, text: str, usage) -> None:
    if len(text) > MAX_INPUT_CHARS:
        raise BudgetExceeded("message too long")
    if usage.tokens_today(user_id) >= DAILY_TOKENS_PER_USER:
        raise BudgetExceeded("daily limit reached, try tomorrow")

def after_call(user_id: str, tokens_used: int, usage) -> None:
    usage.add(user_id, tokens_used)   # record real usage from the API response
The numbers above are examples. Choose yours by measuring normal use first, then setting limits comfortably above what honest users need. Tell users clearly when they hit a limit.

Caching and cheaper paths

Many questions repeat: "What are your delivery charges?" A cache of answers to common questions saves money and time. But cache keys must include anything that changes the answer or who may see it, such as tenant and permission scope. A careless cache can serve one user's private answer to another.
Watch out
Rate limits by IP address alone work poorly. Many mobile users in India share IP addresses through their network provider, so an IP limit can block honest users while a bot network spreads across many addresses. Limit by account where you can, and use IP only as one signal.
Note
Many model providers offer usage limits, spend alerts or separate project keys. Check what yours offers and turn them on. They are a safety net under your own limits, not a replacement.
Try this. For one AI feature, find out: what is the largest single request it can make, and what is the most one user could spend in a day? If you cannot answer, that is your first task.

Watch and read more

Lab

A one-page cost budget with limits, alerts and actions for a free AI feature.

~30 min

The problem

The feature: a free exam-preparation chatbot for a college with about 20,000 students. Use an imaginary price that you write down clearly, for example "₹X per million input tokens and ₹Y per million output tokens". Do not look up or claim real prices.

  1. Estimate normal use: questions per student per day, tokens per question in and out. Write your assumptions.
  2. Calculate an expected monthly cost from your assumptions.
  3. Set limits: per request (input, output, timeout), per user per day, and a monthly feature budget.
  4. Set alerts at 50%, 80% and 100% of the budget, and write what happens at each (who is told, what changes).
  5. Describe the kill switch: who can press it and what students see.

You are done when

Hard questions

Try to answer before you reveal. If you can answer these, you understood the lesson.

Q1Exam week arrives and honest usage triples. Your 80% alert fires on day 20 of the month. What do you do, and what should you have planned?Reveal

Look at the data first: is it many students using it normally, or a few accounts using far more? If honest, choose a planned response: a cheaper model for simple questions, shorter answers, caching common questions, or a budget increase approved by the owner. Good planning expects seasonal peaks like exams and sets the budget and limits for them in advance.

Q2Why can an agent loop cost far more than a normal chat, even with the same per-call output limit?Reveal

Because each step is a separate call, and each call re-sends the growing context: instructions, history and tool results. The input tokens grow step after step. Ten or fifty steps can cost much more than one answer. Limits on steps, total time and total cost per task are what stop it.

Please sign in to continue.

Questions people ask

What is a token?

A small piece of text, often part of a word. Models read and write text as tokens, and most providers price by tokens in and tokens out. Text in different languages can use different numbers of tokens for the same meaning.

How do we choose limits without annoying real users?

Measure first. Look at how much normal users actually send and receive, then set limits well above that. Give clear messages when a limit is hit, and offer a way to ask for more if there is a real need.

Is caching safe for AI answers?

For public, non-personal answers, usually yes. For anything personal or permissioned, include the user or permission scope in the cache key, or do not cache. Also clear cached answers when their source documents change.

Should agents have a time limit?

Yes. Agents can loop, retry and call tools many times. Set a maximum number of steps, a maximum total time and a maximum cost per task. When a limit is hit, stop and report, instead of trying forever.

Lesson test

5 questions. Get 3 right (60%) to pass and complete this lesson.

Sign in to take the test and save your progress