Skip to content

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

Open
giulio-leone wants to merge 2 commits 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 2 commits 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

@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!

Copilot AI review requested due to automatic review settings March 4, 2026 04:29
@giulio-leone giulio-leone force-pushed the fix/issue-13483-google-ai-vertexai-api-key branch from ce250e0 to 3814db8 Compare March 4, 2026 04:29
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes Google AI connector initialization for Vertex AI usage by skipping the api_key requirement when use_vertexai=True, aligning the validation logic with the intended ADC authentication path.

Changes:

  • Guard api_key validation with not use_vertexai in GoogleAIChatCompletion.
  • Guard api_key validation with not use_vertexai in GoogleAITextCompletion.
  • Guard api_key validation with not use_vertexai in GoogleAITextEmbedding.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.

File Description
python/semantic_kernel/connectors/ai/google/google_ai/services/google_ai_chat_completion.py Skip API key validation when using Vertex AI during initialization.
python/semantic_kernel/connectors/ai/google/google_ai/services/google_ai_text_completion.py Skip API key validation when using Vertex AI during initialization.
python/semantic_kernel/connectors/ai/google/google_ai/services/google_ai_text_embedding.py Skip API key validation when using Vertex AI during initialization.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@giulio-leone
Copy link
Author

Hi! Gentle ping — this PR is rebased, CI passes, and ready for review. Happy to address any feedback. Thanks!

giulio-leone and others added 2 commits March 6, 2026 13:12
@giulio-leone giulio-leone force-pushed the fix/issue-13483-google-ai-vertexai-api-key branch from 94d8643 to d8cb434 Compare March 6, 2026 12:12
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

3 participants