Why invoices and internal logs disagree
Provider invoices and internal usage logs come from different systems. Provider billing data is typically aggregated by model, project, API key, or time window, while internal request logs are records from gateways, applications, and agent runtimes. The two sources can differ in time zone, model names, token units, and pricing assumptions, so totals rarely match until both are brought to a shared basis.
The process below defines a consistent record, aligns both data sets, and turns each remaining difference into a classified, owned variance.
Reconciliation data flow
- Provider billing dataInvoices and exports aggregated by model, project, API key, or time window.
- Internal request logsRecords from gateways, applications, and agent runtimes.
- Normalized basisShared time zone, model names, token units, and pricing assumptions.
- Variance reviewClassified differences checked against tolerance and assigned to owners.
Step 1: Define the log schema and identifiers
Capture a consistent request record at the gateway or runtime layer. Each record should include the following fields:
- Internal request ID and provider request ID
- Provider, model, and model version as requested and as returned
- API key or credential reference, project, team, and agent identity
- Input, output, and cached token counts as reported by the provider
- Request start and end timestamps in UTC, plus status and retry count
- Parent request ID and tool-call linkage for agent workflows
Steps 2 to 5: Normalize, match, classify, and resolve
- Normalize. Bring both data sets to the same time zone, model identifier, unit, and price basis.
- Match. Join internal records to provider data at the finest level the provider exports.
- Classify. Assign each remaining variance to a cause.
- Resolve. Compare each variance to a documented tolerance and assign it to an owner for review.
Matching and variance classification in practice
Normalization removes differences that come from representation rather than usage. Align the following dimensions before attempting any match:
| Dimension | Align on |
|---|---|
| Time zone | A single time zone for both data sets (internal timestamps are recorded in UTC) |
| Model identifier | Consistent model names, comparing the model as requested with the model as returned |
| Unit | Token units, using input, output, and cached token counts as reported by the provider |
| Price basis | Shared pricing assumptions applied to both data sets |
After normalization, match at the finest level the provider exports. Where the provider exports only aggregates by model, project, API key, or time window, compare internal totals at that same level. Each variance that remains should be classified by cause rather than carried forward as a single unexplained difference.
Tolerances, cadence, and ownership
Compare each classified variance to a documented tolerance, and review on a fixed cadence with a named owner.
Agent and tool-call logging for attribution and audit
For agent workflows, the schema includes agent identity, a parent request ID, and tool-call linkage. These fields connect individual provider requests to the agent activity that produced them, which supports attribution when variances are reviewed and gives auditors a traceable record.