fix: reuse google auth per provider instance#14102
Merged
aayush-kapoor merged 1 commit intovercel:mainfrom May 1, 2026
Merged
Conversation
Collaborator
aayush-kapoor
left a comment
There was a problem hiding this comment.
thank you for the PR! changes look good, you'll just need to resolve the conflicts and sign your commits please.
e847339 to
bb137a4
Compare
Contributor
Author
|
Conflicts resolved and commits signed. |
Collaborator
|
apologies for the back and forth but there's a change coming in #14857 that will cause this to conflict again. i'll ask you to resolve it again since that will be merged first. thank you |
bb137a4 to
20b3dcb
Compare
Contributor
Author
|
No Problem. Merge conflicts solved. |
aayush-kapoor
approved these changes
May 1, 2026
Contributor
|
|
5 tasks
gr2m
pushed a commit
that referenced
this pull request
May 1, 2026
## Background the change in #14102 didn't pull from latest main and didn't account for the latest vertex/xai package created. and thus `main` on that path was using the wrong import ## Summary use correct import
aayush-kapoor
added a commit
that referenced
this pull request
May 1, 2026
This is an automated backport of #14102 to the release-v6.0 branch. FYI @heiwen This backport has conflicts that need to be resolved manually. ### `git cherry-pick` output ``` Auto-merging packages/google-vertex/src/anthropic/google-vertex-anthropic-provider-node.test.ts CONFLICT (content): Merge conflict in packages/google-vertex/src/anthropic/google-vertex-anthropic-provider-node.test.ts Auto-merging packages/google-vertex/src/anthropic/google-vertex-anthropic-provider-node.ts Auto-merging packages/google-vertex/src/google-vertex-auth-google-auth-library.ts CONFLICT (content): Merge conflict in packages/google-vertex/src/google-vertex-auth-google-auth-library.ts Auto-merging packages/google-vertex/src/google-vertex-provider.test.ts CONFLICT (content): Merge conflict in packages/google-vertex/src/google-vertex-provider.test.ts Auto-merging packages/google-vertex/src/google-vertex-provider.ts CONFLICT (content): Merge conflict in packages/google-vertex/src/google-vertex-provider.ts Auto-merging packages/google-vertex/src/maas/google-vertex-maas-provider-node.test.ts Auto-merging packages/google-vertex/src/maas/google-vertex-maas-provider-node.ts error: could not apply 96d056d... fix: reuse google auth per provider instance (#14102) 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: Aayush Kapoor <aayushkapoor34@gmail.com> Co-authored-by: Aayush Kapoor <83492835+aayush-kapoor@users.noreply.github.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
@ai-sdk/google-vertexused a module-levelGoogleAuthcache in the shared Node auth helper. That cache was invalidated by object reference equality, which caused unnecessaryGoogleAuthrecreation in two cases:googleAuthOptionswould recreate auth when requests alternated between them.googleAuthOptionswas omitted,generateAuthToken(options || {})created a new empty object on every call, so auth could be recreated on every request even for a single provider.Because
GoogleAuthcaches the resolved auth client on the instance, recreating it discards warm auth state and can add avoidable auth overhead.Summary
This PR removes the module-level
GoogleAuthsingleton from@ai-sdk/google-vertex's shared Node auth helper and replaces it with a per-provider auth token generator.Changes included:
generateAuthToken(options)helper withcreateAuthTokenGenerator(options), which creates oneGoogleAuthinstance and returns a reusable token generator closure.@ai-sdk/google-vertex@ai-sdk/google-vertex/anthropic@ai-sdk/google-vertex/maasgoogleAuthOptions@ai-sdk/google-vertexManual Verification
I manually verified the change by inspecting the Node auth flow and confirming the auth generator is now created once during provider construction rather than on each request path.
Concretely:
createAuthTokenGenerator(options.googleAuthOptions)once at provider initializationundefined -> {}invalidation path is goneI also verified behavior through automated coverage:
pnpm --filter @ai-sdk/google-vertex test:nodepnpm type-check:fullChecklist
pnpm changesetin the project root)Future Work
A follow-up PR could evaluate whether the Edge auth path should also cache tokens or auth state more aggressively, since it uses a different implementation and is not addressed here.
Related Issues
Fixes #14101