microsoft/semantic-kernel · error · ServiceInitializationError

The Vertex AI Gemini model ID is required.

Error message

The Vertex AI Gemini model ID is required.

What it means

Raised by VertexAIChatCompletion.__init__ after settings parse successfully but gemini_model_id resolves to a falsy value. Even though VertexAISettings validated, no model id was supplied explicitly or via env, so the service cannot pick a target model and refuses to initialize.

Source

Thrown at python/semantic_kernel/connectors/ai/google/vertex_ai/services/vertex_ai_chat_completion.py:105

            project_id (str): The Google Cloud project ID.
            region (str): The Google Cloud region.
            gemini_model_id (str): The Gemini model ID.
            service_id (str): The Vertex AI service ID.
            env_file_path (str): The path to the environment file.
            env_file_encoding (str): The encoding of the environment file.
        """
        try:
            vertex_ai_settings = VertexAISettings(
                project_id=project_id,
                region=region,
                gemini_model_id=gemini_model_id,
                env_file_path=env_file_path,
                env_file_encoding=env_file_encoding,
            )
        except ValidationError as e:
            raise ServiceInitializationError(f"Failed to validate Vertex AI settings: {e}") from e
        if not vertex_ai_settings.gemini_model_id:
            raise ServiceInitializationError("The Vertex AI Gemini model ID is required.")

        super().__init__(
            ai_model_id=vertex_ai_settings.gemini_model_id,
            service_id=service_id or vertex_ai_settings.gemini_model_id,
            service_settings=vertex_ai_settings,
        )

    # region Overriding base class methods

    # Override from AIServiceClientBase
    @override
    def get_prompt_execution_settings_class(self) -> type["PromptExecutionSettings"]:
        return VertexAIChatPromptExecutionSettings

    @override
    @trace_chat_completion(VertexAIBase.MODEL_PROVIDER_NAME)
    async def _inner_get_chat_message_contents(
        self,

View on GitHub (pinned to c028a0c7dc)

Solutions

  1. Pass gemini_model_id explicitly to the VertexAIChatCompletion constructor (e.g. 'gemini-1.5-pro').
  2. Set the VERTEX_AI_GEMINI_MODEL_ID (or configured alias) environment variable / .env entry.
  3. Confirm the model id string is non-empty and matches a valid Vertex AI Gemini model name.

Example fix

# before
svc = VertexAIChatCompletion(project_id='p', region='us-central1')
# after
svc = VertexAIChatCompletion(project_id='p', region='us-central1', gemini_model_id='gemini-1.5-pro')
Defensive patterns

Strategy: validation

Validate before calling

model_id = os.environ.get('VERTEX_AI_GEMINI_MODEL_ID') or passed_model_id
assert model_id, 'Vertex AI Gemini model ID is required'

Prevention

When it happens

Trigger: Constructing VertexAIChatCompletion without gemini_model_id and without a corresponding env var (e.g. VERTEX_AI_GEMINI_MODEL_ID). Passing an empty string for the model id.

Common situations: Forgetting to set the model id env var. Assuming a default model is chosen. Copying sample code that omits the model argument while the .env doesn't define it.

Related errors


AI-assisted analysis of microsoft/semantic-kernel@c028a0c7dc (2026-08-13). Data as JSON: /api/errors/546eab9ecc346b1d. Report an issue: GitHub.