Skip to content

Python: fix(google-ai): skip api_key check when use_vertexai is True#13607

Open
giulio-leone wants to merge 1 commit intomicrosoft:mainfrom
giulio-leone:fix/issue-13483-google-ai-vertexai-api-key
Open

Python: fix(google-ai): skip api_key check when use_vertexai is True#13607
giulio-leone wants to merge 1 commit intomicrosoft:mainfrom
giulio-leone:fix/issue-13483-google-ai-vertexai-api-key

Conversation

@giulio-leone
Copy link

Summary

Fixes #13483

Motivation and Context

When use_vertexai=True, users authenticate via Application Default Credentials (ADC) and don't need an API key. However, the initialization check for api_key runs unconditionally, blocking Vertex AI users with:

ServiceInitializationError: The API key is required when use_vertexai is False.

Description

Guard the api_key validation with not google_ai_settings.use_vertexai in all three Google AI service classes:

  • GoogleAIChatCompletion
  • GoogleAITextCompletion
  • GoogleAITextEmbedding

The error message already reads "when use_vertexai is False", so the condition now matches the intent.

Before / After

# Before — fails even with use_vertexai=True
GoogleAIChatCompletion(
    use_vertexai=True,
    cloud_project_id="my-project",
    cloud_region="us-central1"
)
# → ServiceInitializationError: The API key is required when use_vertexai is False.

# After — works correctly
GoogleAIChatCompletion(
    use_vertexai=True,
    cloud_project_id="my-project",
    cloud_region="us-central1"
)
# → Initializes successfully, uses ADC for authentication

Contribution Checklist

@giulio-leone giulio-leone requested a review from a team as a code owner February 28, 2026 12:34
@moonbox3 moonbox3 added the python Pull requests for the Python Semantic Kernel label Feb 28, 2026
@giulio-leone
Copy link
Author

@microsoft-github-policy-service agree

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 microsoft#13483
@giulio-leone giulio-leone force-pushed the fix/issue-13483-google-ai-vertexai-api-key branch from 27f8e4d to ce250e0 Compare February 28, 2026 14:51
@giulio-leone
Copy link
Author

Friendly ping — CI is green and this is ready for review. Happy to address any feedback. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

python Pull requests for the Python Semantic Kernel

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Python: Bug: GoogleAIChatCompletion wrongly requires api_key even when use_vertexai is set to True

2 participants