microsoft/semantic-kernel · error · ServiceInitializationError
Project ID must be provided when use_vertexai is True.
Error message
Project ID must be provided when use_vertexai is True.
What it means
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.
Source
Thrown at python/semantic_kernel/connectors/ai/google/google_ai/services/google_ai_text_embedding.py:83
try:
google_ai_settings = GoogleAISettings(
embedding_model_id=embedding_model_id,
api_key=api_key,
cloud_project_id=project_id,
cloud_region=region,
use_vertexai=use_vertexai,
env_file_path=env_file_path,
env_file_encoding=env_file_encoding,
)
except ValidationError as e:
raise ServiceInitializationError(f"Failed to validate Google AI settings: {e}") from e
if not google_ai_settings.embedding_model_id:
raise ServiceInitializationError("The Google AI embedding model ID is required.")
if not client:
if google_ai_settings.use_vertexai and not google_ai_settings.cloud_project_id:
raise ServiceInitializationError("Project ID must be provided when use_vertexai is True.")
if google_ai_settings.use_vertexai and not google_ai_settings.cloud_region:
raise ServiceInitializationError("Region must be provided when use_vertexai is True.")
if not google_ai_settings.use_vertexai and not google_ai_settings.api_key:
raise ServiceInitializationError("The API key is required when use_vertexai is False.")
super().__init__(
ai_model_id=google_ai_settings.embedding_model_id,
service_id=service_id or google_ai_settings.embedding_model_id,
service_settings=google_ai_settings,
client=client,
)
@override
async def generate_embeddings(
self,
texts: list[str],
settings: "PromptExecutionSettings | None" = None,
**kwargs: Any,View on GitHub (pinned to c028a0c7dc)
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.
Example fix
# before
embed = GoogleAITextEmbedding(use_vertexai=True, embedding_model_id='text-embedding-004')
# after
embed = GoogleAITextEmbedding(
use_vertexai=True, embedding_model_id='text-embedding-004',
project_id='my-gcp-project', region='us-central1',
) Defensive patterns
Strategy: validation
Validate before calling
import os
if os.environ.get('GOOGLE_AI_USE_VERTEXAI', '').lower() == 'true':
if not os.environ.get('GOOGLE_AI_CLOUD_PROJECT_ID'):
raise EnvironmentError('Set GOOGLE_AI_CLOUD_PROJECT_ID when using Vertex AI embeddings.') Try / catch
try:
service = GoogleAITextEmbedding(use_vertexai=True)
except ServiceInitializationError as e:
if 'Project ID must be provided' in str(e):
logging.error('Missing GOOGLE_AI_CLOUD_PROJECT_ID for Vertex AI embedding service.')
raise Prevention
- 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.
When it happens
Trigger: Constructing GoogleAITextEmbedding(use_vertexai=True) without project_id and without GOOGLE_AI_CLOUD_PROJECT_ID.
Common situations: Migrating embedding service to Vertex AI and forgetting the project; env var not set; used an unprefixed project variable name.
Related errors
- Project ID must be provided when use_vertexai is True.
- Region must be provided when use_vertexai is True.
- Project ID must be provided when use_vertexai is True.
- Region must be provided when use_vertexai is True.
- The Google AI embedding model ID is required.
AI-assisted analysis of microsoft/semantic-kernel@c028a0c7dc (2026-08-13).
Data as JSON: /api/errors/5715f29c68c6f75f.
Report an issue: GitHub.