Vertex AI SDK (Python)
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.
Warnings
- 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.
- breaking vertexai.generative_models, vertexai.language_models, vertexai.vision_models, vertexai.tuning, vertexai.caching deprecated June 24, 2025. Will be removed June 24, 2026.
- 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().
- 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.
- gotcha vertexai.init() must be called before any Vertex AI SDK calls. Forgetting this causes authentication or project resolution errors.
- gotcha location parameter is required and must be a valid GCP region. 'us-central1' is most common. Wrong or missing location raises InvalidArgument errors.
Install
-
pip install google-cloud-aiplatform -
pip install vertexai -
pip install 'google-cloud-aiplatform[agent_engines,adk]'
Imports
- vertexai.init
import vertexai vertexai.init( project='your-project-id', location='us-central1' ) - 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) - Application Default Credentials
import vertexai # Uses ADC automatically — run: gcloud auth application-default login vertexai.init(project='your-project-id', location='us-central1')
Quickstart
# 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)