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.
max_tokens), trim chat history, and reject oversized uploads before they reach the model.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.
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.
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.
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.
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.
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.