{"record":{"id":"3e675fe39c44c25d","repo":"microsoft/semantic-kernel","slug":"region-must-be-provided-when-use-vertexai-is-true-3e675f","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_embedding.py","lineNumber":85,"sourceCode":"                embedding_model_id=embedding_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.embedding_model_id:\n            raise ServiceInitializationError(\"The Google AI embedding 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.embedding_model_id,\n            service_id=service_id or google_ai_settings.embedding_model_id,\n            service_settings=google_ai_settings,\n            client=client,\n        )\n\n    @override\n    async def generate_embeddings(\n        self,\n        texts: list[str],\n        settings: \"PromptExecutionSettings | None\" = None,\n        **kwargs: Any,\n    ) -> ndarray:\n        raw_embeddings = await self.generate_raw_embeddings(texts, settings, **kwargs)","sourceCodeStart":67,"sourceCodeEnd":103,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/python/semantic_kernel/connectors/ai/google/google_ai/services/google_ai_text_embedding.py#L67-L103","documentation":"Raised in the GoogleAITextEmbedding constructor when use_vertexai is True but cloud_region is absent. The Vertex AI embedding endpoint requires a region/location to determine the endpoint URL. The guard runs only when no custom client is supplied.","triggerScenarios":"Constructing GoogleAITextEmbedding(use_vertexai=True) without region and without GOOGLE_AI_CLOUD_REGION.","commonSituations":"Configured project_id but omitted region; env var GOOGLE_AI_CLOUD_REGION missing; used an alternative variable 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 GoogleAITextEmbedding constructor.","Supply a pre-configured google.genai Client if you manage the Vertex endpoint yourself."],"exampleFix":"# before\nembed = GoogleAITextEmbedding(use_vertexai=True, embedding_model_id='text-embedding-004', project_id='proj')\n\n# after\nembed = GoogleAITextEmbedding(\n    use_vertexai=True, embedding_model_id='text-embedding-004',\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 embeddings.')","typeGuard":null,"tryCatchPattern":"try:\n    service = GoogleAITextEmbedding(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 embedding service.')\n    raise","preventionTips":["Always set GOOGLE_AI_CLOUD_REGION with GOOGLE_AI_CLOUD_PROJECT_ID for Vertex AI.","Use a known-good region from the Vertex AI supported regions list.","Bundlle project_id and region in one configuration object."],"tags":["google-ai","vertex-ai","region","configuration","embeddings","constructor"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}