Skip to content

Cost and latency governance

Budgets, attribution and routing that keep AI spend predictable as usage grows.

7 MIN READUPDATED 2026-11-18Inference & production
ORIGINAL DIAGRAM · 4 STEPS1Tag every request with2Record tokens, model, l…3Set per-run and per-fea…4Review cost per success…

Original flow diagram from note steps — not a copied image

§ 01Key concepts
Cost per taskSpend divided by successful outcomes, not by raw token count.
AttributionAssigning cost and latency to a specific agent, step, model or customer.
Spend ceilingA hard limit that stops or degrades work before a budget is exceeded.
§ 02When to use
  • AI spend is growing faster than usage.
  • Several agents or teams share a budget.
  • You need to justify ROI with per-feature numbers.
§ 03How it works
  1. 01Tag every request with feature, customer and run ID.
  2. 02Record tokens, model, latency and tool calls per step.
  3. 03Set per-run and per-feature ceilings with defined degradation behaviour.
  4. 04Review cost per successful task weekly and route simple steps to cheaper models.
§ 04Use cases & scenarios

Cost per resolved ticket

Context
Several features share one AI budget.
Problem
Token totals rise but nobody knows which feature is worth the spend.
Approach
Tag each run with feature, customer and outcome, then divide spend by resolved tickets.
Outcome
Clear ROI per feature and an obvious target for optimisation.

Traffic spike with a budget ceiling

Context
A campaign drives a sudden surge in assistant usage.
Problem
Spend would exceed the monthly ceiling within hours.
Approach
Degrade retrieval depth first, then switch to a smaller model, and stop only non-critical paths.
Outcome
Service continues within budget instead of failing outright.
§ 05Examples

Cost record for one ticket

json
{
  "run_id": "run-8821",
  "feature": "support_assistant",
  "customer": "acme",
  "model": "pinned-small",
  "input_tokens": 4200,
  "output_tokens": 310,
  "tool_calls": 2,
  "resolved": true
}

Group records by feature and divide spend by resolved tickets — that is the number that exposes waste.

Ceiling with graceful degradation

yaml
run_budget_tokens: 6000
degradation:
  - step: retrieval
    action: reduce final_passages from 6 to 3
  - step: model
    action: switch to pinned-small
stop_when: budget_exceeded and not critical

Degrade before stopping. Hard stops should apply only to non-critical paths.

§ 06Trade-offs

Hard ceilings

Up: Predictable spend

Down: Can block legitimate work

Soft alerts

Up: Flexible

Down: Overspend can still happen

Cheaper routing

Up: Lower unit cost

Down: Requires confidence checks

§ 07Implementation checklist
  • Separate input and output token costs in reporting.
  • Attribute cost to steps, not just entire requests.
  • Alert on cost-per-success regressions.
  • Include retry and tool costs in the total.
§ 08Configuration reference
KeyTypical valueNote
run_budgetper workflowEnforced at runtime.
feature_tagrequiredNeeded for attribution.
degradationcheaper modelDefine before hitting the ceiling.
§ 09Troubleshooting
SymptomCauseFix
Costs spiked without traffic growthRetries or longer promptsInspect step-level traces and token deltas.
Attribution incompleteMissing tags on background jobsMake tags mandatory in the client.
§ 10Frequently asked questions

What should I measure first?

Cost per successful task by feature. It exposes waste that token totals hide.

Should ceilings stop work outright?

Usually degrade first (cheaper model, fewer passages), then stop for non-critical paths.

More in Inference & production