Skip to content

[bot] Anthropic usage extractor drops service_tier and inference_geo execution metadata #45

@braintrust-bot

Description

@braintrust-bot

Summary

The extract_anthropic_usage() function reads token counts from the Anthropic usage object but silently drops the service_tier and inference_geo fields. These fields are part of the Anthropic Messages API response's usage object, are present in the Anthropic Python SDK's Usage type, and Braintrust's Anthropic integration docs state that other SDKs capture them as metadata.

What is missing

Anthropic's Messages API returns two non-token fields inside the usage object:

"usage": {
  "input_tokens": 200,
  "output_tokens": 50,
  "service_tier": "priority",
  "inference_geo": "us-east-1"
}
  • service_tier ("standard" | "priority" | "batch") — which pricing tier processed the request. Priority tier costs more; batch tier is 50% cheaper. Missing this field means cost attribution may use wrong pricing assumptions.
  • inference_geo (string) — geographic region where inference ran. Relevant for data residency compliance and latency analysis.

Currently in src/extractors.rs:92-188, extract_anthropic_usage() reads the usage object and extracts only token-related fields (input_tokens, output_tokens, cache_read_input_tokens, cache_creation_input_tokens, reasoning_tokens, output_tokens_details). Both service_tier and inference_geo are present in the same object but are not read.

The UsageMetrics return type (src/types.rs) is purely token-focused (Option<u32> fields), so there is currently no field to hold string-valued execution metadata. The fix would likely involve either expanding the extractor's return type or providing a separate metadata extraction path so these values can be logged to the span's metadata field.

Why this matters

  • Cost accuracy: Braintrust calculates costs per span. Without service_tier, priority-tier or batch-tier requests may be costed at standard rates.
  • Compliance: inference_geo tells users where their data was processed — important for regulated workloads.

Braintrust docs status

supported — The Braintrust Anthropic integration page states: "Metadata fields track service tier, inference geography, and ephemeral cache variants." Other Braintrust SDKs (TypeScript, Python, Go, Ruby, Java, .NET) capture these fields.

Upstream sources

Relationship to existing issues

Local files inspected

  • src/extractors.rsextract_anthropic_usage() (lines 92-188) reads token fields from usage but does not read service_tier or inference_geo
  • src/types.rsUsageMetrics struct has only Option<u32> fields; no support for string-valued execution metadata
  • Full codebase grep for service_tier, inference_geo — zero results

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions