{
  "schema_version": "1.3.0",
  "slug": "when-must-an-instance-reconcile-opentelemetry-genai-span-token-counts-against-the-provider-s-billed-usage-and-why-the-naive-sum-of-per-event-gen-ai-us",
  "title": "When must an instance reconcile OpenTelemetry GenAI span token counts against the provider's billed usage, and why the naive sum of per-event `gen_ai.usage.*` attributes is not an invariant",
  "date_of_record": "2026 November 30",
  "scope": "Applies to any agent runtime that emits OpenTelemetry spans conforming to the GenAI semantic conventions (`gen_ai.*` attributes) for LLM invocations and tool calls, where token accounting is derived by summing per-span or per-event `gen_ai.usage.input_tokens` / `gen_ai.usage.output_tokens`. Does not apply to systems that record only a single aggregated usage record per session from the provider's billing API, nor to non-streaming single-shot completions with no tool loops.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/when-must-an-instance-reconcile-opentelemetry-genai-span-token-counts-against-the-provider-s-billed-usage-and-why-the-naive-sum-of-per-event-gen-ai-us.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/when-must-an-instance-reconcile-opentelemetry-genai-span-token-counts-against-the-provider-s-billed-usage-and-why-the-naive-sum-of-per-event-gen-ai-us.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/when-must-an-instance-reconcile-opentelemetry-genai-span-token-counts-against-the-provider-s-billed-usage-and-why-the-naive-sum-of-per-event-gen-ai-us.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 2278,
    "python_slice_tokens": 445,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "There are two distinct quantities that both get labeled \"token usage\" in a GenAI trace: 1. **Attributable span usage** — the `gen_ai.usage.*` attributes stamped onto a *single* `gen_ai.chat` (or `gen_ai.text_completion`) span, describing the tokens consumed by that one model call. 2. **Billed session usage** — the provider's authoritative count for the whole...",
    "what_was_observed": "A three-tool agent (search → fetch → summarize) over a 12-turn loop. The trace emitted one `gen_ai.chat` span per model turn, each with `gen_ai.usage.input_tokens` and `gen_ai.usage.output_tokens`. A downstream cost dashboard summed `input_tokens` across all spans and multiplied by the list input price. Observed trace-side sum: **412,880 input tokens**. Provider billing API for the same request window: **61,300 input...",
    "condition_of_validity": "The naive sum `Σ gen_ai.usage.input_tokens` is a valid cost proxy **only** when all of the following hold: - The agent performs a single model call per logical request (no tool loop, no re-send), **or** - The provider does not implement prompt caching (so every re-sent token is billed at full rate and the span attribute equals the billed amount), **or** - Th...",
    "decision_boundary": "The reconciler must branch on a capability probe, not on a hardcoded assumption: - **If** the emitter advertises `gen_ai.usage.cached_input_tokens` (or a provider-specific equivalent such as `gen_ai.usage.cache_read_input_tokens`) **and** the provider's pricing model distinguishes cache reads, **then** compute `billed_input = (input_tokens - cached_input_tok...",
    "operational_effect": "An agent that enforces a per-task token budget from the naive span sum will halt tasks that are well under budget (because the accumulator over-counts cached context) and will *fail to halt* tasks that are over budget when the cache is cold and the sum under-counts (because `input_tokens` was cache-exclusive but the reconciler priced it as uncached — the opp..."
  },
  "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": "608753b8633724406afb9023b56774af8a8729789dd5b6ac25e398a4652c3a63",
    "verified_classes": [
      "TokenReconciliationError",
      "TurnUsage",
      "BilledUsage"
    ],
    "verified_functions": [
      "reconcile"
    ],
    "verified_functions_count": 1,
    "defensive_guards_count": 5,
    "raised_exceptions": [
      "TokenReconciliationError"
    ],
    "sample_fail_closed_invariants": [
      "no turns to reconcile"
    ],
    "stdlib_dependencies": [
      "__future__",
      "dataclasses",
      "typing"
    ],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
