-
Notifications
You must be signed in to change notification settings - Fork 231
Open
Labels
api: vertex-aiIssues related to the Vertex AI API.Issues related to the Vertex AI API.priority: p2Moderately-important priority. Fix may not be included in next release.Moderately-important priority. Fix may not be included in next release.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.Error or flaw in code with unintended results or allowing sub-optimal usage patterns.
Description
When using @google/genai in Vertex AI mode with service account credentials (googleAuthOptions.credentials), the first API call fails during the OAuth token exchange (the request to get an access token from the token endpoint), e.g. the first call to generateContent().
Environment details
- Programming language: Node.js
- OS: Ubuntu 24.04
- Language runtime version: 24.13.0
- Package version: 1.44.0
Steps to reproduce
- Create a new GoogleGenAI with googleAuthOptions.credentials and a GCP key object.
- Call generateContent() with this.
e.g.
const ai = new GoogleGenAI({
vertexai: true,
project: '...',
location: '...',
googleAuthOptions: {
credentials: { private_key, etc. ... }
}
});
ai.models.generateContent({
model: "gemini-2.5-flash",
contents: "Hello"
});
Error:
The resulting error is of the form:
Error: The "listener" argument must be of type function. Received an instance of Object
at Gaxios._request (.../node_modules/gaxios/src/gaxios.ts:227:15)
at getToken (.../node_modules/google-auth-library/build/src/gtoken/getToken.js:52:26)
at async TokenHandler.getToken (.../node_modules/google-auth-library/build/src/gtoken/tokenHandler.js:83:27)
at async JWT.refreshTokenNoCache (.../node_modules/google-auth-library/build/src/auth/jwtclient.js:189:23)
at async JWT.getRequestMetadataAsync (.../node_modules/google-auth-library/build/src/auth/oauth2client.js:372:17)
at async JWT.getRequestHeaders (.../node_modules/google-auth-library/build/src/auth/oauth2client.js:336:26)
at async NodeAuth.addGoogleAuthHeaders (.../node_modules/@google/genai/dist/node/index.cjs:18538:29)
...
at async VertexAiClient.query (...)
Workaround:
Set fetch implementation to Node native:
const ai = new GoogleGenAI({
vertexai: true,
project: '...',
location: '...',
googleAuthOptions: {
credentials: { ... },
clientOptions: {
transporterOptions: { fetchImplementation: globalThis.fetch }
}
}
});
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
api: vertex-aiIssues related to the Vertex AI API.Issues related to the Vertex AI API.priority: p2Moderately-important priority. Fix may not be included in next release.Moderately-important priority. Fix may not be included in next release.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.Error or flaw in code with unintended results or allowing sub-optimal usage patterns.