{"record":{"id":"45d7ec814ce0af9c","repo":"microsoft/semantic-kernel","slug":"project-id-must-be-provided-when-use-vertexai-is-t","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_chat_completion.py","lineNumber":121,"sourceCode":"        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\n    # Override from AIServiceClientBase\n    @override\n    def get_prompt_execution_settings_class(self) -> type[\"PromptExecutionSettings\"]:\n        return GoogleAIChatPromptExecutionSettings","sourceCodeStart":103,"sourceCodeEnd":139,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/python/semantic_kernel/connectors/ai/google/google_ai/services/google_ai_chat_completion.py#L103-L139","documentation":"Raised during GoogleAIChatCompletion.__init__ when use_vertexai is True, no client was injected, and cloud_project_id is missing. The Vertex AI client requires a Google Cloud project ID to construct, so SK rejects initialization before attempting the call.","triggerScenarios":"Constructing with use_vertexai=True (via arg or GOOGLE_AI_USE_VERTEXAI=true) without GOOGLE_AI_CLOUD_PROJECT_ID or a project_id argument, and without providing a prebuilt client.","commonSituations":"Switching from Gemini API key mode to Vertex AI mode but forgetting to set the project ID; env var typo GOOGLE_AI_CLOUD_PROJECT_ID; .env not loaded; assuming project_id is optional under Vertex AI.","solutions":["Set GOOGLE_AI_CLOUD_PROJECT_ID to your GCP project ID, or pass project_id='my-project' to the constructor.","Confirm use_vertexai is actually True (it defaults to False) so the check reflects your intent.","If you already have a google.genai Client configured for Vertex AI, pass it as client= to bypass this check."],"exampleFix":"# before\nsvc = GoogleAIChatCompletion(use_vertexai=True, gemini_model_id=\"gemini-1.5-pro\")\n# after\nsvc = GoogleAIChatCompletion(use_vertexai=True, gemini_model_id=\"gemini-1.5-pro\", project_id=\"my-gcp-project\")","handlingStrategy":"validation","validationCode":"def vertex_has_project_id(use_vertexai: bool, project_id: str | None, client) -> bool:\n    if use_vertexai and client is None:\n        return isinstance(project_id, str) and bool(project_id.strip())\n    return True","typeGuard":"def is_valid_vertex_project_config(use_vertexai: bool, project_id: object, has_client: bool) -> bool:\n    return not use_vertexai or has_client or (isinstance(project_id, str) and bool(project_id.strip()))","tryCatchPattern":"from semantic_kernel.exceptions.service_exceptions import ServiceInitializationError\n\ntry:\n    svc = GoogleAIChatCompletion(use_vertexai=True, project_id=pid, region=region, gemini_model_id=mid)\nexcept ServiceInitializationError as e:\n    if \"Project ID must be provided\" in str(e):\n        raise ValueError(\"Set GOOGLE_AI_CLOUD_PROJECT_ID or pass project_id for Vertex AI\") from e\n    raise","preventionTips":["When enabling Vertex AI, always set the GCP project ID via env or constructor.","Double-check use_vertexai is True so the requirement matches your intent.","Inject a prebuilt client to bypass the check in break-glass scenarios."],"tags":["google-ai","vertex-ai","project-id","initialization","configuration"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}