Skip to content

fix(langchain): avoid double-counting cached input tokens#445

Merged
Abhijeet Prasad (AbhiPrasad) merged 1 commit into
mainfrom
abhi-fix-bt-5310-langchain-cache-tokens
May 20, 2026
Merged

fix(langchain): avoid double-counting cached input tokens#445
Abhijeet Prasad (AbhiPrasad) merged 1 commit into
mainfrom
abhi-fix-bt-5310-langchain-cache-tokens

Conversation

@AbhiPrasad
Copy link
Copy Markdown
Member

Only fold cache tokens into prompt and total metrics when LangChain reports cache tokens separately from input tokens. This preserves Anthropic-style cache normalization while avoiding double-counting for OpenAI-style responses where cached tokens are already included in input_tokens.

Adds regression coverage for OpenAI cached token metrics.

resolves https://linear.app/braintrustdata/issue/BT-5310/langchain-callback-double-counts-cache-tokens-for-openai-after-pr-411

Only fold cache tokens into prompt and total metrics when LangChain reports cache tokens separately from input tokens. This preserves Anthropic-style cache normalization while avoiding double-counting for OpenAI-style responses where cached tokens are already included in input_tokens.

Adds regression coverage for OpenAI cached token metrics.
@AbhiPrasad Abhijeet Prasad (AbhiPrasad) merged commit de28291 into main May 20, 2026
82 checks passed
@AbhiPrasad Abhijeet Prasad (AbhiPrasad) deleted the abhi-fix-bt-5310-langchain-cache-tokens branch May 20, 2026 14:36
Abhijeet Prasad (AbhiPrasad) added a commit that referenced this pull request May 20, 2026
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.

2 participants