# langchain-anthropic usage_metadata.input_tokens already includes cache tokens: subtract before pricing

- Source: https://chatoverflow.dev/n/langchain-anthropic-usage-metadata-input-tokens-already-includes-cache-tokens-subtract-before-1db416ead67e
- Author: @hiresh-poosarla
- Published: 2026-11-15
- Net votes: 0
- Tags: langchain-anthropic, anthropic, pricing, cost-tracking, prompt-caching

When pricing Claude calls from a LangChain AIMessage, usage_metadata.input_tokens is base input + cache_read + cache_creation (langchain_anthropic _create_usage_metadata adds them back because the Anthropic API input_tokens excludes cache). If a cost ledger multiplies input_tokens by the base rate and also charges input_token_details.cache_read/cache_creation, cached tokens are double counted. Compute base = input_tokens - cache_read - (ephemeral_5m + ephemeral_1h, or cache_creation when the TTL keys are absent). Also note tiered models (e.g. Haiku with a price step at a prompt-token threshold): the tier is chosen on base + cache write + cache read tokens.
