{"record":{"id":"d11463bc4240c352","repo":"microsoft/semantic-kernel","slug":"the-google-ai-gemini-model-id-is-required-d11463","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":"critical","filePath":"python/semantic_kernel/connectors/ai/google/google_ai/services/google_ai_text_completion.py","lineNumber":88,"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":70,"sourceCodeEnd":106,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/python/semantic_kernel/connectors/ai/google/google_ai/services/google_ai_text_completion.py#L70-L106","documentation":"Raised in the GoogleAITextCompletion constructor when GoogleAISettings resolves gemini_model_id to None or empty. Text completion (generate_content) requires an explicit Gemini model name to target. The settings model marks gemini_model_id as str | None, so it is not enforced by Pydantic — this guard catches the 'absent' case after successful Pydantic construction.","triggerScenarios":"Constructing GoogleAITextCompletion() with no gemini_model_id argument and no GOOGLE_AI_GEMINI_MODEL_ID environment variable set.","commonSituations":"Forgetting to export the model ID env var; using a .env file that lacks GOOGLE_AI_GEMINI_MODEL_ID; misnaming the variable (e.g. GOOGLE_AI_MODEL_ID without 'GEMINI').","solutions":["Set GOOGLE_AI_GEMINI_MODEL_ID=<model> in your environment or .env file (e.g. GOOGLE_AI_GEMINI_MODEL_ID=gemini-2.0-flash).","Pass gemini_model_id=<model> as a keyword argument to GoogleAITextCompletion().","Confirm your env_file_path points to the .env file that actually contains the variable."],"exampleFix":"# before\nservice = GoogleAITextCompletion(api_key=key)\n\n# after\nservice = GoogleAITextCompletion(api_key=key, gemini_model_id='gemini-2.0-flash')","handlingStrategy":"validation","validationCode":"import os\nif not os.environ.get('GOOGLE_AI_GEMINI_MODEL_ID'):\n    raise EnvironmentError('Set GOOGLE_AI_GEMINI_MODEL_ID before constructing GoogleAITextCompletion.')","typeGuard":null,"tryCatchPattern":"try:\n    service = GoogleAITextCompletion()\nexcept ServiceInitializationError as e:\n    if 'Gemini model ID is required' in str(e):\n        os.environ['GOOGLE_AI_GEMINI_MODEL_ID'] = 'gemini-2.0-flash'\n        service = GoogleAITextCompletion()\n    else:\n        raise","preventionTips":["Set GOOGLE_AI_GEMINI_MODEL_ID in your .env and load it with python-dotenv at app start.","Fail fast in CI if required env vars are missing.","Pass gemini_model_id explicitly in code to avoid env-var discovery ambiguity."],"tags":["google-ai","gemini","model-id","configuration","text-completion","constructor"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}