Model usage and budgets
Every language model call in the platform goes through the model gateway. Budgets cap that spend for an agent, a person or the whole tenant, by day or by month. At a cap the gateway either keeps going and records an alert, or refuses the call and the caller stops cleanly. This guide sets up budgets for the illustrative ice cream maker, attributes the spend and reads it back with SQL
ops.model_usageIn the platform today
- Budgets per tenant, agent and person run in the platform service with tests
- The tenant's monthly cap, set by your administrator, always applies, and more budgets are set in
ontology.yamlunderlanguageModels.budgets, by calendar day or month in the ontology's time zone - Thresholds default to an alert at 80 % and a block at 100 %. A block refuses calls with
MODEL_BUDGET_EXCEEDEDonce spend in the window has reached it, and the caller takes its deterministic path. An alert is recorded once, in the audit log - For a person, a budget naming them wins; otherwise the largest matching group or
*budget applies GET /api/v2/models/budgetsshows each budget's spend in its current window, andGET /api/v2/models/usage?groupBy=tier,purpose,agent,persongroups spend by tier, purpose, agent and person- Each model can also have a daily token and a calls-per-minute capacity, enforced with
RATE_LIMITED; see the language model catalogue
- Budgets per AI function and per cost tag, reserving the worst-case cost before a call is sent (today a block applies from the next call once spend reaches it), notifications at a threshold, approvers and overrides, simulation, and a budgets screen
languageModels:
budgets:
tenant-day: { scope: tenant, window: day, limitCad: 25 }
aog-desk: { scope: { agent: aog-desk }, window: month, limitCad: 40,
thresholds: [{ at: 0.8, then: alert }, { at: 1.0, then: block }] }
person-default: { scope: { person: "*" }, window: day, limitCad: 4 }
planners: { scope: { person: "group:planning" }, window: day, limitCad: 15 }
- Permission to change
ontology.yaml, where tenant, agent and person budgets are set underlanguageModels.budgets - At least one model route in the model gateway, with a price table, as set up in model adapters
- Read access to the
opscatalogue in operational tables, which Administrators have by default, to run the queries on this page
How budgets work
A budget is a limit in Canadian dollars on one scope over one window, with thresholds that say what happens as spend approaches it. The gateway checks every budget that applies to a call before sending it, and a call refused by a budget is never sent to a provider, so it costs nothing. On request, the gateway prices each call before it is sent and reserves its worst-case cost against each budget
Scopes and windows
| Scope | What it counts | Windows | Set by |
|---|---|---|---|
| Agent | Every call made by one agent | Day, month | languageModels.budgets |
| Person | Every call made on behalf of one person or group member, whichever agent made it | Day, month | languageModels.budgets |
| Tenant | Every call in the tenant | Day, month | Set by your administrator, and languageModels.budgets |
All budgets that apply to a call are checked, and the most restrictive one decides. Days run from 00:00 to 24:00 and months from the 1st, both in the tenant time zone, which for the creamery is America/Halifax. A scope can have a daily and a monthly budget at once; the daily one stops a runaway loop on a Tuesday from eating the month. On request, budgets per call, per AI function and per cost tag
Set up budgets
Budgets are set under languageModels.budgets, as shown above. On request, budgets per AI function and cost tag, approvers, and a simulation that replays past usage
- Look at what you spend now. Before you set a number, find out what normal looks like. Query the last full month of
ops.model_usageby caller and by person. A budget set without this is either too loose to matter or tight enough to stop the weekend planner on the first busy Friday
-- September spend by agent or purpose, with the busiest day for each
SELECT coalesce(agent, purpose) AS caller,
round(sum(cost_cad), 2) AS month_cad,
round(max(day_cad), 2) AS busiest_day_cad,
count(DISTINCT user_id) AS people
FROM (
SELECT *,
sum(cost_cad) OVER (PARTITION BY coalesce(agent, purpose),
date_trunc('day', occurred_at)) AS day_cad
FROM ops.model_usage
WHERE occurred_at >= TIMESTAMPTZ '2026-09-01 00:00:00-03:00'
AND occurred_at < TIMESTAMPTZ '2026-10-01 00:00:00-03:00'
AND outcome = 'ok'
)
GROUP BY 1
ORDER BY month_cad DESC;
- Choose alert or block for each cap. A threshold with
then: alertis recorded once in the audit log and lets calls continue;then: blockrefuses calls once spend in the window has reached it. Use block for agents that run unattended and for the tenant ceiling. Use alert alone where stopping would hurt more than overspending, such as an agent that drafts the recall notice
When a budget blocks
The gateway refuses a call before it leaves the platform, so nothing is sent and nothing is charged. What happens next depends on the caller, and in every case the refusal is a row in ops.model_usage with outcome refused_budget
| Caller | Behaviour | What the person sees |
|---|---|---|
| Agent run | An agent with a playbook runs it instead, recorded as a fallback step in the trace. Without a playbook the run fails with the error | The playbook's result, or the error |
| AI function | The declared fallback runs, as for any other refusal on AI functions | The fallback result |
| Assistant | Verified answers make no model call and are never affected. Only the optional drafting path stops, and the Assistant gives its closest-match reply instead; see how the Assistant answers | "I don't have a checked answer for that", with the closest questions |
| Evaluation run | Model-graded checks are skipped with the reason rather than failed | "skipped: MODEL_BUDGET_EXCEEDED" on the check |
| API caller | A synchronous call that needs a model, such as invoking an AI function without a fallback, returns the error below | The error body |
{
"type": "https://docs.marklandstreet.com/errors#MODEL_BUDGET_EXCEEDED",
"title": "Model budget exceeded",
"status": 429,
"code": "MODEL_BUDGET_EXCEEDED",
"reason": "MODEL_BUDGET_EXCEEDED.AGENT_MONTHLY",
"detail": "Budget agt-weekend (agent, month) is used up: 320.04 of 320.00 CAD",
"params": {
"budgetCad": 320.0,
"budget": {
"id": "agt-weekend", "scope": "agent", "window": "month",
"limitCad": 320.0, "usedCad": 320.04, "resetsAt": "2026-11-01T03:00:00+00:00"
}
},
"errors": [],
"retryable": false,
"requestId": "req_01JB3A2N6V4K8QX1"
}
The reason names the scope and window: TENANT_MONTHLY, TENANT_DAILY, AGENT_MONTHLY, AGENT_DAILY, PERSON_MONTHLY or PERSON_DAILY. On request, the body also names the budget's approvers, and the detail says how much a reserved call needed
Do not retry MODEL_BUDGET_EXCEEDED in a loop. It clears only when the window resets, at resetsAt, or when the budget is raised; the SDK does not retry it
Overrides
On request, time-limited overrides raise a budget, approved by a named group
Cost attribution tags
On request, cost tags from a controlled list, such as cost-centre=retail, explain spend. They are set on agents, AI functions, automations, evaluation suites and API clients, travel with the work, and can carry their own budgets
Usage data in ops.model_usage
Every call the gateway handles, including refused ones, is a row in ops.model_usage, one of the operational tables. The table holds no prompts or outputs; those stay in the reasoning trace under its own retention and access labels
| Columns | What they hold |
|---|---|
usage_id, occurred_at, purpose, run_id, agent, user_id | The call, when it was made, what for and on whose behalf |
provider, model, tier, route, escalated_from | Where the call went |
outcome | ok, refusal, schema_failed, refused_budget, no_eligible_route, rate_limited or error |
input_tokens, output_tokens, cache_read_tokens, cache_write_tokens, cost_cad, latency_ms | Tokens, cost and time |
schema_valid, redacted, error | Whether the output passed its schema, how many values were redacted, and any error |
Redaction counts by kind are in ops.model_redactions and budget alerts in the audit log. On request, columns for the caller's kind and version, the person behind it, cost tags and the refusing budget
Lowering cost
A budget tells you when spend is too high. These are the levers that bring it down without making agents worse. Change one at a time, rerun the agent's evaluation suite to check it still passes, and compare spend in ops.model_usage before and after
| Lever | Where it is set | Typical effect |
|---|---|---|
| Gateway exact-match cache | On request, per route, scoped to the caller's access | Free repeats for scheduled runs that ask the same thing of unchanged data, such as a 05:00 briefing rerun |
| Provider prompt caching | Automatic where the provider offers it, for the stable prefix of instructions and tool definitions | Lower input cost on long agent runs |
| Route small tasks to small models | The routing table: send classify and summarize to a small model, keep plan on a large one | Classification calls at a fraction of the cost |
| Models you run | On request, a route to an OpenAI-compatible server on your own GPUs, priced at the internal rate you set | Embeddings and extraction at a predictable fixed cost |
| Tighter agent limits | The agent's stepLimit, and a team's costLimitCad per run | Bounds the worst run; the trace shows which steps were expensive |
| Smaller tool results | Select fewer properties and smaller pages in tools | Less context per step, so cheaper later steps |
| Verified answers instead of drafting | Turn frequent Assistant drafts into verified answers | No model call at all for that question from then on |
Verify it worked
- Check the budgets.
GET /api/v2/models/budgetsshows each budget's spend in its current window and when it resets. Spend should match the query in step 1 for the current month - Force a refusal on a test agent. Give a copy of an agent a daily budget of $0.01 CAD and run it twice. Once spend has reached the budget, the next model call is refused with
MODEL_BUDGET_EXCEEDED, and the agent runs its playbook or fails - Find the refusal in the table. Query
ops.model_usageforoutcome = 'refused_budget'and the test agent. Remove the test budget afterwards - Check the alert path. Lower a threshold below current spend on a test budget and confirm the alert is in the audit log
Limitations
- Built budgets are set under
languageModels.budgets. Columns ofops.model_usageare only added, under the same notice rules as every other operational table - Budgets are in Canadian dollars and computed from the route price table, not the provider's invoice. Currency conversion and provider rounding make the two differ slightly
- Windows are calendar days and months only; there are no weekly or rolling 30-day budgets
- A call that has been sent is never cut off. It completes and is charged in full, even if it takes a budget past its limit
- Calls to models you run cost the internal price you set, zero by default. GPU time is not metered by the gateway
- Person budgets count calls made on behalf of that person. Automations running as a service identity count against that identity, not the person who built the automation
- Tags on calls already made cannot be changed. Retagging an agent affects its calls from then on