{"record":{"id":"7f9c22256d5bd3ec","repo":"microsoft/semantic-kernel","slug":"project-id-must-be-provided-when-use-vertexai-is-t-7f9c22","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_completion.py","lineNumber":92,"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 GoogleAITextPromptExecutionSettings","sourceCodeStart":74,"sourceCodeEnd":110,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/python/semantic_kernel/connectors/ai/google/google_ai/services/google_ai_text_completion.py#L74-L110","documentation":"Raised in the GoogleAITextCompletion constructor when use_vertexai is True but cloud_project_id is not provided. The Vertex AI backend of the Google GenAI SDK requires a Google Cloud project ID to route requests. No custom client was supplied (the check only runs when client is None), so the service would have to build its own Client and needs the project.","triggerScenarios":"Constructing GoogleAITextCompletion(use_vertexai=True) without a project_id argument and without GOOGLE_AI_CLOUD_PROJECT_ID in the environment.","commonSituations":"Switching from the Gemini API key flow to Vertex AI and forgetting the project ID; env var GOOGLE_AI_CLOUD_PROJECT_ID not exported; using GOOGLE_PROJECT_ID instead of the prefixed name.","solutions":["Set GOOGLE_AI_CLOUD_PROJECT_ID=<your-gcp-project-id> in your environment or .env file.","Pass project_id=<your-gcp-project-id> to the GoogleAITextCompletion constructor.","Confirm use_vertexai=True is actually what you want — if not, leave it False and use an API key instead."],"exampleFix":"# before\nservice = GoogleAITextCompletion(use_vertexai=True, gemini_model_id='gemini-2.0-flash')\n\n# after\nservice = GoogleAITextCompletion(\n    use_vertexai=True, gemini_model_id='gemini-2.0-flash',\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.')","typeGuard":null,"tryCatchPattern":"try:\n    service = GoogleAITextCompletion(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 mode.')\n    raise","preventionTips":["When enabling Vertex AI, set all three: project_id, region, and use_vertexai together.","Document the Vertex AI prerequisites in your project README.","Use a config object that bundles project_id + region so they are never set independently."],"tags":["google-ai","vertex-ai","project-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"}