Advanced

Measuring & Governing Token Spend

You can't optimize what you can't see. Build the observability, budgets, and governance that keep token costs optimized after the heroic cleanup ends.

✍️ AI School Editorial Team · Lilly Tech Systems 📅 Published Jun 3, 2026 · Reviewed Jun 4, 2026

The Visibility Gap

Most organizations discover AI overspend the way they once discovered cloud overspend: a shocking invoice, weeks later, with no way to tell which team or feature caused it. The fix is the same discipline cloud FinOps brought to compute - applied to tokens. Everything in this lesson exists so that the question "where is the money going?" has an instant, accurate answer.

Instrument Every Call

Log, for every model call:

  • Tokens in / out - split by cached vs. uncached
  • Model and reasoning/thinking budget used
  • Feature / endpoint, and team or cost center
  • Latency and success/failure
  • For agents: run ID and step count, so runs can be costed end-to-end

Providers return exact token usage in every API response - capture it at your gateway or SDK wrapper so coverage is automatic, not per-team voluntary.

Route all traffic through one internal AI gateway. One choke point gives you usage attribution, budget enforcement, model routing, caching policy, and key management in a single place. This is the foundational architecture decision for AI governance - everything else in this lesson gets dramatically easier once it exists.

The Metrics That Matter

MetricWhy It MattersHealthy Signal
Cost per successful taskThe north star - not cost per callFalling while usage grows
Cost per feature per dayRegressions are bugs; trend itFlat or explained changes
Cache hit rate (high-volume routes)Structural prompt health≥70-90%
Output/input ratio per featureRising ratio = growing verbosityStable
Frontier-model share% of calls on the most expensive tierFalling as routing matures
Agent run cost P50/P95/maxThe tail is where incidents liveBounded max; stable P95

Budgets, Alerts, and Circuit Breakers

Reactive dashboards are not governance. Make limits structural:

  • Per-team and per-feature budgets with alerts at 50/80/100% of the monthly mark.
  • Hard per-run caps for agents (Lesson 3) - the difference between a logged failure and a billing incident.
  • Anomaly alerts - today's spend ≥3× the trailing average fires a page, not an email.
  • Circuit breakers - a runaway feature gets automatically downgraded to a cheaper model or rate-limited rather than taken down. Degrade gracefully; never choose between an outage and an invoice surprise.

Make Cost a Review-Time Concern

Optimized systems regress one merged PR at a time. Catch it where it happens:

  • Add expected token cost to feature design templates - a simple "cost per 1,000 uses" estimate.
  • Include a token-cost check in code review for AI features: model tier justified? max_tokens set? prompt structured for caching? reasoning budget appropriate?
  • Run a monthly token review: top-10 features by spend, cache hit rates, routing share, and any regressions. Treat a cost regression exactly like a performance regression.

Chargeback and Accountability

Showback (publish per-team costs internally) changes behavior; chargeback (actually bill the team's budget) changes it faster. When the team that ships the feature owns its token bill, optimization becomes self-sustaining - engineers start asking "does this need the frontier model?" without being told to. That cultural end-state is the real goal of this lesson.

💡
Governance is also negotiation power. With per-seat usage data and per-feature API costs in one dashboard, "should we renew this $360k contract?" becomes an arithmetic problem instead of a leap of faith - and vendor negotiations start from your data instead of their list price.
📚
See also: AI Cost Management for budgeting and tracking practices, and AI Cost Dashboards for build guides.

Ready to Go Deeper?

Live instructor-led courses from our partners. Affiliate disclosure.