← ~/pillars / cost-engineering / guide

Cost engineering

Cost observability as an engineering discipline, same as performance monitoring or error tracking: measuring what agents actually cost, attributing it to people and outcomes, and optimising with evidence.

updated 2026-07-06 ~3 min read

← back to cost-engineering/

on this page

You have p99 dashboards for latency. You page someone when error rates move. Where is your p99 for spend? For most teams adopting coding agents, the honest answer is a monthly invoice and a feeling. The feeling is usually wrong, because agent spend is bursty, cache-dependent, and attributed to nobody. Cost observability is an engineering discipline, the same as performance monitoring or error tracking: instrumented at the source, attributed to owners, reviewed on a cadence, and connected to outcomes. This pillar treats it that way.

The three-layer model

Every question about agent cost is answered at one of three layers, and most confusion comes from mixing them up:

Layer one: local telemetry. The harness knows the most, soonest. Claude Code emits per-request cost and token events over OpenTelemetry (including all four token types and session, user, and even per-agent attribution), and exposes live figures in /usage and a scriptable status line (monitoring usage). This layer is real-time and richly attributed, but its dollar figures are client-side approximations, not a bill (costs).

Layer two: provider accounting. The vendor’s own ledgers: Anthropic’s usage and cost APIs report by key, workspace, and day (usage and cost API). Authoritative for what the provider thinks happened, but coarser-grained and hours behind.

Layer three: billing truth. What you are actually invoiced. On AWS this is Cost Explorer and the CUR, where, since April 2026, Bedrock attributes every inference to the calling IAM principal, which makes billing-accurate per-developer cost a configuration exercise rather than an aspiration (IAM principal cost allocation).

The discipline is knowing which layer you are quoting. Real-time steering comes from layer one; monthly reconciliation from layer three; and any figure that cannot be traced to one of the three is a rumour.

Tokens times list price is not a bill

The most common cost-analysis mistake in the field: multiplying token counts by list prices and calling it spend. It fails twice. First, cached tokens are billed at different rates in both directions (cache writes carry a premium, cache reads a deep discount), and an agentic session is mostly cache reads, which is why the CUR carries four distinct usage types per model and summing only input and output will never match your invoice (understanding CUR data). Second, subscription plans (Claude Pro and Max included) meter opaque quota, not dollars: local telemetry can tell you the API-equivalent value of what you consumed, but nothing converts quota fraction to cost. Both failure modes have the same cure: take the number from the layer that owns it.

Cost per outcome, not cost per token

Cost per token is accounting. Cost per completed task is engineering, and it is the number almost nobody publishes, because it requires joining spend to results. The FinOps Foundation’s AI working group frames this as cost per unit of work (FinOps for AI); in agentic development the natural units are the completed task and the merged pull request, with the cost of failed runs amortised over the successes, because a cheap model that fails twice before succeeding is not cheap.

This site measured it rather than asserting it. Our benchmark harness recorded the cost of every session it ran, and its first cross-model comparison made the argument immediately: the newer model matched the older one’s outcomes on an identical task, at roughly sixty percent higher cost and more turns. Better on the leaderboard, dearer per outcome, on that workload. That is exactly the kind of decision-grade fact that cost-per-token dashboards cannot see, and it is why choosing models for agent fleets weighs price beside every benchmark score.

What this pillar covers

The pattern pages arrive in sequence, each with a copy-paste artifact: instrumenting Claude Code’s telemetry end to end; billing-accurate per-developer attribution on Bedrock; the subscription-versus-API ledger and what metered billing buys you beyond dollars; prompt-cache economics, measured rather than assumed; session hygiene and context budgeting (the practices that cut spend without cutting capability); and cost-per-merged-PR as the metric your rollout should be steering by.

// sources