{"record":{"id":"5715f29c68c6f75f","repo":"microsoft/semantic-kernel","slug":"project-id-must-be-provided-when-use-vertexai-is-t-5715f2","errorCode":null,"errorMessage":"Project ID must be provided when use_vertexai is True.","messagePattern":"Project ID 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":83,"sourceCode":"        try:\n            google_ai_settings = GoogleAISettings(\n                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,","sourceCodeStart":65,"sourceCodeEnd":101,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/python/semantic_kernel/connectors/ai/google/google_ai/services/google_ai_text_embedding.py#L65-L101","documentation":"Raised in the GoogleAITextEmbedding constructor when use_vertexai is True but cloud_project_id is absent. The Vertex AI embedding endpoint requires a Google Cloud project ID to route requests. The guard runs only when no custom client is supplied.","triggerScenarios":"Constructing GoogleAITextEmbedding(use_vertexai=True) without project_id and without GOOGLE_AI_CLOUD_PROJECT_ID.","commonSituations":"Migrating embedding service to Vertex AI and forgetting the project; env var not set; used an unprefixed project variable name.","solutions":["Set GOOGLE_AI_CLOUD_PROJECT_ID=<gcp-project-id> in your environment or .env file.","Pass project_id=<gcp-project-id> to the GoogleAITextEmbedding constructor.","Double-check that use_vertexai=True is intentional; otherwise use api_key flow."],"exampleFix":"# before\nembed = GoogleAITextEmbedding(use_vertexai=True, embedding_model_id='text-embedding-004')\n\n# after\nembed = GoogleAITextEmbedding(\n    use_vertexai=True, embedding_model_id='text-embedding-004',\n    project_id='my-gcp-project', 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_PROJECT_ID'):\n        raise EnvironmentError('Set GOOGLE_AI_CLOUD_PROJECT_ID when using Vertex AI embeddings.')","typeGuard":null,"tryCatchPattern":"try:\n    service = GoogleAITextEmbedding(use_vertexai=True)\nexcept ServiceInitializationError as e:\n    if 'Project ID must be provided' in str(e):\n        logging.error('Missing GOOGLE_AI_CLOUD_PROJECT_ID for Vertex AI embedding service.')\n    raise","preventionTips":["Bundle project_id and region with use_vertexai=True in a single config step.","Keep a shared Vertex AI config used by both text and embedding services.","Document Vertex AI prerequisites in your project setup guide."],"tags":["google-ai","vertex-ai","project-id","configuration","embeddings","constructor"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}