Agent Budgets
4
Agents with budgets
1
At 90% or more
0
Over budget
| Agent | Monthly budget | Spent this month | When spent | Model |
|---|---|---|---|---|
| Ticket triage | $400 | $362 (91%) | Switch to cheaper model | Main model |
| IT access | $150 | $41 (27%) | Ask for approval | Main model |
| CRM hygiene | $250 | $198 (79%) | Stop until next month | Main model |
| Invoice matching | $300 | $120 (40%) | Ask for approval | Main model |
What matters here
- On Tray Helix you set your own budget per agent, enforced in the app, from the token usage the model provider returns on every call.
- Record the model and the input and output tokens of every call, priced at the rates you pay for that model.
- Check the budget before each run starts, so an agent can't spend past it unnoticed.
- Choose what happens when the budget is spent: stop, switch to a cheaper model, or ask a person to approve the run.
- Your agent analytics app can show spend against budget per agent, next to the outcomes that spend produced.
Who this is for
You own agents in production and someone has asked what they cost and what stops them costing more. You want a limit per agent that you set, not a surprise at month end.
How it works in practice
From a model call to a run that stops when it should.
- 1
Every model call returns usage
Model providers return input and output tokens on each call.
- 2
The agent records it
Agent, run, model and tokens go into the app's database, priced at the rate for that model.
- 3
A check runs before each run
It adds up this month's spend for the agent and compares it with the budget.
- 4
The rule applies
Under budget, the run goes ahead. Spent, it stops, switches model or waits for approval.
- 5
Owners see it coming
A Slack notice at 80% of budget gives the owner time to decide.
What per-agent budgets are made of
A usage record, a rate table, a check and a rule.
A usage record
Each model call: agent, run, model, input tokens, output tokens and time.
A rate table
The price per million input and output tokens for each model, as you pay it. Editable.
A pre-run check
Before each run, this month's spend for the agent against its budget.
A rule per agent
What happens when the budget is spent: stop, switch to a cheaper model, or ask for approval.
The prompts
Paste these into Claude Code, Codex or Cursor in order. Each one leaves you with something that runs, so you can stop after any step.
These prompts start from a Helix project, which is what handles sign-in, credentials and hosting. Start with Helix.
Record usage on every call
The numbers a budget depends on.
In my Helix app, record the usage of every model call the agent makes.
Store the agent, the run, the model, input tokens and output tokens as the model provider returns them, and the time.
Keep a rate table I can edit: price per million input tokens and per million output tokens for each model we use. Price each call from it.
Budgets and the pre-run check
Stop spending before it happens.
Add a monthly budget per agent, and a rule for when it is spent: stop until next month, switch to a cheaper model I name, or ask for approval before each further run.
Before every run, add up the agent's spend this month and compare it with the budget. Under budget, run as normal. Over budget, apply the rule. Record each decision with the spend and the budget at the time.
At 80% of budget, post the agent's owner in Slack once.
The budgets view
Spend against budget, per agent.
Show a budgets view: each agent, its monthly budget, spend this month as an amount and a percentage, the rule, and the model it is running on now. Show a history of budget decisions, and let owners edit their own agent's budget.
Connect it to real systems
Where the warnings go.
Now connect it to the systems we actually run.
Anything in angle brackets is a placeholder. Swap it for whatever we use.
<Slack>. Warn owners at 80% of budget and when a budget is spent.
Ship it
A URL, and the owners on it.
Deploy my app.
What it connects to
The usage comes from the model calls. Everything else is in the app.
- Model provider Return input and output tokens on every call, such as Claude, OpenAI or Bedrock. Reads
-
Slack Warn the owner at 80% of budget and when the budget is spent. Writes
Named systems are the ones most teams actually run, not a list of the only ones that work. Swap in whatever you use.
Running it for real
The build gets you budgets you set. Running it means changes are reviewed and spend is visible next to outcomes.
- 1
Budget rules ship with the agent
The check is code in the app, so it deploys from CI, deploy approvals gate changes, and you can roll back any deployment.
- 2
Owners set their own budgets
SSO and access control decide who can change an agent's budget, and each change is recorded.
- 3
Model keys held by Tray
Model and system credentials are held in Tray, not in the code.
- 4
Every budget decision logged
Each pre-run check and its outcome is recorded, and Tray streams agent logs to your SIEM.
- 5
AI usage per app
Tray shows AI usage per app, next to the per-agent spend your budgets track.