fix: normalize all gateway usage results to v3 so usage is populated#12793
Open
AspectFlame wants to merge 7 commits intovercel:mainfrom
Open
fix: normalize all gateway usage results to v3 so usage is populated#12793AspectFlame wants to merge 7 commits intovercel:mainfrom
AspectFlame wants to merge 7 commits intovercel:mainfrom
Conversation
Co-authored-by: Cursor <cursoragent@cursor.com>
…tTokens to be a valid object instead of having an addi Only require inputTokens to be a valid object instead of having an additional check. Co-authored-by: vercel[bot] <35613825+vercel[bot]@users.noreply.github.com>
Author
|
@Ayushlm10 could you please provide feedback on my solution if you get a chance? |
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
Fix to #12771
Previously, the gateway backend returned usage in AISDK's v2 shape, including inputTokens and outputTokens as numbers, regardless of the spec version. Because the AISDK gateway v3 emits specificationVersion: "v3", the process to convert v2 usage to v3 usage never happened, so result.usage remained undefined.
Summary
In /gateway, I added normalizeGatewayUsageToV3() to convert v2 usage results to v3 usage results before returning them. I used existing tests that assert that usage is normalized to v3 shape to verify that my solution works.
Manual Verification
I used generateText() on a local example and confirmed that result.usage has numeric values filled out, instead of being undefined.
Checklist
pnpm changesetin the project root)Fixes #12771