Files
Giulio Leone 83ff0a5aaa Python: fix(google-ai): skip api_key check when use_vertexai is True (#13607)
## 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

```python
# 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

- [x] The code builds clean without any errors or warnings
- [x] The PR follows the [SK Contribution
Guidelines](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md)
- [x] The code follows the [SK coding
standards](https://github.com/microsoft/semantic-kernel/blob/main/python/README.md)

---------

Co-authored-by: giulio-leone <giulio.leone@users.noreply.github.com>
Co-authored-by: giulio-leone <6887247+giulio-leone@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-03-24 10:01:54 +00:00
..
2025-01-24 11:02:29 +00:00
2025-06-05 07:18:12 +00:00
2023-08-24 16:07:34 -07:00
2025-07-30 23:04:57 +01:00
2023-07-03 16:32:35 -07:00