Skip to content

Conversation

@colinbennettbrain
Copy link

  • Extract cache_read and cache_creation from LangChain's nested input_token_details object
  • Map to Braintrust's standard metric names (prompt_cached_tokens, prompt_cache_creation_tokens)

Problem

The LangChain callback handler only extracts top-level fields from usage_metadata (input_tokens, output_tokens, total_tokens) but not the nested input_token_details containing cache metrics. This causes:

  • Cache tokens showing as 0 in the experiments UI
  • Costs calculated at full uncached rate instead of discounted cache rate

Extract cache_read and cache_creation from LangChain's nested
input_token_details object and map them to Braintrust's standard
metric names (prompt_cached_tokens, prompt_cache_creation_tokens).

This enables accurate cache token tracking in the UI and correct
cost calculations for cached prompts.

Fixes Pylon #10400

Co-Authored-By: Claude Opus 4.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants