LLM cost and abuse controls: stopping denial-of-wallet
LLM cost control against abuse: cap every request, budget each user and IP in your own spend ledger, then set a hard provider limit. Alerts do not stop a bill.
Asghar Ali · Chief Technology Officer, Kakushin.io LTD
LLM cost control against abuse comes down to four limits, each stopping something the others miss: a cap on every request (input size, output tokens, agent steps), a budget per user and per IP kept in your own spend ledger, a ceiling for each AI feature, and a hard spend limit at the provider as the last line. Alerts tell you about a bill. Only a cap that halts inference stops one. Then read the ledger, because abuse has a shape you can see long before the invoice.
This is for the founder or developer who has put a language-model feature in front of the public: a chat box, a summariser, a free tier, an agent. It covers what OWASP calls Unbounded Consumption, why provider limits do not protect you user by user, the order to add controls, what to record per call, what abuse looks like in the logs and how to test it. For where cost sits among the other risks, see the OWASP Top 10 for LLM applications in a real product.
What is a denial-of-wallet attack on an AI feature?
It is the cost version of a denial of service: instead of taking your feature down, someone makes it expensive. OWASP covers it under Unbounded Consumption, LLM06 in the 2026 edition of its LLM Top 10 (published 3 August 2026; it was LLM10 in the 2025 list; read on 1 December 2026). The entry names cost asymmetry as "a defining characteristic of this threat": a request that costs the sender almost nothing can cost you a lot of computation.
Volume is only one shape: the entry also lists near-limit context, short prompts that send reasoning models into long thinking, agents stuck in tool-calling loops, and bulk querying to copy a model.
Two lines from it shape everything below. "Traditional request-rate limiting alone is no longer sufficient": one request can cost far more than another, so limits have to count tokens and estimated cost. And spending caps should halt inference rather than raise alerts, because a fast workload can outrun an alert. NIST's Generative AI Profile (AI 600-1, July 2024) treats the availability of the system as part of information security for generative AI, and OWASP's API4:2023 Unrestricted Resource Consumption already calls an API vulnerable when a third-party provider's spending limit is missing or set wrongly.
Why is the provider's spend limit not enough?
Because it protects your account, not your users from each other. OpenAI's rate limits guide says its limits are set at the organisation and project level, "not user level", and recommends a usage limit for individual users, daily, weekly or monthly (read on 1 December 2026). Anthropic's rate limits page works the same way: limits for the organisation and, if you set them, for each workspace (read on 1 December 2026). Neither limits each of your customers for you.
So a provider cap alone turns a denial-of-wallet into a plain denial of service: the bill stops, and so does the feature for every customer. You still want it as the floor, and the details matter:
- Alerts are not caps. OpenAI's spend limits guide says spend alerts do not enforce a cap. A hard limit on the organisation or a project makes requests fail with a 429 and an
organization_spend_limit_exceededorproject_spend_limit_exceededcode. Enforcement "is not instantaneous", so recorded spend can slightly exceed the limit. - Know the error you will get. On Anthropic, a spend limit you set returns HTTP 400 with
invalid_request_error. Reaching your tier's monthly cap returns a 429 with noretry-afterheader. Treat both as "feature paused", not as something to retry. - Check what the limit covers. Anthropic notes that a default-workspace spend limit might not count some usage, such as the Console playground. Give production its own project or workspace, key and limit.
Which limits should a small AI product set first?
Four layers, from the cheapest check to the last resort.
| Layer | What it limits | Where it lives | What happens when it trips |
|---|---|---|---|
| 1. Per request | Input size, output tokens, reasoning budget, agent steps and run time | Your server, before the call | Rejected with a clear message, nothing spent |
| 2. Per user and per IP | Tokens and estimated cost per day and per month, requests per minute | Your spend ledger | That user or IP is throttled or paused; everyone else carries on |
| 3. Per feature | Total estimated cost per day for each AI route | Your spend ledger | That feature degrades: cached answers, a queue, a "back tomorrow" note |
| 4. Provider hard limit | Monthly spend for the project or workspace | The provider's console | Every request in that project fails until the limit is raised or the month resets |
The order to add them in a small product:
- Today: the provider hard limit on a dedicated project or workspace, above a normal month and well below one that would hurt.
- Per-request caps. A maximum output length on every call, oversized inputs rejected before sending, and for agents the step, recursion depth, time and per-run cost limits that OWASP's 2026 entry asks for. Least privilege for agent tools covers the rest of an agent's leash.
- The ledger, in log-only mode for a week, so you learn what a heavy but honest user costs before you pick a number.
- Per-user and per-IP budgets, enforced: above your heaviest honest users, well below what a script would spend. Anonymous and free tiers get the tightest.
- Per-feature ceilings and alerts, so a new pattern reaches a person long before the provider limit trips.
If the model sits behind a relay proxy, as it should when the client is a mobile or browser app, these limits belong on the relay: API keys in mobile apps explains why the proxy needs them.
What goes in a spend ledger?
One row per model call, written by your server: who spent it, on what, and was it normal.
- Who: user ID (or a session ID for logged-out visitors), the client IP or its network prefix, the API key or tenant.
- What: the route, the model, input tokens, cached input tokens, output tokens, reasoning tokens where the provider reports them, the number of tool calls, and the finish reason (did the answer end by itself or hit the length cap?).
- Cost: your estimate before the call and the actual figure after it, from the usage the provider returns.
- Outcome: allowed, throttled, blocked or whitelisted, with the rule that decided it.
Two design choices make it a control rather than a report. Reserve, then settle: before the call, estimate the worst case (input tokens plus the maximum output you allow, at that model's price), check it against every budget the request falls under, and reserve it; after the call, replace the reservation with the real figure. OWASP's entry asks for this pre-flight estimate, so a request is rejected before inference begins. Check atomically: otherwise ten parallel requests each see enough budget left and all ten go through.
Keep prompts out of the ledger by default; a hash is enough to spot repetition. Treat IP addresses as personal data, with a retention period. OpenAI's safety best practices suggest sending a hashed user identifier with each request (safety_identifier).
What does abuse look like in the logs?
It shows up as a pattern in the ledger long before the bill. No single signal proves abuse; together they tell you where to look.
| Signal in the ledger | What it often means | First response |
|---|---|---|
| One IP or network prefix behind many new accounts or sessions | Sign-ups used to reset per-user budgets | Budget per IP and prefix as well as per user; slow down sign-up |
| A steady request rate through the night, every night | A script, not a person | Throttle, then review the account |
| Output stops at the length cap on most calls | Someone pushing for maximum output | Lower the output cap for that route; check what the prompts are for |
| Inputs always just under the size limit | Large-context abuse: within limits, inflating cost | A cost-based budget, not only a size check |
| Reasoning tokens far above the route's baseline | Prompts that send a reasoning model into long thinking | A reasoning budget per call |
| Agent runs with many tool calls or repeated identical steps | A loop | Step limit, per-run cost ceiling, stop on repeated state |
| Requests unrelated to the feature, such as general chat in a summariser | Your feature used as a free model | Narrow the prompt and accepted inputs; per-user budget |
| Large numbers of varied, systematic queries | Possible copying of the model's behaviour, which OWASP lists as distillation | Volume caps per account; review |
Two actions earn their place in the admin screen. Block stops an IP, a prefix or an account at layer 2 without touching anyone else. Whitelist exists because IP limits are blunt: an office or a mobile network can put many honest people behind one address. Log who blocked or whitelisted what, and when.
How do you test that the controls work?
On your own app, in staging, with budgets turned right down. You are checking that each layer trips and fails safely.
- Send an input over the size limit: it is rejected before any model call, and the ledger shows nothing spent.
- Use one test account until its budget runs out: it gets a clear message while a second account carries on.
- Repeat from one IP across several new test accounts: the IP or prefix budget trips.
- Run an agent task with the step limit set low: it stops at the limit and says so.
- On a staging project only, set the provider limit just above current spend: the app shows a paused state, does not retry in a loop, and alerts someone.
- Confirm every alert reached a person, not just a dashboard.
A worked example (illustrative)
An invented case, not a client: a small SaaS adds a free "summarise this PDF" box to its marketing site. No login, one provider key on the server, a hard limit on the provider project.
Three weeks in, the ledger shows most of a day's cost coming from a handful of network prefixes, steadily through the night, with output hitting the length cap and inputs no one would want summarised. Nothing has tripped: every request is within the size limit.
The team blocks the prefixes, lowers the anonymous IP budget, caps output for the route and asks for an email address before a second summary in a day. The ledger returns to its normal shape. The provider limit was never reached, which was the point: had it been, every paying customer would have lost the feature too.
What these controls cannot tell you
- Intent. A heavy honest user and a careful abuser can look alike. Budgets limit the damage either way; deciding which is which needs a person.
- Who is behind an IP. Proxies spread one script across many addresses, and many honest people share one. IP budgets are a layer, not an identity.
- The exact bill. Your estimate is not the invoice. Reconcile the ledger with the provider's usage figures.
- The other risks. A spend ledger does nothing about injected instructions or data leaking through answers. Prompt injection testing is a separate job.
Frequently asked questions
What is denial of wallet in an AI app?
An attack, or an accident, that runs up your model bill instead of taking the service down. OWASP lists it under Unbounded Consumption, LLM06 in the 2026 edition.
Is the provider's spending limit enough on its own?
No. It caps the account, not each user, so when one script reaches it every customer loses the feature. Keep it as the last layer.
Should I limit by user or by IP?
Both. Per-user budgets are fair to people behind shared addresses, but free sign-ups make new users cheap. Per-IP budgets catch account farming and anonymous traffic; a whitelist covers the honest networks they would hurt.
How do I choose the first budget numbers?
From your own ledger, not someone else's defaults. Log a week without blocking, see what your heaviest honest users spend in a day, and set the per-user budget above that. Review it monthly.
Do AI agents need different limits?
Yes, because one request can fan out into many model and tool calls. Give every run a step limit, a time limit and a cost ceiling, and stop it when it repeats the same state. OWASP calls these agentic circuit breakers.
If you want this checked
On a reference app I built AI spend controls around a per-IP ledger, abuse heuristics, and block and whitelist actions. On the customer apps of a European national electricity utility I introduced a relay-proxy architecture that removed every client API key from the shipped binaries. Spend limits are one of the AI-feature checks in a security review of an AI-built app. I can review where your model calls are exposed, which limits are missing and what your logs already show. The scope is on my hire page.