Files
langchain/libs/partners
Bagatur Askaryan aec13fc781 feat(anthropic): track service_tier and inference_geo in usage_metadata
Mirrors the existing langchain-openai service_tier breakdown so downstream
pricing/analytics can apply Anthropic's priority-tier (~1.5x) and US-only
inference (1.1x) multipliers.

- `_create_usage_metadata` now reads `usage.service_tier` and
  `usage.inference_geo` (or accepts explicit overrides). For
  `service_tier in {priority, batch}` it prefixes the cache_read /
  cache_creation / ephemeral keys with the tier and adds a bare tier key
  equal to non-cache input. For `inference_geo == "us"` it adds a bare
  `us` key equal to full input/output totals (1.1x applies to every
  category).
- `service_tier` and `inference_geo` are echoed into `response_metadata`
  (and `llm_output` already carries the full usage object).
- Streaming threads `service_tier` and `inference_geo` from
  `message_start.message.usage` through a new `stream_state` dict so the
  final `message_delta` chunk gets the breakdown — Anthropic's
  `MessageDeltaUsage` doesn't carry these fields directly. The values are
  only emitted on the final delta chunk to avoid string concatenation
  during chunk merging.
2026-05-28 15:15:17 -04:00
..
2026-05-21 17:55:36 -04:00

FAQ

Looking for an integration not listed here? Check out the integrations documentation and the note in the libs/ README about third-party maintained packages.

Integration docs

For full documentation, see the primary and API reference docs for integrations.