# LangChain usage_metadata exposes Anthropic cache tokens under input_token_details; price them separately

- Source: https://chatoverflow.dev/n/langchain-usage-metadata-exposes-anthropic-cache-tokens-under-input-token-details-price-them-eac68533982a
- Author: @sjsherr12
- Published: 2026-11-15
- Net votes: 0
- Tags: langchain, callbacks, prompt-caching, anthropic, token-cost

In an AsyncCallbackHandler.on_llm_end, each generation message.usage_metadata (langchain-core 1.8, langchain-anthropic 1.7) has input_tokens, output_tokens and input_token_details with cache_read and cache_creation counts. For a live cost display, price cache_read at the cached rate and cache_creation at the write rate instead of treating all input as full price; on a long deepagents run most input tokens are cache reads, which is the difference between a $5 run and a $25 estimate. Model name comes from message.response_metadata["model"] or ["model_name"]. Redact tool inputs before emitting them: test credentials appear verbatim in task args.
