microsoft/semantic-kernel · error · ServiceInitializationError
The Google AI Gemini model ID is required.
Error message
The Google AI Gemini model ID is required.
What it means
Raised during GoogleAIChatCompletion.__init__ when the resolved GoogleAISettings.gemini_model_id is falsy (None or empty string). Even though the field is optional in settings (so it passes pydantic validation), the service cannot operate without a model ID, so construction is rejected after settings load.
Source
Thrown at python/semantic_kernel/connectors/ai/google/google_ai/services/google_ai_chat_completion.py:117
Raises:
ServiceInitializationError: If an error occurs during initialization.
"""
try:
google_ai_settings = GoogleAISettings(
gemini_model_id=gemini_model_id,
api_key=api_key,
cloud_project_id=project_id,
cloud_region=region,
use_vertexai=use_vertexai,
env_file_path=env_file_path,
env_file_encoding=env_file_encoding,
)
except ValidationError as e:
raise ServiceInitializationError(f"Failed to validate Google AI settings: {e}") from e
if not google_ai_settings.gemini_model_id:
raise ServiceInitializationError("The Google AI Gemini model ID is required.")
if not client:
if google_ai_settings.use_vertexai and not google_ai_settings.cloud_project_id:
raise ServiceInitializationError("Project ID must be provided when use_vertexai is True.")
if google_ai_settings.use_vertexai and not google_ai_settings.cloud_region:
raise ServiceInitializationError("Region must be provided when use_vertexai is True.")
if not google_ai_settings.use_vertexai and not google_ai_settings.api_key:
raise ServiceInitializationError("The API key is required when use_vertexai is False.")
super().__init__(
ai_model_id=google_ai_settings.gemini_model_id,
service_id=service_id or google_ai_settings.gemini_model_id,
service_settings=google_ai_settings,
client=client,
)
# region Overriding base class methods
View on GitHub (pinned to c028a0c7dc)
Solutions
- Set GOOGLE_AI_GEMINI_MODEL_ID to a valid model (e.g. gemini-1.5-pro) in the environment or .env.
- Pass gemini_model_id explicitly to the constructor.
- Verify the env_file_path/encoding arguments point to the .env file that actually defines the variable.
Example fix
# before svc = GoogleAIChatCompletion() # GOOGLE_AI_GEMINI_MODEL_ID unset # after svc = GoogleAIChatCompletion(gemini_model_id="gemini-1.5-pro")
Defensive patterns
Strategy: validation
Validate before calling
def has_gemini_model_id(model_id: str | None) -> bool:
return isinstance(model_id, str) and bool(model_id.strip()) Type guard
def is_non_empty_model_id(value: object) -> bool:
return isinstance(value, str) and bool(value.strip()) Try / catch
from semantic_kernel.exceptions.service_exceptions import ServiceInitializationError
try:
svc = GoogleAIChatCompletion(gemini_model_id=model_id)
except ServiceInitializationError as e:
if "model ID is required" in str(e):
raise ValueError("Set GOOGLE_AI_GEMINI_MODEL_ID or pass gemini_model_id") from e
raise Prevention
- Always set GOOGLE_AI_GEMINI_MODEL_ID in the environment or pass gemini_model_id explicitly.
- Verify the .env path/encoding so the variable is actually loaded.
- Add a startup check that the model ID env var is present.
When it happens
Trigger: Constructing GoogleAIChatCompletion without a gemini_model_id argument and without GOOGLE_AI_GEMINI_MODEL_ID in the environment/.env, so the settings field resolves to None.
Common situations: Missing GOOGLE_AI_GEMINI_MODEL_ID env var; typo in the env var name; .env not loaded (wrong path/encoding); passing gemini_model_id=None explicitly and relying on env that is absent.
Related errors
- The Google AI Gemini model ID is required.
- Failed to validate Google AI settings: {e}
- Project ID must be provided when use_vertexai is True.
- Region must be provided when use_vertexai is True.
- The API key is required when use_vertexai is False.
AI-assisted analysis of microsoft/semantic-kernel@c028a0c7dc (2026-08-13).
Data as JSON: /api/errors/080843bb769a8b98.
Report an issue: GitHub.