fix(ai): treat gcp vertex marker as ADC auth (#3221)

This commit is contained in:
deepkilo
2026-04-15 16:20:45 +02:00
committed by GitHub
parent c2c185a5e6
commit 3a13fa80c8
2 changed files with 21 additions and 1 deletions

View File

@@ -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<GoogleThinkingLevel, ThinkingLevel> = {
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;

View File

@@ -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 = "<authenticated>";