The November 23 UTC Claude Code release makes cached prompt tokens part of input totals. Migrate span queries without double counting.
An input total can already contain cached tokens
Claude Code 2.1.331 was released at 21:34 UTC on November 23, 2026, or November 24 in India. Its release notes add gen_ai.usage fields, the response model and operation name to claude_code.llm_request trace spans. They explicitly state that gen_ai.usage.input_tokens includes prompt-cache tokens. A dashboard that adds cache counts to that total can therefore count the same input twice.
This article focuses on trace semantics and aggregation. It does not estimate current provider prices, measure a real Claude Code session or claim that caching changes model quality. The worked examples are synthetic span fixtures. Their purpose is to make a schema migration reviewable before a new field definition changes an operational chart.
OpenTelemetry's GenAI conventions define total input usage and cache-related components. The older semantic-conventions registry now points to a separate GenAI conventions repository, so record the schema and instrumentation versions rather than citing an unversioned page as a permanent contract. The release note establishes the Claude Code behavior discussed here; other producers may expose different raw provider fields.
Write the accounting identity before the query
Assume a synthetic span reports total input 1200, cache-read input 900 and cache-creation input 100. If those components are non-overlapping subsets of the total under the producer's documented contract, uncached input is 200. The total remains 1200. Computing 1200 plus 900 plus 100 produces 2200, which is a double-counted quantity with no useful meaning as input tokens.
The non-overlap assumption matters. Do not subtract every vaguely cache-related field without understanding its definition. A provider can expose aggregate and detailed subfields that overlap. A schema adapter should document which fields form a partition of the total and which are alternative views. If that relationship is unknown, retain the reported total and label the breakdown unavailable.
Output tokens are a separate quantity. Reasoning-related output can likewise be a subset rather than an additional total, depending on the producer's contract. The general rule is to identify totals, components and dimensions before summing. Similar names and matching units do not imply that two counters are additive.
Normalize at the instrumentation boundary
Create a normalized internal record with total input, optional cache-read input, optional cache-creation input and an explicit schema identifier. Preserve the producer version and original field names in metadata useful for debugging. Do not rewrite old stored spans as if they had always used the new semantics.
# Author: Sandeep Belgavi. Original synthetic-span normalizer.
def normalize(attributes):
total = attributes.get("gen_ai.usage.input_tokens")
read = attributes.get("gen_ai.usage.cache_read.input_tokens")
create = attributes.get("gen_ai.usage.cache_creation.input_tokens")
values = [x for x in (total, read, create) if x is not None]
if any(type(x) is not int or x < 0 for x in values):
raise ValueError("usage must contain nonnegative integer counts")
if total is None:
return {"total": None, "uncached": None, "status": "missing_total"}
if read is None or create is None:
return {"total": total, "uncached": None, "status": "partial_breakdown"}
if read + create > total:
raise ValueError("components exceed the documented inclusive total")
return {"total": total, "uncached": total-read-create, "status": "complete"}This function assumes the documented inclusive-total schema and disjoint cache components. It rejects booleans even though Python treats bool as an integer subtype. It preserves missing values instead of replacing them with zero. A missing cache field may mean unsupported instrumentation, not that no caching occurred.
The normalizer should not infer a total by adding unknown provider fields. If a different producer reports uncached input separately, give it a different adapter and tests. A shared downstream record is helpful only when the adapters preserve the source meaning. Renaming fields without resolving semantics merely hides the incompatibility.
Avoid counting one request at several telemetry levels
An agent turn can contain multiple model calls, retries and parent spans. If both the parent span and each model-call span carry usage, summing all spans in the trace may duplicate the same work. Choose an aggregation level, such as completed model-request spans from a specific instrumentation scope, and document it.
Retries require an explicit interpretation. A retried provider request may consume additional tokens, while a repeated export of the same span is a telemetry duplicate. Stable span identity can help deduplicate exported records; application request identity can group attempts. Those operations answer different questions and should not share a single deduplication key without analysis.
Keep model identity as a dimension rather than merging every response into one assumed tokenizer or price class. Requested model and response model can differ in some systems. The release adds gen_ai.response.model, which can help identify what the span reports. It does not justify assuming that every missing response-model field equals the configured model name.
Walk through a mixed-version dashboard
Before an upgrade, a dashboard may use a producer-specific field with an uncached-input meaning. After the upgrade, a query begins consuming gen_ai.usage.input_tokens, which is inclusive. If the old cache-addition expression remains, the chart can jump without any increase in actual workload. The timing can resemble a performance or cost regression.
Create a migration fixture with equivalent workload represented in both schemas. Normalize each through its own adapter and assert the same total. Then run the old query against the new fixture to demonstrate the erroneous increase. This makes the migration review concrete: the expected change is in field interpretation, not a claim that the workload improved or worsened.
During rollout, segment data by instrumentation version or schema identifier. A deployment timestamp alone is an unreliable boundary when old processes continue running or buffered telemetry arrives late. Backfill only when the old schema has enough information to reconstruct the normalized values. Mark unrecoverable intervals rather than manufacturing precision.
Make ratios robust to missing and zero values
A cache-read share can be computed as cache-read input divided by total input when both values are known and total input is positive. If total is zero, define the ratio as unavailable or a separately documented special case. Returning one hundred percent for a zero-token request is rarely an informative default.
Aggregate counts before calculating a fleet-level ratio. Averaging per-request percentages gives a tiny request the same weight as a large request. For synthetic requests with totals ten and one thousand, that can produce a very different result from total cache-read tokens divided by total input tokens. Report which weighting the chart uses.
Missing breakdowns should not silently enter the denominator as zero cache use. Show coverage: how many requests and input tokens have a complete breakdown? A stable-looking ratio with falling coverage can hide an instrumentation failure. Keep invalid-component records in a diagnostic stream so the adapter does not quietly conceal producer drift.
Separate usage accounting from billing claims
Token counts alone do not determine a bill. Provider pricing can vary by model, cache operation, context length or other terms, and telemetry may be sampled or incomplete. This guide supplies no price table. If an application estimates cost, it needs a dated pricing source, the relevant billing dimensions and reconciliation against actual billing records.
Do not multiply an inclusive input total by a generic input rate and then also charge every cache component unless the pricing model explicitly requires that calculation. Usually an estimator needs disjoint categories with their respective rates. The safe engineering step is to validate the category partition before discussing money.
Similarly, lower uncached input does not establish faster responses. Latency also depends on output generation, queueing, network behavior and service implementation. Keep usage charts and latency measurements separate, then investigate correlations using actual observations. The synthetic fixtures demonstrate arithmetic only.
Test the schema migration as code
Include fixtures for a complete inclusive total, missing total, missing cache fields, zero input, negative counts, non-integer values and components larger than the total. Assert that the normalizer preserves unknowns and rejects inconsistent records. Include duplicate exported spans and parent-plus-child usage to test the chosen aggregation boundary.
Verify that equivalent old and new representations normalize to the same counts. Keep a regression fixture that would double count if the old query were restored. Test aggregate ratios with differently sized requests so accidental averaging of percentages is visible.
Finally, inspect an actual trace from the pinned Claude Code version before applying the adapter to a real deployment. Record which attributes are present and the schema version you observed without retaining prompts unnecessarily. The release note gives a clear migration warning: cached prompt tokens are already inside the input total. A small explicit accounting contract prevents that useful new telemetry from becoming a misleading chart.
Run the example yourself
The synthetic fixtures, expected output and tests behind this guide are in the companion code on GitHub; its README lists the prerequisites, exact commands, expected output and limits.