Skip to content

Conversation

@RogerHYang
Copy link
Contributor

@RogerHYang RogerHYang commented Nov 6, 2025

resolves #2381


Note

Fixes token accounting for Anthropic (including cache read/write) and adds parsing of LangChain UsageMetadata with detailed token breakdown; updates tests and bumps langchain_core minimum.

  • Instrumentation (LangChain tracer):
    • Parse langchain_core.messages.ai.UsageMetadata to emit LLM_TOKEN_COUNT_* (incl. audio, reasoning, cache read/write) with Bedrock Anthropic heuristics.
    • Support raw Anthropic usage with cache_read_input_tokens/cache_creation_input_tokens; compute prompt/completion and cache detail attributes.
    • Refactor _token_counts to use new detectors/extractors while retaining OpenAI/VertexAI paths.
  • Tests:
    • Update Anthropic token count expectation (prompt now includes cache; 33).
    • Add tests/test_token_counts.py with parametrized cases for UsageMetadata and raw Anthropic usage.
  • Dependencies/Tooling:
    • Bump langchain_core min version to >=0.3.9 (and type-check pin).
    • Tox: add uv pip list -v in setup.

Written by Cursor Bugbot for commit 8f3b955. This will update automatically on new commits. Configure here.

@RogerHYang RogerHYang requested a review from a team as a code owner November 6, 2025 16:57
@dosubot dosubot bot added the size:XL This PR changes 500-999 lines, ignoring generated files. label Nov 6, 2025
@RogerHYang RogerHYang marked this pull request as draft November 6, 2025 21:38
@RogerHYang RogerHYang marked this pull request as ready for review November 7, 2025 17:18
@dosubot dosubot bot added size:L This PR changes 100-499 lines, ignoring generated files. and removed size:XL This PR changes 500-999 lines, ignoring generated files. labels Nov 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:L This PR changes 100-499 lines, ignoring generated files.

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

[BUG]: Prompt Caching Price Miscalculation

2 participants