
Token usage logging without storing secrets
Build interpretable LLM usage records with clear totals, missing-value handling, deduplication, and transparent cost estimates.
Read Token usage logging without storing secretsToken Logger / Field guide
Token logging here means recording LLM usage metadata. Keep input, output, and any supported detail categories understandable so an application’s usage history can be reconciled without preserving credentials or conversation content.

Start with the purpose
A token usage record connects quantities to an operation, an attempt, a model reference, and a reporting source. Decide which boundary the record represents before summing it. A retry is additional work, while a repeated delivery of the same usage record may be a duplicate that should not increase an operation total.
Keep input and output quantities separate and preserve the source’s definitions. Additional categories can overlap with those totals. A cache-related quantity or another detailed breakdown should not be added as independent usage unless its relationship to the total is understood. Write that relationship down alongside the integration.
Missing usage is different from measured zero usage. A request may end without a complete usage report, or an integration may not expose a detail category. Preserve the distinction in an application accounting record and define how incomplete records are reconciled. That makes uncertainty visible instead of hiding it inside a plausible-looking total.
Cost estimates require their own inputs. Keep the pricing assumption, its effective date, applicable model, unit, and currency separate from measured usage. Explain which cost components the estimate includes. An application estimate can support planning and anomaly review; it should not be presented as a guaranteed provider invoice.
Identifiers can join usage to relevant operational events without joining it to the full prompt or response. Review those joins and access rules together. In this context, a token logger is a usage accounting concept: passwords, API keys, access tokens, and session credentials are not token usage data and do not belong in its records.
Four decisions to make
Separate the user-visible operation from each attempted model call, then state what an aggregate sums.
Keep reported totals and detailed subsets distinct so a report does not accidentally count the same usage twice.
Represent unavailable usage explicitly and give incomplete records a reconciliation status.
Version any estimate inputs separately from observed usage, including unit, effective date, and currency.

Build interpretable LLM usage records with clear totals, missing-value handling, deduplication, and transparent cost estimates.
Read Token usage logging without storing secrets
Trace a model request through timings, retries, tool calls, configuration changes, and outcomes without collecting every message.
Read AI logging: what to capture around a model requestStart with the fundamentals, then follow the signal that matters to your work.