The Token Bill Is a Performance Metric, and Yours Is Unread

The invoice tripled with no traffic change, because the prompts tripled, and nobody was reading tokens as a metric.

Share
The Token Bill Is a Performance Metric, and Yours Is Unread. Abstract performance illustration in orange and dark grey on debugly.dev

The finance question arrived as a curiosity: why did the agent spend triple last month when the number of tasks barely moved. The answer was in the token accounting, which nobody had been reading, because tokens were filed under "AI cost" rather than "performance". But the token bill is a performance artifact, precisely the way a slow query's row count is, and reading it as one found the same three culprits every performance investigation finds: bloat, redundant work and cache misses, reborn as prompt growth, re reading and prefix churn.

This is the case for treating input and output tokens as latency and efficiency metrics, with the same dashboards, budgets and p99 thinking the site applies to everything else that scales.

This was an agent fleet with per request token logging, per tracing an LLM pipeline with the observability you already have, and the tripling decomposed cleanly once the fields existed.

The bill is a profile

A performance profile answers "where does the time go". The token bill answers "where does the work go", and for an LLM workload the two are the same question, because tokens are the unit of both cost and, roughly, latency. So the first move is the profiler's move: attribute the spend. Per feature, per agent, per step, per prompt version, which turns the invoice from a scalar into a histogram, and the histogram's tall bars are the hot paths.

In our case the tall bars were not the hard tasks. They were the easy ones, repeated, with enormous contexts, which is the signature of inefficiency, because hard tasks earning their tokens is fine, and easy tasks carrying a book are waste.

Bloat: the context that grew by accretion

The largest bar was input tokens on routine tasks, and the cause was context accretion: each prompt change appended a section, nobody removed one, and the system prompt plus retrieved history had tripled in a quarter, the prompt cousin of your theme has 340 settings and merchants use eleven. Every routine call now shipped the book, paying latency and cost to re read instructions the task did not use.

The fix is the budget: a maximum prompt size per task class, enforced in CI like a performance budget, with the diff of a prompt change reporting its token delta, because a prompt that grows fifty percent is a regression, visible pre merge, exactly as treat a prompt change like a deploy argues.

Redundant re reads: the agent re acquiring what it has

The second bar was the agent re reading files and re deriving facts it already had, the compaction loop from what an agent forgets when its context gets compacted, and each re read is tokens spent re acquiring state. The fix is the external scratchpad, so the state lives outside the window and is read once, and the metric that catches the waste is re read rate per session, which is the cache miss rate of the agent's memory, and it belongs on the dashboard next to the bill.

Cache misses: the prefix that never repeats

The third bar was the cheapest to fix and the most subtle. Inference providers cache the prompt prefix, so a request whose prefix matches a recent one is faster and cheaper, and a request whose prefix churns, because a timestamp or a per request id was prepended before the stable body, misses every time. Our prompts embedded a wall clock timestamp at the top, invalidating the prefix on every call, which is the cache key defect from the cache that returned another customer's data in mirror image: the key was too unique.

Moving the volatile fields to the end of the prompt, after the stable body, restored prefix hits, and the latency and cost per call dropped together, which is the pleasing property of cache fixes: they pay on both axes at once.

Output tokens are the latency tail

The output side matters too, because generation is sequential and the long answer is the slow answer, and the fleet's p99 latency was a p99 of output length. Capping and shaping the output, structured responses instead of prose where prose is not needed, is the output analogue of pagination, and it moves the tail for the same reason you are serving a 2400px image to a 390px phone moves LCP: send less, and the slow path gets faster by construction.

The dashboard that makes it a metric

The bill becomes a performance metric when it has the performance metric's furniture: a per feature attribution, a p99 of tokens per task class, a budget with a CI gate, and an alert on the slope, because the tripling was a slope over a quarter, and slopes are what alerts catch. The unread invoice was not a finance failure. It was a missing dashboard, which is the oldest failure in this site's archive.

The rule I keep

Tokens are the unit of cost and latency for an LLM workload, so the bill is a performance profile: attribute it per feature and step, budget the prompt like a performance budget, watch the re read rate as the memory cache miss rate, keep the prompt prefix stable so the inference cache hits, and shape the output because the long answer is the slow answer.

The invoice that is unread is a hot path that is unprofiled, and the three culprits are the same three culprits they have always been, wearing new names: bloat, redundant work and cache misses, billing you monthly until someone reads the histogram.

The organisational half matters as much as the technical one: put the token dashboard next to the latency dashboard in the same review, so a prompt change is discussed once, as a single performance decision, rather than as a cost conversation and a speed conversation that never meet. The two conversations are the same conversation, because the token is the unit of both, and the team that merges them finds the waste in the first review instead of the first invoice.


Published on debugly.dev by Rohit Bhadani | Founder of Krova Cloud