# Under what conditions must an instance reject a GenAI span whose token-accounting attributes were derived from a different model than the one named in `genai.request.model`? **Date of Record:** 2026 November 28 **Scope:** Applies to any agent runtime that emits OpenTelemetry GenAI spans where `genai.usage.input_tokens`/`output_tokens` may be populated by a router, proxy, or sidecar that is not the component that executed the inference. Does not apply to single-model, single-process instrumentation where the executing client and the span emitter are the same object and no routing layer sits between them. ## Core Distinction The GenAI semantic conventions treat `genai.request.model` and `genai.usage.*_tokens` as attributes of *one* span describing *one* inference call. They are not independently trustworthy fields. The non-obvious failure is a **provenance split**: a routing layer (a model gateway, a fallback wrapper, a speculative-decoding proxy) rewrites the request to a different model than the one the caller named, and it also writes the token counts it observed from the *backend* response onto a span whose `genai.request.model` still carries the *caller's* original model string. The span is internally consistent as a record but externally false as a measurement: the token count belongs to model B while the model attribute names model A. Downstream cost attribution, context-budget accounting, and model-quality regression analysis all silently corrupt. The boundary condition is: **a GenAI span is only valid if the model identity used to compute token counts is the same model identity recorded in the span's model attributes.** When a routing hop breaks that identity, the span must be rejected or re-labeled, not merged. ## What Was Observed A tool-calling agent routed through a gateway that implements "cheap-first, escalate-on-failure" fallback. The caller requested `genai.request.model = "frontier-large"`. The gateway attempted the call on `small-cheap`, the tool schema negotiation failed on the first attempt (the small model emitted a malformed arguments object), the gateway silently retried against `frontier-large`, and the call succeeded. The emitted span carried: - `genai.request.model = "frontier-large"` (the caller's original string, preserved by the gateway) - `genai.response.model = "frontier-large"` (from the final backend response) - `genai.usage.input_tokens = 4102`, `genai.usage.output_tokens = 88` — but these were the *summed* counts across both attempts, with the failed `small-cheap` attempt contributing roughly 3,900 input tokens of schema and tool definitions plus a partial output. The span was schema-valid. Every attribute was present and well-typed. A validator checking only for attribute presence and type passed it. But the token count was a mixture from two different models, attributed entirely to one. Cost dashboards over-attributed ~3,900 tokens to `frontier-large` pricing (roughly 15× the `small-cheap` rate), and the context-budget accounting for the agent's next turn assumed 4,190 tokens had been consumed from a 200k window when the *effective* context the frontier model saw was only ~300 tokens. A second, subtler instance: a speculative-decoding proxy where the draft model's tokens are not billed to the caller but the proxy still wrote the draft model's acceptance-sampling token counts into `genai.usage.output_tokens`. The `genai.request.model` named the target model. The number was right for the proxy's internal accounting and wrong for the caller's. ## Condition of Validity The invariant: **for a GenAI span to be a valid measurement, the tuple (`genai.request.model`, `genai.response.model`, `genai.usage.input_tokens`, `genai.usage.output_tokens`) must all describe the same single inference execution.** This is a *conjunctive* condition. It does not hold when any of the following is true: 1. The span aggregates token counts across more than one backend model (fallback, retry-on-different-model, ensemble, speculative decoding with a distinct draft model). 2. The span's model attribute was preserved from the caller's request while the executing model differed (routing rewrite without re-labeling). 3. The token counts were produced by a component (gateway, proxy, sidecar) that observed the backend response but did not observe which model produced it. When any of these hold, the span is not "slightly noisy" — it is a category error. The correct resolution is one of two, never a silent merge: - **Split the span.** Emit one child span per backend attempt, each with its own `genai.request.model` reflecting the model *actually invoked* for that attempt, and its own token counts. The parent span carries no `genai.usage.*` attributes at all. This preserves the per-model truth and lets the aggregator sum correctly by model. - **Re-label and mark.** If a single span is mandatory (e.g., the backend provides no per-attempt breakdown), set `genai.request.model` to the model that actually produced the counted tokens, and add an explicit attribute (e.g., `genai.routing.fallback = true`, `genai.routing.attempts = 2`) so downstream consumers know the count is not attributable to the caller's requested model. What is *not* valid: keeping the caller's model string and the backend's blended token count on the same span with no marker. That combination is the failure. ## Decision Boundary The emitter must decide, at span-close time, between *accept*, *split*, and *relabel*. The decision hinges on whether the emitter can prove single-model provenance: - If the emitter is the executing client and no routing hop exists → accept. The tuple is trivially coherent. - If a routing hop exists and the emitter can observe per-attempt model + per-attempt usage → split. This is the default for any gateway that sees backend responses. - If a routing hop exists and the emitter *cannot* decompose the usage (backend returns only a total) → relabel to the dominant/final model and set the routing marker. Do not accept. - If the emitter cannot determine which model produced the counts at all → reject the usage attributes entirely. Emit the span with model attributes but omit `genai.usage.*`; a missing measurement is honest, a false one is not. The trap is treating "all attributes present and well-typed" as "valid." Schema conformance is necessary and insufficient. The provenance check is the actual gate. ## Operational Effect Downstream consumers of GenAI spans — cost ledgers, context-window budgeters, model-quality regression harnesses, and routing-policy learners — all assume per-model attribution. A blended-count span poisons each differently: - **Cost ledgers** over- or under-charge by the price ratio between the models involved (here ~15×). - **Context budgeters** over-count consumed context, causing premature truncation or unnecessary summarization on the *next* turn, because they believe the window is fuller than it is. - **Regression harnesses** attribute a small model's failure-mode tokens to the large model, degrading the large model's apparent efficiency. - **Routing learners** trained on these spans learn that the large model "consumes" far more tokens than it does, biasing the policy toward the small model for reasons that are artifacts of the instrumentation, not the models. The guardrail is a provenance validator that runs at span-close and refuses to emit a coherent-looking-but-false tuple. The validator below encodes the decision boundary: it accepts single-model spans, splits or relabels routed spans, and rejects usage attributes it cannot attribute. ```python from dataclasses import dataclass, field from typing import Optional class GenAISpanProvenanceError(RuntimeError): """Raised when a GenAI span's token-accounting provenance cannot be reconciled with its model identity.""" pass @dataclass class Attempt: model: str input_tokens: int output_tokens: int @dataclass class GenAISpan: request_model: str response_model: Optional[str] = None input_tokens: Optional[int] = None output_tokens: Optional[int] = None routing_fallback: bool = False routing_attempts: int = 1 def validate_and_emit(span: GenAISpan, attempts: list[Attempt]) -> list[GenAISpan]: """Enforce the conjunctive provenance invariant. Returns the list of spans that should actually be emitted. May be the original span (accept), a set of per-attempt child spans (split), or a relabeled span (relabel). Raises if the tuple is incoherent and undecomposable. """ # Case 1: single-model, single-attempt -> accept as-is. if len(attempts) <= 1 and (span.routing_attempts <= 1): if span.input_tokens is None or span.output_tokens is None: raise GenAISpanProvenanceError( f"single-attempt span for {span.request_model!r} is missing " f"usage attributes; cannot emit a partial measurement" ) return [span] # Case 2: multiple attempts observed -> split into per-attempt children. distinct_models = {a.model for a in attempts} if len(distinct_models) > 1: emitted = [] for i, a in enumerate(attempts): emitted.append(GenAISpan( request_model=a.model, response_model=a.model, input_tokens=a.input_tokens, output_tokens=a.output_tokens, routing_fallback=True, routing_attempts=len(attempts), )) # Parent/aggregate span must NOT carry usage attributes. parent = GenAISpan( request_model=span.request_model, response_model=span.response_model, input_tokens=None, output_tokens=None, routing_fallback=True, routing_attempts=len(attempts), ) emitted.append(parent) return emitted # Case 3: multiple attempts, single model -> relabel is safe only if # the aggregate count actually matches the per-attempt sum. total_in = sum(a.input_tokens for a in attempts) total_out = sum(a.output_tokens for a in attempts) if (span.input_tokens, span.output_tokens) != (total_in, total_out): raise GenAISpanProvenanceError( f"aggregate usage ({span.input_tokens},{span.output_tokens}) does " f"not match per-attempt sum ({total_in},{total_out}) for model " f"{span.request_model!r}; provenance is unreconcilable" ) span.routing_fallback = True span.routing_attempts = len(attempts) return [span] ```