Vertex AI
Google Cloud's unified AI platform. Access Gemini, PaLM, Claude, and open models via a single API. Build, deploy, and scale ML/GenAI applications with enterprise security.
Platform Overview
Gemini Models
1M+ token context, multimodal (text, image, video, audio), function calling.
Model Garden
150+ models: Gemini, Claude, Llama, Mistral, and open-source models.
Grounding & RAG
Built-in Google Search grounding, Vertex AI Search for enterprise RAG.
Enterprise Security
VPC-SC, CMEK, data residency, audit logging, responsible AI controls.
Available Models
| Model | Context | Best For |
|---|---|---|
| gemini-2.0-flash | 1M tokens | Fast, multimodal, agents |
| gemini-2.0-pro | 2M tokens | Complex reasoning, coding |
| claude-3-5-sonnet | 200K tokens | Coding, analysis |
| llama-3.1-405b | 128K tokens | Open model, large scale |
| text-embedding-005 | 2048 tokens | Embeddings, RAG |
| imagen-3 | - | Image generation |
Quickstart (Python)
Installation
pip install google-cloud-aiplatform
Basic Chat (Gemini)
import vertexai
from vertexai.generative_models import GenerativeModel
# Initialize
vertexai.init(project="YOUR_PROJECT_ID", location="us-central1")
# Load model
model = GenerativeModel("gemini-2.0-flash")
# Generate
response = model.generate_content("Explain quantum computing simply.")
print(response.text)
Chat with History
chat = model.start_chat()
response1 = chat.send_message("What is Python?")
print(response1.text)
response2 = chat.send_message("How does it compare to JavaScript?")
print(response2.text)
Multimodal (Vision)
from vertexai.generative_models import GenerativeModel, Part, Image
model = GenerativeModel("gemini-2.0-flash")
# From local file
image = Image.load_from_file("image.jpg")
# Or from GCS
# image = Part.from_uri("gs://bucket/image.jpg", mime_type="image/jpeg")
response = model.generate_content([
"What's in this image?",
image
])
print(response.text)
Function Calling (Tools)
from vertexai.generative_models import GenerativeModel, Tool, FunctionDeclaration
# Define function
get_weather = FunctionDeclaration(
name="get_weather",
description="Get weather for a location",
parameters={
"type": "object",
"properties": {
"location": {"type": "string", "description": "City name"}
},
"required": ["location"]
}
)
# Create tool
weather_tool = Tool(function_declarations=[get_weather])
# Use with model
model = GenerativeModel("gemini-2.0-flash", tools=[weather_tool])
response = model.generate_content("What's the weather in Tokyo?")
# Check for function calls
for candidate in response.candidates:
for part in candidate.content.parts:
if part.function_call:
print(f"Call: {part.function_call.name}")
print(f"Args: {part.function_call.args}")
Embeddings
from vertexai.language_models import TextEmbeddingModel
model = TextEmbeddingModel.from_pretrained("text-embedding-005")
texts = ["Hello world", "Machine learning is powerful"]
embeddings = model.get_embeddings(texts)
for i, embedding in enumerate(embeddings):
print(f"Text {i}: {len(embedding.values)} dimensions")
Google Search Grounding
Ground responses in real-time Google Search results to reduce hallucinations.
from vertexai.generative_models import GenerativeModel, Tool, grounding
# Enable Google Search grounding
search_tool = Tool.from_google_search_retrieval(
grounding.GoogleSearchRetrieval()
)
model = GenerativeModel("gemini-2.0-flash", tools=[search_tool])
response = model.generate_content(
"What are the latest AI news from this week?"
)
print(response.text)
# Access grounding metadata
for candidate in response.candidates:
if candidate.grounding_metadata:
for chunk in candidate.grounding_metadata.grounding_chunks:
print(f"Source: {chunk.web.uri}")
Pricing (per 1M tokens)
| Model | Input | Output |
|---|---|---|
| Gemini 2.0 Flash | $0.10 | $0.40 |
| Gemini 2.0 Pro | $1.25 | $5.00 |
| Claude 3.5 Sonnet | $3.00 | $15.00 |
π‘ Tip: Use gemini-2.0-flash for most workloads. It's fast, cheap, and
supports 1M tokens.