-
Notifications
You must be signed in to change notification settings - Fork 217
fix: double counting anthropic langchain #2838
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: double counting anthropic langchain #2838
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Problem AnalysisThe issue stems from how Anthropic's API reports token usage compared to other LLM providers. When using prompt caching with Anthropic via LangChain:
Changes MadeIn
In
Technical ImplementationThe fix correctly handles the difference in how Anthropic vs other providers report cached tokens:
The token adjustment logic now calculates: Impact and RisksLow Risk Changes:
Potential Considerations:
This is a targeted bug fix with comprehensive test coverage that resolves token accounting accuracy for Anthropic's caching features. |
|
Size Change: +3.72 kB (+0.07%) Total Size: 5.4 MB
ℹ️ View Unchanged
|
80d0fc3 to
1db37f7
Compare
|
@carlos-marchal-ph Is this bug only for the Node SDK? |
It was also present in the Python one, there was another PR for that. |
We were counting cache write tokens incorrectly when using Anthropic with Langchain.
Furthermore, we were sending read tokens under the wrong property name.