{"record":{"id":"4aebc7cd2e5ea2a9","repo":"microsoft/semantic-kernel","slug":"region-must-be-provided-when-use-vertexai-is-true-4aebc7","errorCode":null,"errorMessage":"Region must be provided when use_vertexai is True.","messagePattern":"Region must be provided when use_vertexai is True\\.","errorType":"exception","errorClass":"ServiceInitializationError","httpStatus":null,"severity":"error","filePath":"python/semantic_kernel/connectors/ai/google/google_ai/services/google_ai_text_completion.py","lineNumber":94,"sourceCode":"                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\n    # Override from AIServiceClientBase\n    @override\n    def get_prompt_execution_settings_class(self) -> type[\"PromptExecutionSettings\"]:\n        return GoogleAITextPromptExecutionSettings\n\n    @override","sourceCodeStart":76,"sourceCodeEnd":112,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/python/semantic_kernel/connectors/ai/google/google_ai/services/google_ai_text_completion.py#L76-L112","documentation":"Raised in the GoogleAITextCompletion constructor when use_vertexai is True but cloud_region is not provided. The Vertex AI backend needs a region/location (e.g. 'us-central1') to determine the API endpoint. The check runs only when no custom client was supplied, meaning the service must construct the google.genai.Client itself and needs the region.","triggerScenarios":"Constructing GoogleAITextCompletion(use_vertexai=True) without a region argument and without GOOGLE_AI_CLOUD_REGION in the environment.","commonSituations":"Configured project_id but forgot region; env var GOOGLE_AI_CLOUD_REGION missing; used GOOGLE_REGION or GOOGLE_CLOUD_REGION instead of the prefixed GOOGLE_AI_ name.","solutions":["Set GOOGLE_AI_CLOUD_REGION=<region> in your environment or .env file (e.g. GOOGLE_AI_CLOUD_REGION=us-central1).","Pass region=<region> to the GoogleAITextCompletion constructor.","Provide a custom google.genai Client (break-glass) if you configure the Vertex endpoint yourself."],"exampleFix":"# before\nservice = GoogleAITextCompletion(use_vertexai=True, gemini_model_id='gemini-2.0-flash', project_id='proj')\n\n# after\nservice = GoogleAITextCompletion(\n    use_vertexai=True, gemini_model_id='gemini-2.0-flash',\n    project_id='proj', region='us-central1',\n)","handlingStrategy":"validation","validationCode":"import os\nif os.environ.get('GOOGLE_AI_USE_VERTEXAI', '').lower() == 'true':\n    if not os.environ.get('GOOGLE_AI_CLOUD_REGION'):\n        raise EnvironmentError('Set GOOGLE_AI_CLOUD_REGION when using Vertex AI.')","typeGuard":null,"tryCatchPattern":"try:\n    service = GoogleAITextCompletion(use_vertexai=True)\nexcept ServiceInitializationError as e:\n    if 'Region must be provided' in str(e):\n        logging.error('Missing GOOGLE_AI_CLOUD_REGION for Vertex AI mode.')\n    raise","preventionTips":["Set GOOGLE_AI_CLOUD_REGION alongside GOOGLE_AI_CLOUD_PROJECT_ID whenever use_vertexai is True.","Use a supported Vertex AI region (e.g. us-central1, europe-west1).","Bundlle project_id and region in a single config step to avoid partial configuration."],"tags":["google-ai","vertex-ai","region","configuration","text-completion","constructor"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}