Token Normalization Across Multiple LLMs: A Technical Practice
This article explains how to build a unified token measurement layer across heterogeneous large model services. It covers the design goals and boundaries, a four-layer architecture, a raw usage triple as the intermediate representation, versioned conversion tables, dual-layer quotas with routing, observability, and a step-by-step adoption checklist so that cost, budget, and capacity planning share one reliable baseline.
1. Why Tokens Need a Unified Unit of Measurement
When building multi-model applications, the most common problem teams face is not “the call fails” but “the numbers don’t add up.” Different large model services differ in tokenization strategy, how they define the context window, and how they bill input versus output. The same Chinese passage may be split into a different number of minimal processing units depending on the provider; some services count the system prompt as input while others report it separately; some apply a different accounting rule to cache hits. As a result, usage data at the application layer cannot be compared horizontally, and cost accounting, quota allocation, and capacity planning all lose a shared baseline.
A cloud vendor recently introduced a unified metering unit for large model calls, letting users redeem multiple model services and ecosystem application benefits under the same measurement, with a phased rollout in selected provinces first. Setting aside the specific product form, the underlying problem is a general engineering one: abstracting a metering and settlement layer that is decoupled from specific implementations, on top of a heterogeneous model supply. This article takes that general perspective.
The essence of a unified unit is “standardizing weights and measures,” which delivers at least three benefits:
- Comparability: cost and usage across models and versions can be aligned in a single report.
- Budgetability: business teams request quota in the unified unit, so the platform does not have to maintain a separate budget model for every model.
- Portability: when the underlying model is swapped, quota logic and alert thresholds on the business side do not need to be rewritten.
2. Design Goals and Boundaries
Before designing this kind of system, be clear about what it does not do, or it will balloon into a bloated all-in-one gateway. Reasonable boundaries are:
- Measure and convert only; do not interfere with inference semantics. A unified unit should not change output quality and should not imply prompt rewriting.
- Stay bidirectionally traceable. You must be able to trace from a unified unit back to raw usage details, and aggregate raw details back into the unified unit.
- Make conversion rules versionable. Tokenizers and billing rules change, so the conversion table must carry a version number and support gradual rollout.
- Make failures explainable. Every conversion failure must return an explicit reason code rather than silently returning zero.
Note that a unified unit does not mean “flattening differences.” Model capability, latency, and context length remain fundamentally different; the unit only addresses the measurement question.
3. Overall Architecture: Four Decoupled Layers
A practical implementation is usually split into four layers:
- Access layer: unified authentication, rate limiting, and request normalization that hide differences between provider APIs.
- Metering layer: collect the number of input/output minimal processing units, cache hit status, and call status.
- Conversion layer: map raw usage to the unified unit using a versioned conversion table.
- Governance layer: quota, budget, alerting, reporting, and auditing.
The conversion layer is the core of the whole system. Use a “raw usage triple” as the intermediate representation:
UsageRaw {model_id: string // logical model identifier, not a vendor nameinput_units: int // input-side minimal processing unitsoutput_units: int // output-side minimal processing unitscached_units: int // input units served from cachestatus: enum // success / partial / failed}
The unified unit is defined as an abstract “standard processing unit,” and the conversion formula should stay linear and auditable:
standard_units =(input_units - cached_units) * w_in(model_id, version)+ cached_units * w_cache(model_id, version)+ output_units * w_out(model_id, version)
The weights come from the conversion table and must satisfy additivity: the sum of converted results from multiple calls must equal the result of converting the merged usage in one pass. This is the bottom line for accounting correctness and must be covered by unit tests.
4. Conversion Table and Version Management
Manage the conversion table as immutable configuration plus a version number to avoid runtime drift:
conversion_table:version: "2026-11-a"entries:- model: "general-chat-large"weights: { in: 1.0, cache: 0.25, out: 2.0 }- model: "code-assist"weights: { in: 1.1, cache: 0.3, out: 2.4 }effective_from: "2026-11-11T00:00:00Z"
Three engineering practices are essential:
- Gradual rollout: run the new version in parallel on a small traffic slice, diff it against the old version, and block the release if the divergence rate exceeds a threshold.
- Backfill and recompute: if historical bills need to be recalculated under a new measurement, raw usage details must be retained; storing only converted results is forbidden.
- Explicit fallback: on an unknown model identifier, use an explicitly configured fallback weight and tag it, rather than throwing an exception and breaking the request.
5. Coordinating Quota, Routing, and Budget
The biggest value of a unified unit is making “budget” a first-class citizen. The recommended approach is dual-layer quota: the account layer holds a total amount in the unified unit, the model layer holds sub-limits, and the routing component considers latency, availability, and remaining sub-quota when selecting a model.
def choose_model(req, candidates, quota):feasible = [c for c in candidatesif quota.remaining(c.model) >= estimate(req, c)]if not feasible:raise QuotaExceeded("no candidate satisfies estimated budget")return min(feasible, key=lambda c: (c.p95_latency, c.estimated_units))
The key here is that estimate and the real conversion must use the same conversion table, otherwise a reconciliation gap appears where “the estimate was enough but settlement went over budget.” In practice, apply a safety factor to the estimate and write back the deviation after settlement for continuous calibration.
6. Observability and Cost Governance
A unit without observability is just a ledger and cannot be operated. At minimum you need four metrics: conversion failure rate, version divergence rate, unit cost trend, and cache hit rate. On the logging side, keep fields that link the request identifier to the conversion version so each record can be traced.
For cost governance, three strategies help: first, trim prompts and reuse context to directly reduce input units; second, raise the cache hit ratio so repeated prefixes become a low-weight portion; third, tier quota by business value and prioritize the unified unit for high-value paths. Any optimization must be gated by quality regression tests, so you do not sacrifice output usability to save quota.
7. Adoption Steps and Acceptance Checklist
Proceed in five steps:
- Define the standard processing unit and the raw usage triple, and freeze the field semantics.
- Set up a conversion table repository and release process, with gradual-rollout diffing.
- Implement metering instrumentation and detail storage so recomputation is possible.
- Connect dual-layer quota and routing so estimation and settlement share one measurement.
- Establish reporting, alerting, and a monthly reconciliation process.
For acceptance, at minimum check: the additivity test passes; the unknown-model fallback path works; a version rollback does not affect in-flight requests; reports and details reconcile record by record. If you use general capabilities on Baidu AI Cloud, you can reuse the container platform to host the gateway, a message queue to smooth metering spikes, object storage to archive details, and the logging and monitoring services for tracing, without building the full infrastructure stack yourself.
8. Conclusion
A unified unit is not a simple unit conversion but a reconstruction of metering semantics: it converges a heterogeneous, multi-version, inconsistent model supply into a single scale that business teams can understand, finance can audit, and engineering can evolve. For developers, the lowest-risk order is to first retain raw usage and version the conversion, and only then tackle quota and optimization.
