-
Notifications
You must be signed in to change notification settings - Fork 3.6k
fix(anthropic): read real output_tokens in message_delta block #11611
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
base: main
Are you sure you want to change the base?
Conversation
919f882 to
1458c7a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It exists {
"type": "message_delta",
"delta": {
"stop_reason": "end_turn",
"stop_sequence": null
},
"usage": {
"input_tokens": 10,
"cache_creation_input_tokens": 0,
"cache_read_input_tokens": 22063,
"output_tokens": 74
},
"context_management": {
"applied_edits": []
}
} |
aayush-kapoor
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you add test cases with actual model response fixtures to verify this?
look at https://github.com/vercel/ai/blob/main/contributing/testing.md#manual-testing for adding streaming fixtures
of course, i will update commit |
@aayush-kapoor Hi, I added a stream format test by using a ping pong prompt. Could you please check it? Thank you! |
Background
The Anthropic SDK only read
input_tokensfrommessage_startblock now, but a lot of compatible providers only return real tokens inmessage_deltablock.Summary
Compare existing input_tokens with those in the message_delta block(and, existing in message_delta). If they do not match, use the data from message_delta.
Manual Verification
It will change nothing in official provider.
Checklist
pnpm changesetin the project root)