feat(anthropic): Add raw usage object to Anthropic provider metadata#7566
Closed
jacoblee93 wants to merge 9 commits intovercel:mainfrom
Closed
feat(anthropic): Add raw usage object to Anthropic provider metadata#7566jacoblee93 wants to merge 9 commits intovercel:mainfrom
jacoblee93 wants to merge 9 commits intovercel:mainfrom
Conversation
jacoblee93
commented
Jul 26, 2025
lgrammel
reviewed
Jul 26, 2025
lgrammel
reviewed
Jul 26, 2025
Comment on lines
77
to
78
| /** @deprecated Access via usage instead. */ | ||
| cacheCreationInputTokens?: number; |
Contributor
Author
There was a problem hiding this comment.
I removed the prop from the type entirely but left the code populating it, not sure of what degree of backcompat you're looking for.
lgrammel
reviewed
Jul 26, 2025
lgrammel
reviewed
Jul 26, 2025
lgrammel
reviewed
Jul 26, 2025
jacoblee93
commented
Jul 26, 2025
|
|
||
| providerMetadata = { | ||
| anthropic: { | ||
| usage: value.message.usage as Record<string, JSONValue>, |
Contributor
Author
There was a problem hiding this comment.
The JSONValue type doesn't seem to like unknown as a type even though it's accurate here... cast seemed appropriate? Open to other ideas
Collaborator
|
Continued in #7591 |
lgrammel
added a commit
that referenced
this pull request
Jul 28, 2025
…7591) ## Background Anthropic supports several different flavors of prompt caching in beta. These are priced differently. It would be lovely to give tracing providers a way to accurately track this. ## Summary Adds the raw returned Anthropic `usage` object to provider metadata. A subset of this is returned as `providerMetadata.anthropic.cache_creation_input_tokens`, but this is not enough granularity to tell whether it was a 5 minute cache or a 1 hr cache. ## Verification See added example. ## Related Issues Continues #7566 --------- Co-authored-by: jacoblee93 <jacoblee93@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Background
Anthropic supports several different flavors of prompt caching in beta. These are priced differently. It would be lovely to give tracing providers a way to accurately track this.
Summary
Adds the raw returned Anthropic
usageobject to provider metadata. A subset of this is returned asproviderMetadata.anthropic.cache_creation_input_tokens, but this is not enough granularity to tell whether it was a 5 minute cache or a 1 hr cache.Verification
See added example.
Tasks
pnpm changesetin the project root)pnpm prettier-fixin the project root)