fix(anthropic): fix token accounting#5490
Conversation
Semver Impact of This PR🟢 Patch (bug fixes) 📋 Changelog PreviewThis is how your changes will appear in the changelog. Bug Fixes 🐛
Internal Changes 🔧
🤖 This preview updates automatically when you update the PR. |
Codecov Results 📊✅ 13 passed | Total: 13 | Pass Rate: 100% | Execution Time: 7.79s All tests are passing successfully. ❌ Patch coverage is 0.00%. Project has 13701 uncovered lines. Files with missing lines (180)
Generated by Codecov Action |
| # Anthropic's input_tokens excludes cached/cache_write tokens. | ||
| # Normalize to total input tokens so downstream cost calculations | ||
| # (input_tokens - cached) don't produce negative values. | ||
| input_tokens += cache_read_input_tokens + cache_write_input_tokens |
There was a problem hiding this comment.
you're already adding cache read and write outside afterwards, can remove this.
There was a problem hiding this comment.
No I don't think we can remove this - there are two codepaths below, one of them for non-streaming and one for streaming. The streaming one does not use this function to retrieve the cost, so it needs to normalize separately
alexander-alderman-webb
left a comment
There was a problem hiding this comment.
I would expect existing tests to change, can you please verify why they still pass even though the behavior has changed @shellmayr 🙏
alexander-alderman-webb
left a comment
There was a problem hiding this comment.
ah it's fine the tests aren't great.
|
@alexander-alderman-webb had a look at the tests - they didn't assert on the total tokens, etc, only the cache tokens. adapted them so they would have failed, as a regression test going forward |
Uh oh!
There was an error while loading. Please reload this page.