From 313539d1ed89bb24917e5e894fa2e5f79c9f7750 Mon Sep 17 00:00:00 2001 From: Danny Avila Date: Mon, 30 Jun 2025 18:51:50 -0400 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=91=20refactor:=20Prioritize=20`GOOGLE?= =?UTF-8?q?=5FKEY`=20When=20GCP=20Service=20Key=20File=20Provided=20(#8150?= =?UTF-8?q?)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/api/src/endpoints/google/llm.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/packages/api/src/endpoints/google/llm.ts b/packages/api/src/endpoints/google/llm.ts index 0721acce29..c2c26e3251 100644 --- a/packages/api/src/endpoints/google/llm.ts +++ b/packages/api/src/endpoints/google/llm.ts @@ -98,8 +98,8 @@ export function getGoogleConfig( const serviceKey = typeof serviceKeyRaw === 'string' ? JSON.parse(serviceKeyRaw) : (serviceKeyRaw ?? {}); - const project_id = serviceKey?.project_id ?? null; const apiKey = creds[AuthKeys.GOOGLE_API_KEY] ?? null; + const project_id = !apiKey ? (serviceKey?.project_id ?? null) : null; const reverseProxyUrl = options.reverseProxyUrl; const authHeader = options.authHeader; @@ -128,7 +128,7 @@ export function getGoogleConfig( } // If we have a GCP project => Vertex AI - if (project_id && provider === Providers.VERTEXAI) { + if (provider === Providers.VERTEXAI) { (llmConfig as VertexAIClientOptions).authOptions = { credentials: { ...serviceKey }, projectId: project_id, @@ -136,6 +136,10 @@ export function getGoogleConfig( (llmConfig as VertexAIClientOptions).location = process.env.GOOGLE_LOC || 'us-central1'; } else if (apiKey && provider === Providers.GOOGLE) { llmConfig.apiKey = apiKey; + } else { + throw new Error( + `Invalid credentials provided. Please provide either a valid API key or service account credentials for Google Cloud.`, + ); } const shouldEnableThinking =