When to reach for it
- Costs must be capped or allocated.
- Agents autonomously execute loops.
- Optimisation of models and patterns is required.
/pattern/token-cost-tracking/
Token consumption, model costs, and tool-related expenses are measured per run, agent, or workflow. The measurement is only useful if something acts on it: a kill switch (a hard budget ceiling that terminates a runaway run before a retry storm multiplies the bill) and caching of intermediate results turn the metric into a control.
In practiceAn autonomous research agent emits token and cost telemetry on each LLM call, and a hard per-run budget cap terminates the run before a self-initiated retry storm triples the daily bill.
When to reach for it
When it backfires
The tradeoff
Better budget control is gained against additional measurement and aggregation effort.
Every model call is metered against a budget.
Usage is computed at month end from the provider's invoice. A runaway loop has already cost a week's budget by the time anyone notices.
Fix · Emit cost on every span as it happens. Set hard per-run caps at the harness; treat exceeding the cap as a correctness failure, not a billing concern.
A supervisor fans out to specialists and tools that all bill to one account. The total is visible, but you cannot tell which agent, tenant, or feature drove the spend, so you cannot act on it.
Fix · Tag every model call with run, agent, and tenant identifiers on the span, and aggregate cost along those dimensions — not just a single global counter.
Keep going
Search patterns, frameworks, and pages.