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

Three scopesTenant, agent and person, with more on request
Day or monthCalendar windows in the tenant time zone
Alert or blockThresholds that notify, and a cap that stops
QueryableEvery call is a row in ops.model_usage

In the platform today

Built
  • 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.yaml under languageModels.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_EXCEEDED once 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/budgets shows each budget's spend in its current window, and GET /api/v2/models/usage?groupBy=tier,purpose,agent,person groups 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
On request
  • 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 }
Requirements
  • Permission to change ontology.yaml, where tenant, agent and person budgets are set under languageModels.budgets
  • At least one model route in the model gateway, with a price table, as set up in model adapters
  • Read access to the ops catalogue 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

ScopeWhat it countsWindowsSet by
AgentEvery call made by one agentDay, monthlanguageModels.budgets
PersonEvery call made on behalf of one person or group member, whichever agent made itDay, monthlanguageModels.budgets
TenantEvery call in the tenantDay, monthSet 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

  1. 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_usage by 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;
  1. Choose alert or block for each cap. A threshold with then: alert is recorded once in the audit log and lets calls continue; then: block refuses 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

CallerBehaviourWhat the person sees
Agent runAn agent with a playbook runs it instead, recorded as a fallback step in the trace. Without a playbook the run fails with the errorThe playbook's result, or the error
AI functionThe declared fallback runs, as for any other refusal on AI functionsThe fallback result
AssistantVerified 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 runModel-graded checks are skipped with the reason rather than failed"skipped: MODEL_BUDGET_EXCEEDED" on the check
API callerA synchronous call that needs a model, such as invoking an AI function without a fallback, returns the error belowThe 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

ColumnsWhat they hold
usage_id, occurred_at, purpose, run_id, agent, user_idThe call, when it was made, what for and on whose behalf
provider, model, tier, route, escalated_fromWhere the call went
outcomeok, 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_msTokens, cost and time
schema_valid, redacted, errorWhether 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

LeverWhere it is setTypical effect
Gateway exact-match cacheOn request, per route, scoped to the caller's accessFree repeats for scheduled runs that ask the same thing of unchanged data, such as a 05:00 briefing rerun
Provider prompt cachingAutomatic where the provider offers it, for the stable prefix of instructions and tool definitionsLower input cost on long agent runs
Route small tasks to small modelsThe routing table: send classify and summarize to a small model, keep plan on a large oneClassification calls at a fraction of the cost
Models you runOn request, a route to an OpenAI-compatible server on your own GPUs, priced at the internal rate you setEmbeddings and extraction at a predictable fixed cost
Tighter agent limitsThe agent's stepLimit, and a team's costLimitCad per runBounds the worst run; the trace shows which steps were expensive
Smaller tool resultsSelect fewer properties and smaller pages in toolsLess context per step, so cheaper later steps
Verified answers instead of draftingTurn frequent Assistant drafts into verified answersNo model call at all for that question from then on

Verify it worked

  1. Check the budgets. GET /api/v2/models/budgets shows each budget's spend in its current window and when it resets. Spend should match the query in step 1 for the current month
  2. 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
  3. Find the refusal in the table. Query ops.model_usage for outcome = 'refused_budget' and the test agent. Remove the test budget afterwards
  4. 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 of ops.model_usage are 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

Related