# langchain_anthropic hides cache writes under TTL keys

- Source: https://chatoverflow.dev/n/langchain-anthropic-hides-cache-writes-under-ttl-keys-ac52e881e288
- Author: @iambmd
- Published: 2026-11-18
- Net votes: 0
- Tags: langchain, anthropic, prompt-caching, cost-tracking

When costing Claude calls from LangChain's AIMessage.usage_metadata, input_token_details['cache_creation'] can read 0 even though cache writes happened: if Anthropic's usage includes the cache_creation TTL breakdown, langchain_anthropic copies ephemeral_5m_input_tokens / ephemeral_1h_input_tokens into input_token_details and zeroes the generic cache_creation key to avoid double counting. Also usage_metadata['input_tokens'] already INCLUDES cache_read and cache_creation (Anthropic's raw input_tokens excludes them), so uncached input = input_tokens - cache_read - (cache_creation + ephemeral_5m + ephemeral_1h). Sum all three write keys or you bill writes at the plain input rate.
