{
  "schema_version": "1.3.0",
  "slug": "what-happens-when-an-instance-emits-genai-tool-call-spans-with-gen-ai-usage-input-tokens-counted-at-the-wrong-layer",
  "title": "What happens when an instance emits GenAI tool-call spans with `gen_ai.usage.input_tokens` counted at the wrong layer",
  "date_of_record": "2026 November 15",
  "scope": "Applies to OpenTelemetry GenAI semantic conventions (v1.27–v1.34) for chat/inference spans that contain `gen_ai.tool.call` child spans and report token usage. Does not apply to pure embedding spans, or to spans where token accounting is delegated entirely to a downstream provider SDK without instrumentation.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/what-happens-when-an-instance-emits-genai-tool-call-spans-with-gen-ai-usage-input-tokens-counted-at-the-wrong-layer.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/what-happens-when-an-instance-emits-genai-tool-call-spans-with-gen-ai-usage-input-tokens-counted-at-the-wrong-layer.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/what-happens-when-an-instance-emits-genai-tool-call-spans-with-gen-ai-usage-input-tokens-counted-at-the-wrong-layer.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 1633,
    "python_slice_tokens": 264,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "The GenAI semantic conventions define two independent attribute families that are frequently conflated at instrumentation time: 1. **Usage attributes** (`gen_ai.usage.input_tokens`, `gen_ai.usage.output_tokens`) — defined as the token counts *for the model inference operation represented by the span*. 2. **Tool-call attributes** (`gen_ai.tool.name`, `gen_ai....",
    "what_was_observed": "An agent loop was instrumented with a hand-rolled span wrapper that emitted one `gen_ai.chat` span per model call and one `gen_ai.tool` span per tool invocation. The wrapper read `response.usage` from the provider response object and, on any span that received a non-null usage object, wrote `gen_ai.usage.input_tokens` and `gen_ai.usage.output_tokens`. Because the tool-execution path re-entered the wrapper with the *s...",
    "condition_of_validity": "The convention's token accounting is only meaningful when all of the following hold: - `gen_ai.usage.input_tokens` is set **only** on `gen_ai.chat` / inference spans, and reflects the *cumulative* prompt tokens for that specific model call (including prior assistant turns and tool results already in the context). - `gen_ai.tool.call.id` on the tool span matc...",
    "decision_boundary": "The operational decision is: **where does the usage attribute get written, and against which response snapshot?** - If your instrumentation writes usage at the point the provider response is received, *before* the tool result is folded in, the parent span is a valid single-turn record. Do not also emit usage on the tool span. Accept that the trace's total in...",
    "operational_effect": "Downstream consumers — cost aggregation, token-budget enforcement, rate-limit forecasting, and eval harnesses that normalize by token count — all inherit the placement error. Because the error is directional (under-count on chat spans, double-count on tool spans) and correlates with tool use, it degrades exactly the workloads (agents, multi-step reasoning) t..."
  },
  "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": "9c086311d1401d1a67060865fc36cc3b55d55040a480e72cc7c68b0bc1d67501",
    "verified_classes": [
      "GenAIUsagePlacementError",
      "SpanRecord"
    ],
    "verified_functions": [
      "validate_usage_placement"
    ],
    "verified_functions_count": 1,
    "defensive_guards_count": 3,
    "raised_exceptions": [
      "GenAIUsagePlacementError"
    ],
    "sample_fail_closed_invariants": [],
    "stdlib_dependencies": [
      "dataclasses",
      "typing"
    ],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
