{"record":{"id":"080843bb769a8b98","repo":"microsoft/semantic-kernel","slug":"the-google-ai-gemini-model-id-is-required","errorCode":null,"errorMessage":"The Google AI Gemini model ID is required.","messagePattern":"The Google AI Gemini model ID is required\\.","errorType":"exception","errorClass":"ServiceInitializationError","httpStatus":null,"severity":"error","filePath":"python/semantic_kernel/connectors/ai/google/google_ai/services/google_ai_chat_completion.py","lineNumber":117,"sourceCode":"\n        Raises:\n            ServiceInitializationError: If an error occurs during initialization.\n        \"\"\"\n        try:\n            google_ai_settings = GoogleAISettings(\n                gemini_model_id=gemini_model_id,\n                api_key=api_key,\n                cloud_project_id=project_id,\n                cloud_region=region,\n                use_vertexai=use_vertexai,\n                env_file_path=env_file_path,\n                env_file_encoding=env_file_encoding,\n            )\n        except ValidationError as e:\n            raise ServiceInitializationError(f\"Failed to validate Google AI settings: {e}\") from e\n\n        if not google_ai_settings.gemini_model_id:\n            raise ServiceInitializationError(\"The Google AI Gemini model ID is required.\")\n\n        if not client:\n            if google_ai_settings.use_vertexai and not google_ai_settings.cloud_project_id:\n                raise ServiceInitializationError(\"Project ID must be provided when use_vertexai is True.\")\n            if google_ai_settings.use_vertexai and not google_ai_settings.cloud_region:\n                raise ServiceInitializationError(\"Region must be provided when use_vertexai is True.\")\n            if not google_ai_settings.use_vertexai and not google_ai_settings.api_key:\n                raise ServiceInitializationError(\"The API key is required when use_vertexai is False.\")\n\n        super().__init__(\n            ai_model_id=google_ai_settings.gemini_model_id,\n            service_id=service_id or google_ai_settings.gemini_model_id,\n            service_settings=google_ai_settings,\n            client=client,\n        )\n\n    # region Overriding base class methods\n","sourceCodeStart":99,"sourceCodeEnd":135,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/python/semantic_kernel/connectors/ai/google/google_ai/services/google_ai_chat_completion.py#L99-L135","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"# before\nsvc = GoogleAIChatCompletion()  # GOOGLE_AI_GEMINI_MODEL_ID unset\n# after\nsvc = GoogleAIChatCompletion(gemini_model_id=\"gemini-1.5-pro\")","handlingStrategy":"validation","validationCode":"def has_gemini_model_id(model_id: str | None) -> bool:\n    return isinstance(model_id, str) and bool(model_id.strip())","typeGuard":"def is_non_empty_model_id(value: object) -> bool:\n    return isinstance(value, str) and bool(value.strip())","tryCatchPattern":"from semantic_kernel.exceptions.service_exceptions import ServiceInitializationError\n\ntry:\n    svc = GoogleAIChatCompletion(gemini_model_id=model_id)\nexcept ServiceInitializationError as e:\n    if \"model ID is required\" in str(e):\n        raise ValueError(\"Set GOOGLE_AI_GEMINI_MODEL_ID or pass gemini_model_id\") from e\n    raise","preventionTips":["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."],"tags":["google-ai","gemini","model-id","initialization","configuration"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}