Skip to content

fix: normalize all gateway usage results to v3 so usage is populated#12793

Open
AspectFlame wants to merge 7 commits intovercel:mainfrom
AspectFlame:gateway-usage-fix
Open

fix: normalize all gateway usage results to v3 so usage is populated#12793
AspectFlame wants to merge 7 commits intovercel:mainfrom
AspectFlame:gateway-usage-fix

Conversation

@AspectFlame
Copy link
Copy Markdown

@AspectFlame AspectFlame commented Feb 24, 2026

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

  • Tests have been added / updated (for bug fixes / features)
  • Documentation has been added / updated (for bug fixes / features)
  • A patch changeset for relevant packages has been added (for bug fixes / features - run pnpm changeset in the project root)
  • I have reviewed this pull request (self-review)

Fixes #12771

@tigent tigent Bot added ai/gateway bug Something isn't working as documented provider/gateway Issues related to the @ai-sdk/gateway provider labels Feb 24, 2026
Comment thread packages/gateway/src/gateway-language-model.ts Outdated
…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>
@AspectFlame
Copy link
Copy Markdown
Author

@Ayushlm10 could you please provide feedback on my solution if you get a chance?

@gr2m gr2m added ai/provider related to a provider package. Must be assigned together with at least one `provider/*` label and removed ai/gateway labels Mar 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ai/provider related to a provider package. Must be assigned together with at least one `provider/*` label bug Something isn't working as documented provider/gateway Issues related to the @ai-sdk/gateway provider

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ai/6 usage tokens always undefined

2 participants