How to beginner · 3 min read

Vertex AI Python SDK installation

Quick answer
Install the Vertex AI Python SDK by running pip install google-cloud-aiplatform. Then initialize it in your Python code with import vertexai and vertexai.init() to start using Google Cloud Vertex AI services.

PREREQUISITES

  • Python 3.8+
  • Google Cloud account with Vertex AI enabled
  • Google Cloud SDK installed and authenticated
  • pip install google-cloud-aiplatform

Setup

Install the official Vertex AI Python SDK package google-cloud-aiplatform using pip. Ensure you have Python 3.8 or higher and have authenticated your Google Cloud SDK with gcloud auth login. Set your Google Cloud project and region before using the SDK.

bash
pip install google-cloud-aiplatform

Step by step

Here is a complete example to initialize the Vertex AI SDK and list available models in your project.

python
import os
import vertexai
from vertexai import language_models

# Initialize Vertex AI with your project and location
vertexai.init(
    project=os.environ.get("GOOGLE_CLOUD_PROJECT"),
    location="us-central1"
)

# List available language models
client = language_models.LanguageModelsClient()
models = client.list_models()
for model in models:
    print(f"Model name: {model.name}")
output
Model name: projects/123456789/locations/us-central1/models/text-bison@001
Model name: projects/123456789/locations/us-central1/models/chat-bison@001
...

Common variations

You can use the SDK asynchronously with asyncio or specify different regions and projects in vertexai.init(). For chat models, use vertexai.language_models.ChatModel. The SDK supports streaming responses and advanced configuration.

python
import asyncio
import os
import vertexai
from vertexai.language_models import ChatModel

async def async_chat():
    vertexai.init(project=os.environ["GOOGLE_CLOUD_PROJECT"], location="us-central1")
    chat_model = ChatModel.from_pretrained("chat-bison@001")
    chat = chat_model.start_chat()
    response = await chat.send_message_async("Hello from async Vertex AI!")
    print(response.text)

asyncio.run(async_chat())
output
Hello from async Vertex AI!

Troubleshooting

  • If you get authentication errors, run gcloud auth application-default login to set up credentials.
  • Ensure your Google Cloud project has Vertex AI API enabled in the Cloud Console.
  • If vertexai.init() fails, verify your GOOGLE_CLOUD_PROJECT environment variable is set correctly.

Key Takeaways

  • Use pip install google-cloud-aiplatform to install the Vertex AI Python SDK.
  • Initialize the SDK with vertexai.init(project=..., location=...) before making API calls.
  • Authenticate with Google Cloud using gcloud auth application-default login to avoid credential errors.
Verified 2026-04 · chat-bison@001, text-bison@001
Verify ↗