Skip to content

Commit 313539d

Browse files
authored
🔑 refactor: Prioritize GOOGLE_KEY When GCP Service Key File Provided (danny-avila#8150)
1 parent f869d77 commit 313539d

File tree

1 file changed

+6
-2
lines changed
  • packages/api/src/endpoints/google

1 file changed

+6
-2
lines changed

‎packages/api/src/endpoints/google/llm.ts‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,8 @@ export function getGoogleConfig(
9898
const serviceKey =
9999
typeof serviceKeyRaw === 'string' ? JSON.parse(serviceKeyRaw) : (serviceKeyRaw ?? {});
100100

101-
const project_id = serviceKey?.project_id ?? null;
102101
const apiKey = creds[AuthKeys.GOOGLE_API_KEY] ?? null;
102+
const project_id = !apiKey ? (serviceKey?.project_id ?? null) : null;
103103

104104
const reverseProxyUrl = options.reverseProxyUrl;
105105
const authHeader = options.authHeader;
@@ -128,14 +128,18 @@ export function getGoogleConfig(
128128
}
129129

130130
// If we have a GCP project => Vertex AI
131-
if (project_id && provider === Providers.VERTEXAI) {
131+
if (provider === Providers.VERTEXAI) {
132132
(llmConfig as VertexAIClientOptions).authOptions = {
133133
credentials: { ...serviceKey },
134134
projectId: project_id,
135135
};
136136
(llmConfig as VertexAIClientOptions).location = process.env.GOOGLE_LOC || 'us-central1';
137137
} else if (apiKey && provider === Providers.GOOGLE) {
138138
llmConfig.apiKey = apiKey;
139+
} else {
140+
throw new Error(
141+
`Invalid credentials provided. Please provide either a valid API key or service account credentials for Google Cloud.`,
142+
);
139143
}
140144

141145
const shouldEnableThinking =

0 commit comments

Comments
 (0)