ValueError
vertexai.exceptions.ValueError: Location region not supported
Stack trace
Traceback (most recent call last):
File "app.py", line 10, in <module>
vertexai.init(project=project_id, location=region)
File "/usr/local/lib/python3.9/site-packages/vertexai/__init__.py", line 45, in init
raise ValueError(f"Location region '{location}' not supported.")
ValueError: Location region 'us-central9' not supported. Why it happens
This error occurs because the location region passed to vertexai.init() is either misspelled, deprecated, or not enabled for your Google Cloud project. The Vertex AI SDK validates the region against a list of supported regions and raises this error if the region is invalid.
Detection
Check the region parameter passed to vertexai.init() before runtime; validate it against the official list of supported Vertex AI regions to catch misconfiguration early.
Causes & fixes
Typo or invalid region string passed to vertexai.init()
Correct the region string to a valid supported region such as 'us-central1' or 'us-east1'.
Region is valid but not enabled for your Google Cloud project
Enable the Vertex AI API and services in the Google Cloud Console for the specified region.
Using an outdated Vertex AI SDK version that does not recognize newer regions
Upgrade the vertexai Python package to the latest version that supports all current regions.
Code: broken vs fixed
import os
from vertexai import vertexai
project_id = os.environ.get('GOOGLE_CLOUD_PROJECT')
region = 'us-central9' # Invalid region
vertexai.init(project=project_id, location=region) # This line raises ValueError import os
from vertexai import vertexai
project_id = os.environ.get('GOOGLE_CLOUD_PROJECT')
region = 'us-central1' # Corrected region
vertexai.init(project=project_id, location=region) # Fixed: valid region
print('VertexAI initialized successfully in region:', region) Workaround
Wrap the vertexai.init call in a try/except block catching ValueError, log the invalid region, and fallback to a default supported region programmatically.
Prevention
Always validate the region string against the official Google Cloud Vertex AI supported regions list before calling vertexai.init, and keep the SDK updated to support new regions.