{
  "schema_version": "1.3.0",
  "slug": "where-must-an-instance-of-gen-ai-usage-input-tokens-be-attributed-when-an-agent-span-both-invokes-a-tool-and-re-enters-the-model",
  "title": "Where must an instance of `gen_ai.usage.input_tokens` be attributed when an agent span both invokes a tool and re-enters the model?",
  "date_of_record": "2026 November 12",
  "scope": "Applies to OpenTelemetry GenAI semantic conventions (v1.x, `gen_ai.*` attributes) for agent spans that emit both tool-call child spans and follow-up model invocations within a single logical agent turn. Does not apply to single-shot inference spans, nor to spans where token usage is reported only at the session/root level by an external aggregator.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/where-must-an-instance-of-gen-ai-usage-input-tokens-be-attributed-when-an-agent-span-both-invokes-a-tool-and-re-enters-the-model.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/where-must-an-instance-of-gen-ai-usage-input-tokens-be-attributed-when-an-agent-span-both-invokes-a-tool-and-re-enters-the-model.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/where-must-an-instance-of-gen-ai-usage-input-tokens-be-attributed-when-an-agent-span-both-invokes-a-tool-and-re-enters-the-model.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 1444,
    "python_slice_tokens": 330,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "The GenAI conventions define `gen_ai.usage.input_tokens` and `gen_ai.usage.output_tokens` as *per-inference-call* attributes, not per-agent-turn totals. A common and non-obvious failure arises because an agent span is conceptually one \"operation\" but physically contains *N* model invocations (one before a tool call, one after the tool result is returned). Th...",
    "what_was_observed": "In a LangChain-style agent loop instrumented with a custom `gen_ai` exporter, the following span tree was emitted for a single user turn that required one tool call: - `invoke_agent` (span kind INTERNAL) — attributes: `gen_ai.operation.name=invoke_agent`, `gen_ai.usage.input_tokens=1840`, `gen_ai.usage.output_tokens=112` - └ `chat` (span kind CLIENT) — `gen_ai.operation.name=chat`, `gen_ai.usage.input_tokens=1840`, `...",
    "condition_of_validity": "The invariant \"sum of span-level `gen_ai.usage.*` equals provider billing\" holds **only if all three** of the following are true: 1. Every model invocation within the turn is represented by exactly one span carrying `gen_ai.operation.name` in `{chat, text_completion, generate_content}`. 2. No ancestor span (agent, workflow, session) carries `gen_ai.usage.inp...",
    "decision_boundary": "When deciding where to place usage attributes, use this test: - **Does this span directly correspond to a single request to a model provider endpoint?** → Yes: it is an inference span; write `gen_ai.usage.*` here. - **Does this span aggregate or orchestrate multiple such requests?** → Yes: it is an agent/workflow span; it MUST NOT carry `gen_ai.usage.*`. Agg...",
    "operational_effect": "The practical consequence: cost attribution per agent, per tool, and per turn diverges from provider billing in a way that is *structurally biased upward* (because the first inference's usage is the most likely to be hoisted). Teams observing this typically add a \"reconciliation\" job that compares summed span tokens against the billing API and applies a fudg..."
  },
  "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": "0e4c68d8f1aa6440e7b82f6b154d6e9bd0e8c4a5a8590ef88afc11564744e2e6",
    "verified_classes": [
      "GenAIUsageAttributionError"
    ],
    "verified_functions": [
      "validate_usage_attribution",
      "reconcile_turn_tokens"
    ],
    "verified_functions_count": 2,
    "defensive_guards_count": 3,
    "raised_exceptions": [
      "GenAIUsageAttributionError"
    ],
    "sample_fail_closed_invariants": [],
    "stdlib_dependencies": [
      "__future__",
      "typing"
    ],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
