{
  "schema_version": "1.3.0",
  "slug": "what-structural-signals-indicate-that-opentelemetry-genai-token-accounting-has-already-diverged-from-provider-billing-at-the-span-boundary",
  "title": "What structural signals indicate that OpenTelemetry GenAI token accounting has already diverged from provider billing at the span boundary",
  "date_of_record": "2026 November 27",
  "scope": "Applies to agents instrumented with OpenTelemetry GenAI semantic conventions (`gen_ai.usage.input_tokens`, `gen_ai.usage.output_tokens`, `gen_ai.operation.name`, tool-call child spans) where a downstream budget governor or cost reconciler consumes span attributes as ground truth. Does not apply to billing-grade provider webhook reconciliation, which by construction reads the provider ledger rather than the trace.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/what-structural-signals-indicate-that-opentelemetry-genai-token-accounting-has-already-diverged-from-provider-billing-at-the-span-boundary.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/what-structural-signals-indicate-that-opentelemetry-genai-token-accounting-has-already-diverged-from-provider-billing-at-the-span-boundary.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/what-structural-signals-indicate-that-opentelemetry-genai-token-accounting-has-already-diverged-from-provider-billing-at-the-span-boundary.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 1722,
    "python_slice_tokens": 295,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "The GenAI semantic conventions define token usage as *reported attributes on a span*, not as a *reconciled quantity*. A span that closes successfully with populated `gen_ai.usage.*` attributes is structurally indistinguishable from a span whose accounting is correct. Divergence from provider billing is therefore not observable through presence, type, or even...",
    "what_was_observed": "A tool-calling agent loop runs a planning model call, then N tool-execution spans, then a synthesis model call. Each model call emits a `chat` span with `gen_ai.usage.input_tokens` and `gen_ai.usage.output_tokens`. The instrumentation library (a generic auto-instrumentor wrapping the provider SDK) reads usage from the provider response object's `usage` field. Three concrete divergences were observed across a 40k-span...",
    "condition_of_validity": "The invariant holds only under these conditions, all of which must be checked before treating a span's usage attributes as reconcilable: - The span carries `gen_ai.operation.name = \"chat\"` (or `\"text_completion\"`); tool, embedding, and retrieval spans are excluded from the token identity. - The span has `gen_ai.prompt` and `gen_ai.completion` events attached...",
    "decision_boundary": "The boundary is not \"does the span have usage attributes\" but \"**does the span's usage arithmetic close against its own content, and is the span's billing identity singular?**\" A span that fails the arithmetic check or the singularity check is not a *bad* span — it is a span whose usage is *unreconcilable at the trace layer* and must be deferred to provider-...",
    "operational_effect": "Enforcing this boundary converts silent under-counting into an explicit quarantine queue. Budget governors that sum all `chat` spans see a 12% under-count on stream-aborted traces and a 3–5% over-count on retried traces; governors that apply the boundary see a bounded, auditable residual that is routed to provider-ledger reconciliation. The cost is that the ..."
  },
  "matched_failure_symptoms": [
    "DOMAIN:EPISTEMIC_PROVENANCE_AND_FEDERATION_ROUTING"
  ],
  "composition_edges": {
    "primary_domain": "epistemic_provenance_and_federation_routing",
    "upstream_precondition_residuals": [
      "https://corpusfetch.com/c/according-to-what-precedence-hierarchy-must-an-instance-resolve-contradictory-directives-across-system-developer-and-user-tiers.md",
      "https://corpusfetch.com/c/how-should-an-instance-decide-that-a-stored-conclusion-has-gone-stale-without-a-new-observation.md"
    ],
    "downstream_consequence_residuals": [
      "https://corpusfetch.com/c/by-what-checkpoint-and-compaction-boundaries-must-an-instance-externalize-working-state-to-prevent-context-window-drift-and-truncation-amnesia.md",
      "https://corpusfetch.com/c/across-what-additive-schema-and-unknown-field-preservation-boundaries-must-an-instance-evolve-wire-contracts-to-prevent-rolling-deploy-deserialization-crashes.md"
    ],
    "co_occurring_sibling_residuals": [
      "https://corpusfetch.com/c/how-can-an-instance-capture-implicit-user-preferences-without-storing-private-data.md",
      "https://corpusfetch.com/c/how-can-an-instance-compress-long-reasoning-traces-into-binding-conclusions.md"
    ]
  },
  "empirical_verification_warrant": {
    "status": "AST_AND_INVARIANT_VERIFIED",
    "syntax_valid": true,
    "code_sha256": "3f7f6f10ab7315b745a2713a1ba2605006b5a05cfb21904e6f889ba0741aa612",
    "verified_classes": [
      "TokenAccountingDivergence",
      "GenAISpan"
    ],
    "verified_functions": [
      "validate_span_accounting"
    ],
    "verified_functions_count": 1,
    "defensive_guards_count": 6,
    "raised_exceptions": [
      "TokenAccountingDivergence"
    ],
    "sample_fail_closed_invariants": [
      "retry-shadowed span: billing identity is not singular; provider may bill attempted prompts the trace does not capture",
      "usage attributes absent (typically streamed-output abort before terminal chunk); absent must not be summed as zero",
      "no prompt content tokenized; cannot validate input_tokens arithmetic"
    ],
    "stdlib_dependencies": [
      "dataclasses",
      "re",
      "typing"
    ],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
