Token cost accounting
also called LLM cost accounting · token metering · AI spend attribution
An honest ledger has four buckets, not two, and the buckets have to be mutually exclusive by construction: input tokens that were processed fresh, input tokens served from a prompt cache, tokens written into that cache, and output tokens. Each is billed at its own rate, and on a cache-heavy call the four can span two orders of magnitude. The moment one bucket can contain another, the same token is priced twice or not at all, and no care downstream recovers it. This is why the invariant belongs at the provider boundary: normalise the vendor’s shape into disjoint buckets as the response is parsed, assert it there, and let everything downstream do plain arithmetic.
The disagreement that costs the most money is about cache tokens. Anthropic reports `cache_read_input_tokens` and `cache_creation_input_tokens` exclusive of `input_tokens`: the three numbers add up to what you were charged for on the input leg. OpenAI reports `prompt_tokens_details.cached_tokens` inside `prompt_tokens`, and Gemini reports `cachedContentTokenCount` inside `promptTokenCount`: the cached figure is a breakdown of the total, not an addition to it. Read the inclusive convention as if it were exclusive and you bill the cached prefix twice — once at the full input rate and once at the cached rate. Read the exclusive convention as inclusive and you subtract the cache reads from a number that never contained them, and under-bill. On traffic where most of the prompt is a repeated prefix, the error runs to somewhere between half and nine tenths of the input leg, which on agent workloads is most of the bill.
Provider usage is untrusted wire data even when a type declaration says it is a number. A negative count subtracts from a budget window; a float that is not a safe integer loses precision as soon as it is persisted or summed; a missing field becomes `NaN` and poisons every total it touches. Refusing anything that is not a non-negative safe integer, at the boundary, turns a class of silent mispricing into a loud parse failure. Streaming needs one more rule: provider usage counters are cumulative, but some compatible endpoints emit more than one usage frame and a later frame can omit or regress a bucket. Merging by taking the greatest validated value seen for each bucket is conservative — it never credits a budget, and it never mistakes a repeated total for an increment, which is the mistake that doubles a streamed call’s recorded cost.
Then there is the question of which price. A price table matched on the model name alone breaks as soon as the same model is reachable through two upstreams at different rates, so rows are keyed on model pattern and provider kind: an exact provider beats a wildcard, an exact model beats a wildcard, and the longest pattern wins among equals. Give rows an effective window rather than overwriting them, so a historic entry can still be explained by the row that produced it. Two ordering rules matter. Price against the provider that actually served the call: a failover priced at the first candidate’s rates attributes spend to a vendor that never ran the request. And pin the row before the call rather than re-reading it afterwards, since a catalogue sync landing mid-call would otherwise reprice an admitted request.
The failure worth designing against is not an inaccurate figure but a missing one. A price lookup that returns zero for an unknown model produces a ledger of $0 traces and, where a spend ceiling reads the same estimate, a per-request cap that admits everything — a control that is off while the console still shows it configured. An estate spending nothing and an estate spending unmetered emit identical bytes, and the difference arrives on the invoice. Refuse a budgeted call whose resolved route cannot be priced, rather than pricing it at nothing. Two smaller hedges belong beside the claim: a character-count estimate (roughly four characters per token) is fine for a pre-flight check and must never reach the ledger, where the figure has to come from the provider’s own reported usage; and a per-call ledger will not reconcile exactly to a vendor invoice, which carries commitments, batch rates and rounding the call record never sees.
The same call, priced under both conventions (illustrative rates)
A call reports a 200,000-token prompt of which 180,000 were served from cache, plus 800 output tokens, on a model priced at $3.00 per million input tokens, $0.30 per million cache-read tokens and $15.00 per million output tokens. Counted correctly under the inclusive convention: 20,000 uncached input at $0.06, 180,000 cache reads at $0.054, 800 output at $0.012 — $0.126. Counted as if the cached figure sat outside the prompt total: the full 200,000 at $0.60, plus the same 180,000 cache reads at $0.054, plus $0.012 — $0.666. Same response, same usage payload, 5.3 times the cost. Nothing in the trace looks wrong; the totals are simply larger, and they stay larger every month.
What token cost accounting is routinely confused with
- Token counting
- Counting answers how many tokens a prompt will consume, and is a property of the tokenizer. Accounting answers what those tokens cost, which additionally requires knowing which bucket each one fell into, which model and provider served the call, and which price row was in force at the time.
- Blended rate
- A blended rate collapses input and output pricing into one dollars-per-million figure so that candidate models can be ranked against each other. It is a ranking device weighted to whatever traffic shape you assume, and it is not a bill: the charged figure always comes from the reported usage against the per-leg rates.
Related terms
Prompt caching
Prompt caching is a provider feature that stores the processed form of a repeated prompt prefix so that later requests beginning with the same bytes are charged at a reduced input rate instead of the full one. It changes the billing shape of a call rather than its content: the prefix still counts as input tokens and still occupies the context window, but the tokens move into a cheap cache-read bucket and, on the call that populates the cache, into a cache-write bucket that on some vendors costs more than uncached input.
Tier routing
Tier routing is the substitution of a cheaper model for the one a caller named, decided before the call by classifying what the request is actually asking the model to do. It is a cost control rather than a quality feature, so the two properties that make it defensible are that it never routes above the tier that was requested, and that it records why it moved.
Model routing
Model routing is the resolution, at the moment of the call, of a requested model name to a concrete provider and model, together with the ordered list of alternatives that may serve it if the first one fails. It lets a client that only knows one model name be pointed at a different vendor, region or price without the client changing, and it is where a multi-provider estate’s data-handling and cost constraints are actually applied.
Fail-closed
Fail-closed describes a control that denies the action it governs whenever it cannot complete its own check — because a dependency is unavailable, a required piece of evidence is missing or stale, a value cannot be evaluated, or the control itself is down. The opposite arrangement, fail-open, permits the action in those same circumstances, which turns every outage in the control into a temporary and silent absence of the control.
Where Token Observe does this
The definition above is the field's, not the product's. This is the part of the product that implements it, for a reader who wants to see one.
Spend controls
Hard USD ceilings, per-minute rate limits and a kill switch, all decided before the request leaves your network.
One billable egress: no retry, no failover
Flight recorder
Every governed request in a timeline a compliance officer can read, and a search box that never writes SQL.
The filter cannot group, count or correlate across traces
The terms next to this one
Where the money goes, why providers disagree about how to count it, and what a spend control has to do to be a control rather than an alert.
Definitions are the easy part.
The glossary is written to be useful whether or not you ever buy anything. If you have got to the point of deciding how to implement one of these in your own estate, say what your agents do and you will get a straight answer about what it would actually take.
no form · no qualification step · no sales desk · the other three ways in