Skip to content

fix(google-vertex): use per-instance auth token generator to avoid cache thrashing#14103

Open
Jah-yee wants to merge 1 commit intovercel:mainfrom
Jah-yee:fix/google-auth-cache-invalidation
Open

fix(google-vertex): use per-instance auth token generator to avoid cache thrashing#14103
Jah-yee wants to merge 1 commit intovercel:mainfrom
Jah-yee:fix/google-auth-cache-invalidation

Conversation

@Jah-yee
Copy link
Copy Markdown

@Jah-yee Jah-yee commented Apr 3, 2026

Closes #14101

The previous module-level singleton used reference equality to detect
options changes, which caused two issues:

  1. Multiple provider instances with equivalent googleAuthOptions would
    thrash the singleton when alternating between them
  2. Omitted googleAuthOptions would create a new empty object each call,
    causing unnecessary recreation

This fix replaces the shared helper with a factory function that creates
a per-instance auth token generator. Each provider instance now gets
stable auth/client caching without requiring structural serialization.


Changes:

  • Added factory function in
  • Updated to use per-instance auth generator
  • Kept backward-compatible function for other consumers

…che thrashing

The previous module-level singleton used reference equality to detect
options changes, which caused two issues:

1. Multiple provider instances with equivalent googleAuthOptions would
   thrash the singleton when alternating between them
2. Omitted googleAuthOptions would create a new empty object each call,
   causing unnecessary recreation

This fix replaces the shared helper with a factory function that creates
a per-instance auth token generator. Each provider instance now gets
stable auth/client caching without requiring structural serialization.

Closes vercel#14101
@tigent tigent bot added 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/google-vertex Issues related to the @ai-sdk/google-vertex provider labels Apr 3, 2026
Copy link
Copy Markdown
Contributor

@vercel vercel bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Additional Suggestions:

  1. Test file imports _resetAuthInstance which was removed from the source module, causing the test to fail at import time.
  1. Anthropic vertex provider uses deprecated generateAuthToken which creates a new GoogleAuth instance on every API request, causing a performance regression.
  1. Test mocks generateAuthToken but production code now imports and uses createAuthTokenGenerator, causing all tests to fail with createAuthTokenGenerator is not a function.

Fix on Vercel

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/google-vertex Issues related to the @ai-sdk/google-vertex provider

Projects

None yet

Development

Successfully merging this pull request may close these issues.

@ai-sdk/google-vertex Node auth helper recreates GoogleAuth too often due to reference-based cache invalidation

1 participant