Unified Token Accounting for LLMs: A Technical Practice for Standardizing Cost Measurement
This article explains how to standardize cost measurement for large language model (LLM) workloads by introducing a unified, model-agnostic unit of account. It covers why unified accounting is needed, three design goals (comparability, attribution, and predictability), a conversion model for input, output, and cache-hit tokens, and the engineering steps for metering, cost allocation, quotas, and caching. It also highlights common pitfalls to avoid when applying the approach in production.
1. Background: Why Tokens Need a Unified Unit of Measure
Once LLM applications move into production, the first non-technical problem teams run into is usually not quality but accounting. Different models price input and output at different ratios, cached and uncached requests differ significantly in cost, and bills from multiple models are not comparable. As a result, budgets cannot be attributed to business lines, capacity planning lacks a basis, and the payoff of architecture changes (such as adding semantic caching) is hard to quantify.
The idea behind a unified unit of measure is to define an abstract metering unit that is decoupled from any specific model, convert all billable resources onto the same scale, and then run budgeting, quotas, and settlement on top of that scale. A cloud vendor recently introduced a similar practice, using a unified token-like unit to carry the conversion relationships across different models.
2. Three Design Goals for a Unified Unit of Measure
- Comparability: Costs can be compared horizontally across models and versions, so you do not have to rebuild a financial model every time you switch models.
- Attribution: Bills can be drilled down to the application, tenant, API, or even a single request, supporting internal chargeback.
- Predictability: Given workload characteristics (input length distribution, output length distribution, hit rate), you can estimate consumption for a period in advance.
3. Conversion Model: Cost Differences Across Three Token Types
Using a recent public conversion example as a reference: 1,000 unified units can be exchanged for about 1.25 million input tokens, or about 357,000 output tokens, and in a cache-hit scenario can support about 5 million cached token accesses. Abstracted into a general formula:
Unified unit consumption = input tokens / input coefficient + output tokens / output coefficient + hit tokens / hit coefficientExample coefficients: input 1250, output 357, hit 5000 (unit: tokens per unified unit)
This leads to three conclusions: the marginal cost of output tokens is about 3.5 times that of input tokens; cache hits are the cheapest resource, costing about one quarter of an uncached input; therefore the optimization order should be “first raise the hit rate, then compress output length, and only then consider switching to a cheaper model.”
4. Engineering Implementation: From Metering to Governance
- Metering: Record
prompt_tokens,completion_tokens,cache_hit_tokens, and the model identifier uniformly at the gateway layer to form a single source of truth. - Cost allocation: Tag by application/tenant, write to logging and monitoring/alerting, and build minute-level dashboards.
- Quotas and rate limiting: Set daily/monthly budgets in unified units, and downgrade to a smaller model or queue requests when a threshold is exceeded.
- Caching strategy: Apply prefix caching to stable prefixes (system prompts, long documents, code context); the hit rate typically rises linearly as context reuse increases.
def cost_units(inp, out, hit, coef=(1250, 357, 5000)):return inp / coef[0] + out / coef[1] + hit / coef[2]
5. Common Pitfalls
The first is treating a unified unit of measure as a price cut; it is essentially about standardizing the measurement, not adjusting prices. The second is neglecting output length governance, which lets costs be amplified on the generation side. The third is a crude cache key design (not including version and tenant), which causes hit pollution. If an enterprise already runs inference services on Baidu AI Cloud using general-purpose container platforms, object storage, and logging/monitoring capabilities, the metering and dashboard approach above can be reused directly without binding to a specific model API.
