Guides

How to stop one user from running up your OpenAI or Claude bill

In short: count AI cost per user on your backend, give each user a daily and 30-day budget, refuse AI calls past it, rate limit bursts, and alert on tokens per user per five minutes to catch loops. Provider limits are a last line of defence for the whole account, not a per-user control.

Four layers, cheapest first

  1. Limits on the request. Cap reply length (max_tokens), trim chat history, and reject oversized uploads before they reach the model.
  2. Rate limits. A few requests per user per second or minute stops scripts and double-clicks. It does not stop a slow, steady heavy user.
  3. Per-user budgets. A dollar budget per user per day and per 30 days, checked before each call. This is the layer that actually caps cost per user. Plan allowances for free and paid users belong here too: limits by plan.
  4. Account limits and alerts. Keep the provider's monthly limit as a backstop, and alert on daily spend for the whole app.

Catch loops in minutes, not at month end

Daily budgets react too late for an agent stuck in a retry loop. Alert, and ideally block, when one user uses more tokens in five minutes than a real person could. Send the alert to Slack or email so someone sees it immediately.

With FiscaLLM

One line after each AI call reports token counts. In Settings you set per-user budgets (today and 30 days), tick Block to make them a cap, and turn on the runaway-loop alert. Before each call your backend asks meter.check(userId) and gets allow or refuse; the SDK also counts locally, so a loop is stopped even if FiscaLLM is unreachable. Free and open source: spending caps reference · alerts.

Before launch

Decide what one user may cost you on each plan. The pricing planner gives a monthly limit per plan that keeps your target margin; the daily cap can be that number divided by 30, times a few for headroom.

Questions

Doesn't OpenAI's usage limit already protect me?

It protects the account: when the organization hits its limit, every user is cut off, including paying ones. It cannot tell which user caused the spend. You need a per-user budget in your own backend.

What is a runaway loop?

An agent or retry loop that keeps calling the model without a human in between, often because a tool call fails and is retried forever. It can spend in minutes what a normal user spends in a month. Detect it by tokens per user per few minutes, not per day.

Should a cap fail open or closed?

Tracking should never block your app. A cap is different: it should refuse once the user is past the budget, and keep refusing even if the tracking service is briefly unreachable, by counting locally too.