From 3a13fa80c8677fb4ad6a00afa592c1c32864eedf Mon Sep 17 00:00:00 2001 From: deepkilo Date: Wed, 15 Apr 2026 16:20:45 +0200 Subject: [PATCH] fix(ai): treat gcp vertex marker as ADC auth (#3221) --- packages/ai/src/providers/google-vertex.ts | 3 ++- .../google-vertex-api-key-resolution.test.ts | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/packages/ai/src/providers/google-vertex.ts b/packages/ai/src/providers/google-vertex.ts index 1e189e1b..4e52be08 100644 --- a/packages/ai/src/providers/google-vertex.ts +++ b/packages/ai/src/providers/google-vertex.ts @@ -45,6 +45,7 @@ export interface GoogleVertexOptions extends StreamOptions { } const API_VERSION = "v1"; +const GCP_VERTEX_CREDENTIALS_MARKER = "gcp-vertex-credentials"; const THINKING_LEVEL_MAP: Record = { THINKING_LEVEL_UNSPECIFIED: ThinkingLevel.THINKING_LEVEL_UNSPECIFIED, @@ -370,7 +371,7 @@ function createClientWithApiKey( function resolveApiKey(options?: GoogleVertexOptions): string | undefined { const apiKey = options?.apiKey?.trim() || process.env.GOOGLE_CLOUD_API_KEY?.trim(); - if (!apiKey || isPlaceholderApiKey(apiKey)) { + if (!apiKey || apiKey === GCP_VERTEX_CREDENTIALS_MARKER || isPlaceholderApiKey(apiKey)) { return undefined; } return apiKey; diff --git a/packages/ai/test/google-vertex-api-key-resolution.test.ts b/packages/ai/test/google-vertex-api-key-resolution.test.ts index 38e0fac4..1b3a0655 100644 --- a/packages/ai/test/google-vertex-api-key-resolution.test.ts +++ b/packages/ai/test/google-vertex-api-key-resolution.test.ts @@ -86,6 +86,25 @@ describe("google-vertex api key resolution", () => { expect(googleGenAiMock.constructorCalls[0]).not.toHaveProperty("apiKey"); }); + it("falls back to ADC when options.apiKey is the gcp-vertex-credentials marker", async () => { + const stream = streamGoogleVertex(model, context, { + apiKey: "gcp-vertex-credentials", + project: "test-project", + location: "us-central1", + }); + + await stream.result(); + + expect(googleGenAiMock.constructorCalls).toHaveLength(1); + expect(googleGenAiMock.constructorCalls[0]).toMatchObject({ + vertexai: true, + project: "test-project", + location: "us-central1", + apiVersion: "v1", + }); + expect(googleGenAiMock.constructorCalls[0]).not.toHaveProperty("apiKey"); + }); + it("falls back to ADC when GOOGLE_CLOUD_API_KEY is a placeholder marker", async () => { process.env.GOOGLE_CLOUD_API_KEY = "";