Install & Compatibility
Where this runs
tested against v1.71.1 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
493MB installed
● package 493MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
vertexai.init
✓ import vertexai
vertexai.init(
project='your-project-id',
location='us-central1'
)
✗ from google.cloud import aiplatform
aiplatform.init(project='your-project-id', location='us-central1')
install is google-cloud-aiplatform but import is vertexai — not google.cloud.aiplatform. Both packages coexist but vertexai is the high-level SDK. google.cloud.aiplatform is the low-level GAPIC client.
vertexai.generative_models (deprecated)
✓ # Use google-genai for generative AI on Vertex AI
from google import genai
client = genai.Client(
vertexai=True,
project='your-project-id',
location='us-central1'
)
response = client.models.generate_content(
model='gemini-2.5-flash',
contents='Explain neural networks'
)
print(response.text)
✗ import vertexai
from vertexai.generative_models import GenerativeModel
vertexai.init(project='your-project', location='us-central1')
model = GenerativeModel('gemini-2.5-flash')
response = model.generate_content('Explain neural networks')
print(response.text)
vertexai.generative_models deprecated June 24, 2025. Removed June 24, 2026. Migrate to google-genai with vertexai=True.
Application Default Credentials
✓ import vertexai
# Uses ADC automatically — run: gcloud auth application-default login
vertexai.init(project='your-project-id', location='us-central1')
✗ import vertexai
vertexai.init(project='your-project-id', location='us-central1', credentials='your-api-key')
Vertex AI does not use API keys. Uses Google Cloud Application Default Credentials (ADC) or service account JSON. No api_key parameter exists on vertexai.init().
Vertex AI Gemini call using google-genai with vertexai=True (recommended path from 2025 onwards).
# For Vertex AI generative AI — use google-genai
# pip install google-genai
from google import genai
client = genai.Client(
vertexai=True,
project='your-gcp-project-id',
location='us-central1'
)
response = client.models.generate_content(
model='gemini-2.5-flash',
contents='What is Vertex AI?'
)
print(response.text)
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'vertexai'
The `vertexai` SDK is part of the `google-cloud-aiplatform` package, which was not installed or installed incorrectly.
fixpip install google-cloud-aiplatform
google.api_core.exceptions.InvalidArgument: 400 The model specified does not exist in this region.
The specified model name (e.g., `gemini-pro`) is either misspelled or not available in the Google Cloud region specified during `vertexai.init()` or model instantiation.
fixVerify the model ID and ensure the `location` parameter in `vertexai.init()` or `GenerativeModel()` call matches a region where the model is available.
google.auth.exceptions.DefaultCredentialsError: Could not automatically determine credentials.
The environment lacks valid Google Cloud credentials, or the service account/user running the code does not have the necessary permissions to access Vertex AI resources.
fixAuthenticate using `gcloud auth application-default login`, set the `GOOGLE_APPLICATION_CREDENTIALS` environment variable, or ensure a service account with the 'Vertex AI User' role is active.
ValueError: Project ID must be specified
The `vertexai.init()` function could not automatically determine the Google Cloud project ID from environment variables, and it was not explicitly provided.
fixCall `vertexai.init(project="your-project-id", location="your-region")` or set the `GCLOUD_PROJECT` environment variable.
AttributeError: 'NoneType' object has no attribute 'generate_content'
The `GenerativeModel` or `ChatSession` object was not successfully initialized, often due to an issue during its creation (e.g., invalid model name, region, or authentication failure), resulting in the variable being `None`.
fixEnsure `vertexai.init()` is called with correct project/location, the `GenerativeModel` is instantiated with a valid model name, and verify that the model object is not `None` before attempting to call generation methods.
Upgrade
Version history
1.71.1latest on PyPI · released Oct 31, 2024
Audit
Dependencies
google-authrequiredRequired for Application Default Credentials. Installed automatically.
google-genaioptionalRequired for new generative AI features. Generative AI modules moving from vertexai to google-genai.