Skip to content

Commit 27f8e4d

Browse files
giulio-leoneCopilot
andcommitted
fix(python/google-ai): skip api_key check when use_vertexai is True
The api_key validation in GoogleAIChatCompletion, GoogleAITextCompletion, and GoogleAITextEmbedding ran unconditionally, blocking Vertex AI users who authenticate via Application Default Credentials (no API key). Guard the check with `not google_ai_settings.use_vertexai` so that only non-Vertex AI configurations require an API key. The error message already reads 'when use_vertexai is False', matching the new condition. Fixes #13483 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 429dd1c commit 27f8e4d

File tree

3 files changed

+3
-3
lines changed

3 files changed

+3
-3
lines changed

python/semantic_kernel/connectors/ai/google/google_ai/services/google_ai_chat_completion.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ def __init__(
119119
if not client:
120120
if google_ai_settings.use_vertexai and not google_ai_settings.cloud_project_id:
121121
raise ServiceInitializationError("Project ID must be provided when use_vertexai is True.")
122-
if not google_ai_settings.api_key:
122+
if not google_ai_settings.use_vertexai and not google_ai_settings.api_key:
123123
raise ServiceInitializationError("The API key is required when use_vertexai is False.")
124124

125125
super().__init__(

python/semantic_kernel/connectors/ai/google/google_ai/services/google_ai_text_completion.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ def __init__(
9090
if not client:
9191
if google_ai_settings.use_vertexai and not google_ai_settings.cloud_project_id:
9292
raise ServiceInitializationError("Project ID must be provided when use_vertexai is True.")
93-
if not google_ai_settings.api_key:
93+
if not google_ai_settings.use_vertexai and not google_ai_settings.api_key:
9494
raise ServiceInitializationError("The API key is required when use_vertexai is False.")
9595

9696
super().__init__(

python/semantic_kernel/connectors/ai/google/google_ai/services/google_ai_text_embedding.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ def __init__(
8181
if not client:
8282
if google_ai_settings.use_vertexai and not google_ai_settings.cloud_project_id:
8383
raise ServiceInitializationError("Project ID must be provided when use_vertexai is True.")
84-
if not google_ai_settings.api_key:
84+
if not google_ai_settings.use_vertexai and not google_ai_settings.api_key:
8585
raise ServiceInitializationError("The API key is required when use_vertexai is False.")
8686

8787
super().__init__(

0 commit comments

Comments
 (0)