Putting budgets on what AI agents spend on model calls
Provider spend limits are set by the month, for a whole organization, workspace or project, so every agent on the same key shares one number. Statio now meters each agent's model calls and refuses the next one once its daily budget is spent, before the request reaches the provider.
An agent stuck on a failing tool keeps calling the model. Each turn bills the whole conversation again as input, a little longer than the last time, so the calls get more expensive while the agent gets nowhere. Usually nobody notices until the invoice arrives, or until the provider's monthly cap stops every other agent on the same key.
A proxy in front of the providers can stop that. What is an LLM gateway? covers what else one does.
What the providers let you cap
Both of the large providers have spend limits, and both count by the month.
Anthropic gives each usage tier a monthly spend cap, and its rate limits page lets you set your own organization limit below it. Workspaces can have spend limits of their own, though the default workspace can't. Once a limit you set is reached, requests return a 400 invalid_request_error until access resumes or someone raises the limit.
OpenAI's rate limits guide offers spend alerts, which send a notification while traffic continues, and hard spend limits, under which affected requests return a 429. You set either one for the organization or for a project, to control monthly API spend.
Keep those limits as a backstop. For agents they are coarse. A limit belongs to the organization, workspace or project behind the key, so ten agents in one project draw on the same number, and the shortest window is a month. If a support bot uses up the project's money on the 4th, the other nine stop with it. The provider only sees the key, so it can't say which agent it was.
Why the check comes before the call
A report of yesterday's spend can't hold a limit. Something has to refuse the next call, and since the provider bills a call when it runs it, the refusal has to happen before the request leaves.
Whatever does the refusing needs two things. It has to see every call, so the agent calls it in place of the provider. And it has to know what each call cost from the usage the provider reports on the response, streamed responses included. A guess from the prompt's length misses the output, which is the expensive half: in Statio's price table, Claude Opus 5.5 output costs five times its input.
Three kinds of 429
A capped call comes back as a 429 whoever capped it. Anthropic's own spend cap answers with rate_limit_error, the same type as an ordinary rate limit, and the docs tell you to read error.details.error_code (enforced_spend_limit_reached) to tell them apart. A gateway that refuses in the provider's error format adds a third 429 of the same type.
The SDK is better off that way, since it shows the message instead of failing to parse the response. The person reading failures later needs them kept apart. A rate limit means slow down and retry. A spent provider cap means every agent on that key has stopped. A budget refusal means one agent reached the limit you gave it, and nothing is wrong with the provider. If all three count as errors, your error rate jumps on the day a budget works.
How Statio meters model calls
An admin adds the provider once, under Models, with the organization's key. The key goes into Statio's vault, and agents never see it. Then you mint a proxy key (sk-statio-…) for an agent or a person. It is shown once and stored only as a hash. The agent changes its base URL and its API key:
# Claude Code and the Anthropic SDK both read these
export ANTHROPIC_BASE_URL=https://api.statio.dev/llm/anthropic
export ANTHROPIC_API_KEY=sk-statio-...
The Keys tab prints this with your URL and key filled in, along with the Python setup for the Anthropic and OpenAI SDKs. The proxy handles Anthropic's Messages API, OpenAI's Chat Completions and Responses APIs, and any OpenAI-compatible provider an admin adds by base URL, such as OpenRouter, Groq or a vLLM server. Any other path under a provider gets a 404 listing the supported ones, so nothing goes through unmetered.
Usage is read off the response as it streams back, without buffering or changing it. On an OpenAI stream the proxy asks for the final usage chunk if the caller didn't. Cache reads, cache writes, reasoning tokens and Anthropic web searches are all counted. Cost comes from a price table in which every row names its source page. A row matches the exact model ID or a dated snapshot of it, never a model with a similar name, and money is kept in integer picodollars so a million summed calls come out exact. Prompts and completions are never stored. Each call's record holds the model, tokens, cost, latency and status.
If the caller hangs up mid-stream, Statio cancels the upstream request so you aren't billed for output nobody will read, and records the call as partial with the tokens reported so far. Statio also adds no markup and resells no tokens. Calls go out on your provider key, and your provider bills you as before.
How the budgets work
A budget is a dollar amount per UTC day for one agent, one person or the whole organization. Before forwarding a call, the proxy checks every budget that applies to the caller. An agent's call is tested against the agent's budget and the organization's, and its cost counts once.
If one is spent, the call stops at Statio. The agent gets a 429 in its provider's own format, rate_limit_error for Anthropic and insufficient_quota for OpenAI-compatible providers. The message starts with "Statio:", names the budget and says when it resets. The response carries x-should-retry: false so the SDK doesn't retry a refusal that will last until midnight UTC. The provider never sees the request, and the refusal is recorded.
A budget is a hard stop for new calls, with one exception. Calls already running when the limit is reached still finish, so spend can go past a budget by what those calls cost. A tighter bound would mean reserving cost before every call, and I left that out.
In two other cases the proxy refuses where it could have guessed. A model with no price is refused while a budget applies to the caller, because a budget that can't count a call can't hold it. And if the budgets can't be read, the call gets a 503 and is not forwarded.
Each budget raises an alert at 80% and at 100%, once per period. Alerts show on an Alerts tab and as a banner on Models and Overview, and they go to the audit log. On Business and up, a webhook destination can opt in to budget.threshold_reached and budget.exhausted events.
What the spend dashboard shows
The Spend tab charts spend hourly, daily, weekly or monthly, by team, agent, model or provider. Every view groups the same ledger of calls, so team totals plus "Unassigned" always equal the organization's total. A call keeps the team its agent had at the time, and moving the agent later leaves past spend where it was.
The Failures tab charts provider errors, refusals by Statio and streams cut off as three separate series, with the top error types by provider and model.
The proxy can only count calls that go through it. The Fleet page has an Outside Statio section, on Team and up, listing the MCP servers and plugins on members' machines that don't route through Statio, as the desktop app reports them. The page also says that model calls made without a proxy key can't be seen there.
Questions
Give one agent a daily model budget. Budgets are on every plan, including Free.