Record it at request time, or not at all
The core insight: model prices change, and you cannot reconstruct historical cost from historical token counts.
Open-source AI infrastructure
Why token counts from provider dashboards cannot be attributed to customers, what to record at request time so cost is reconstructable later, and the three mistakes…
The core insight: model prices change, and you cannot reconstruct historical cost from historical token counts.
The most common one, and it looks fine until you have a second customer.
In application code. Full control, and it works regardless of how you call providers. But it is a code change in every service, it drifts as services are added, and coverage is only ever as good as your least-maintained service.
Raw records are not a cost model. The four things people actually ask:
Once you can attribute spend, you can enforce against it: per-tenant budgets that reject rather than warn, per-tenant rate limits so one customer cannot exhaust shared capacity, and routing rules that send bulk workloads to cheaper models.