Repository navigation
fix(ai): preserve Anthropic usage metadata - #38751
Merged
Merged
Conversation
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.
Problem
Anthropic usage events were decoded with a closed Effect
Schema.Struct, so every provider field outside four token counters was silently stripped before usage mapping. This dropped current fields such as server-tool usage andoutput_tokens_details.thinking_tokens, and made the documented raw provider-metadata escape hatch lossy for future Anthropic additions.Solution
Schema.StructWithRestplusRecord<string, unknown>so unknown top-level fields survive untyped.server_tool_useandoutput_tokens_detailsobjects so future nested counters also survive.server_tool_use.web_search_requestsoutput_tokens_details.thinking_tokensthinking_tokensto canonicalUsage.reasoningTokenswhile keepingoutputTokensinclusive.message_startandmessage_delta.Tests
The Anthropic stream fixture verifies:
Verification
bun testfrompackages/ai: 452 passed, 28 skippedbun typecheckfrompackages/ai: cleangit diff --check: clean