fix(google): read serviceTier from usageMetadata in stream + generate#15488
Merged
Conversation
…generate and stream paths The previous implementation read `serviceTier` from the `x-gemini-service-tier` response header, which is only populated on non-streaming responses. Gemini streaming includes the value in `usageMetadata.serviceTier` on every chunk, so `providerMetadata.google.serviceTier` was always `null` for streams. Read from `usageMetadata` for both paths instead. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
felixarntz
approved these changes
May 20, 2026
Contributor
|
|
shaper
added a commit
that referenced
this pull request
May 20, 2026
- Keep release-v6.0 file structure (providerOptionsName indirection, GoogleGenerativeAI* type names, GoogleGenerativeAITokenDetail). - Adopt the actual semantic change from #15488: read `serviceTier` from `usageMetadata.serviceTier` (body) in both doGenerate and doStream, instead of the `x-gemini-service-tier` response header. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
shaper
added a commit
that referenced
this pull request
May 20, 2026
…+ generate (#15490) This is an automated backport of #15488 to the release-v6.0 branch. FYI @shaper This backport has conflicts that need to be resolved manually. ### `git cherry-pick` output ``` Auto-merging content/providers/01-ai-sdk-providers/15-google.mdx Auto-merging packages/google/src/convert-google-generative-ai-usage.ts CONFLICT (content): Merge conflict in packages/google/src/convert-google-generative-ai-usage.ts Auto-merging packages/google/src/google-generative-ai-language-model.test.ts Auto-merging packages/google/src/google-generative-ai-language-model.ts CONFLICT (content): Merge conflict in packages/google/src/google-generative-ai-language-model.ts error: could not apply 045d2e8... fix(google): read serviceTier from usageMetadata in stream + generate (#15488) hint: After resolving the conflicts, mark them with hint: "git add/rm <pathspec>", then run hint: "git cherry-pick --continue". hint: You can instead skip this commit with "git cherry-pick --skip". hint: To abort and get back to the state before "git cherry-pick", hint: run "git cherry-pick --abort". hint: Disable this message with "git config set advice.mergeConflict false" ``` --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Walter Korman <shaper@vercel.com> Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Contributor
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.
Summary
x-gemini-service-tierresponse header (non-streaming only) andusageMetadata.serviceTierin the response body (both streaming and non-streaming).providerMetadata.google.serviceTierwas alwaysnullonstreamText.usageMetadata.serviceTierfrom the body for bothdoGenerateanddoStream. Single source of truth, no header involvement, matches the pattern Vertex already uses (usageMetadata.trafficType).Test plan
pnpm testinpackages/google— 583 tests pass (node + edge), incl. two new tests assertingserviceTieris populated fromusageMetadatain both generate and stream paths.pnpm type-check:full— clean.pnpm tsx src/generate-text/google/service-tier.ts→serviceTier: priority(still works after dropping header read)pnpm tsx src/stream-text/google/service-tier.ts→serviceTier: priority(previouslynull)pnpm tsx src/generate-text/google/vertex-service-tier.ts→trafficType: ON_DEMAND_PRIORITYpnpm tsx src/stream-text/google/vertex-service-tier.ts→trafficType: ON_DEMAND_PRIORITY🤖 Generated with Claude Code