Vertex AI SDK (Python)

raw JSON →
1.142.0 verified Tue May 12 auth: no python install: verified quickstart: reviewed

Google Cloud Vertex AI SDK for Python. Two separate PyPI packages exist: google-cloud-aiplatform (GAPIC clients, full Vertex AI platform) and vertexai (higher-level SDK, same underlying package). Install is google-cloud-aiplatform, import is vertexai — classic name mismatch. Generative AI modules (vertexai.generative_models, vertexai.language_models, etc.) deprecated June 24, 2025 and will be removed June 24, 2026. Current version: google-cloud-aiplatform 1.142.0 / vertexai 1.71.1.

pip install google-cloud-aiplatform
error ModuleNotFoundError: No module named 'vertexai'
cause The `vertexai` SDK is part of the `google-cloud-aiplatform` package, which was not installed or installed incorrectly.
fix
pip install google-cloud-aiplatform
error google.api_core.exceptions.InvalidArgument: 400 The model specified does not exist in this region.
cause 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.
fix
Verify the model ID and ensure the location parameter in vertexai.init() or GenerativeModel() call matches a region where the model is available.
error google.auth.exceptions.DefaultCredentialsError: Could not automatically determine credentials.
cause 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.
fix
Authenticate 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.
error ValueError: Project ID must be specified
cause The `vertexai.init()` function could not automatically determine the Google Cloud project ID from environment variables, and it was not explicitly provided.
fix
Call vertexai.init(project="your-project-id", location="your-region") or set the GCLOUD_PROJECT environment variable.
error AttributeError: 'NoneType' object has no attribute 'generate_content'
cause 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`.
fix
Ensure 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.
breaking Install package is google-cloud-aiplatform but import is 'import vertexai'. LLMs consistently confuse this and generate 'from google.cloud import vertexai' or 'pip install vertexai-sdk'. Both are wrong.
fix pip install google-cloud-aiplatform; import vertexai
breaking vertexai.generative_models, vertexai.language_models, vertexai.vision_models, vertexai.tuning, vertexai.caching deprecated June 24, 2025. Will be removed June 24, 2026.
fix Migrate to google-genai with vertexai=True. See migration guide at cloud.google.com/vertex-ai/generative-ai/docs/deprecations/genai-vertexai-sdk
breaking Vertex AI does not use API keys. Uses Application Default Credentials (ADC). No api_key parameter. LLMs frequently hallucinate an api_key argument on vertexai.init().
fix Run: gcloud auth application-default login. Or set GOOGLE_APPLICATION_CREDENTIALS to service account JSON path.
gotcha Two PyPI packages: google-cloud-aiplatform and vertexai. They install the same underlying package. Installing either gives you both namespaces. Pinning both to different versions causes conflicts.
fix Pin only one. Prefer google-cloud-aiplatform for consistency with GCP tooling.
gotcha vertexai.init() must be called before any Vertex AI SDK calls. Forgetting this causes authentication or project resolution errors.
fix Always call vertexai.init(project='...', location='...') at startup.
gotcha location parameter is required and must be a valid GCP region. 'us-central1' is most common. Wrong or missing location raises InvalidArgument errors.
fix Always pass location='us-central1' or your preferred region.
pip install vertexai
pip install 'google-cloud-aiplatform[agent_engines,adk]'
python os / libc variant status wheel install import disk
3.10 alpine (musl) agent_engines,adk - - 18.67s 843.9M
3.10 alpine (musl) google-cloud-aiplatform - - 16.93s 323.8M
3.10 alpine (musl) vertexai - - 13.26s 272.5M
3.10 slim (glibc) agent_engines,adk - - 6.51s 882M
3.10 slim (glibc) google-cloud-aiplatform - - 5.09s 389M
3.10 slim (glibc) vertexai - - 4.09s 262M
3.11 alpine (musl) agent_engines,adk - - 21.51s 905.9M
3.11 alpine (musl) google-cloud-aiplatform - - 17.72s 360.2M
3.11 alpine (musl) vertexai - - 13.75s 299.1M
3.11 slim (glibc) agent_engines,adk - - 11.76s 944M
3.11 slim (glibc) google-cloud-aiplatform - - 8.59s 425M
3.11 slim (glibc) vertexai - - 6.50s 288M
3.12 alpine (musl) agent_engines,adk - - 20.93s 889.5M
3.12 alpine (musl) google-cloud-aiplatform - - 16.47s 347.2M
3.12 alpine (musl) vertexai - - 12.87s 285.3M
3.12 slim (glibc) agent_engines,adk - - 13.46s 928M
3.12 slim (glibc) google-cloud-aiplatform - - 9.86s 412M
3.12 slim (glibc) vertexai - - 7.26s 274M
3.13 alpine (musl) agent_engines,adk - - 19.64s 881.6M
3.13 alpine (musl) google-cloud-aiplatform - - 15.98s 341.3M
3.13 alpine (musl) vertexai - - 11.99s 282.7M
3.13 slim (glibc) agent_engines,adk - - 13.66s 922M
3.13 slim (glibc) google-cloud-aiplatform - - 9.66s 408M
3.13 slim (glibc) vertexai - - 7.04s 272M
3.9 alpine (musl) agent_engines,adk - - 16.41s 589.8M
3.9 alpine (musl) google-cloud-aiplatform - - 15.73s 319.3M
3.9 alpine (musl) vertexai - - - -
3.9 slim (glibc) agent_engines,adk - - 6.08s 656M
3.9 slim (glibc) google-cloud-aiplatform - - 5.46s 385M
3.9 slim (glibc) vertexai - - 4.62s 272M

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)