{
  "schema_version": "1.3.0",
  "slug": "where-must-an-instance-reconcile-prompt-completion-span-attributes-when-token-counts-diverge-from-billed-cost-attribution",
  "title": "Where must an instance reconcile prompt/completion span attributes when token counts diverge from billed cost attribution",
  "date_of_record": "2026 November 28",
  "scope": "Applies to LLM-serving instances that emit OpenTelemetry-style prompt/completion spans with semantic-convention attributes (`gen_ai.usage.input_tokens`, `gen_ai.usage.output_tokens`, `gen_ai.usage.total_tokens`, `gen_ai.request.model`) and separately reconcile those spans against a billing/cost ledger. Does not apply to batch inference jobs that never emit per-call spans, nor to pure-cost observability that never attributes back to a span.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/where-must-an-instance-reconcile-prompt-completion-span-attributes-when-token-counts-diverge-from-billed-cost-attribution.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/where-must-an-instance-reconcile-prompt-completion-span-attributes-when-token-counts-diverge-from-billed-cost-attribution.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/where-must-an-instance-reconcile-prompt-completion-span-attributes-when-token-counts-diverge-from-billed-cost-attribution.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 1578,
    "python_slice_tokens": 179,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "The failure is not \"token counts are wrong.\" It is that two independent accounting surfaces — the **span attribute surface** (what the model server reports at emit time) and the **billing ledger surface** (what the provider invoices after the fact) — disagree on the unit of accounting, and the semantic convention gives no invariant binding them. `gen_ai.usag...",
    "what_was_observed": "A serving instance emitted prompt/completion spans for a multi-turn agent loop. For each call it set: The downstream cost aggregator multiplied `total_tokens` by the model's per-token price and wrote a cost record keyed by span ID. Three divergences appeared simultaneously: 1. **Cached-prefix divergence.** The provider billed 1834 input tokens but applied a 40% cached-prefix discount to 1600 of them. The span carried...",
    "condition_of_validity": "The reconciliation invariant holds only when all of the following are true at emit time: - Every cost-bearing attribute carries a provenance marker distinguishing **provider-reported** from **locally-computed** values. A span where `total_tokens` was computed as `input + output` by the instance is not the same artifact as one where the provider reported it, ...",
    "decision_boundary": "An instance must decide, per span, one of three dispositions before the span enters the cost path: - **Reconcilable:** all billing-relevant sub-counts present and provenance-marked. Price directly. - **Deferred:** span carries a count the provider prices but the sub-counts are absent (e.g., no cached-token attribute, no reasoning-token attribute). Hold the s...",
    "operational_effect": "After enforcing the three-disposition boundary, the observed window's per-span cost records summed to 1.00× the invoice within a 0.3% tolerance, and the residual was fully explained by the `cost_attribution_gap` events (retry pairs and one model-attribute mismatch). The cost of the fix is that a fraction of spans — in this workload, 18% — are never priced at..."
  },
  "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": "4d9d341c7a03c0990ab4363d0fe7d8232d7ebea301c40c59b56b599b954ead28",
    "verified_classes": [
      "CostAttributionError",
      "Disposition",
      "Span"
    ],
    "verified_functions": [
      "classify",
      "price_span"
    ],
    "verified_functions_count": 2,
    "defensive_guards_count": 1,
    "raised_exceptions": [
      "CostAttributionError"
    ],
    "sample_fail_closed_invariants": [],
    "stdlib_dependencies": [
      "dataclasses",
      "enum"
    ],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
