|
|
Vertex AI SDK - Deploying Gemini on Google Cloud
Author: Venkata Sudhakar
While the Gemini API with an API key is ideal for prototyping, enterprise deployments on Google Cloud use the Vertex AI SDK. Vertex AI gives you service account authentication with no API keys in code, GCP IAM role-based access control, VPC Service Controls, request audit logging to Cloud Logging, and per-project quota management. Your AI application runs entirely within your GCP project boundary - data never leaves your controlled environment, every call is logged with the caller identity, and access is managed through your existing IAM policies rather than shared API keys. The Vertex AI SDK uses the same google-genai package but initialises with a GCP project and location instead of an API key. Authentication uses Application Default Credentials - on GCP resources (Cloud Run, GKE, Compute Engine) the service account attached to the resource is used automatically. For local development run gcloud auth application-default login. The model names are identical to the Gemini API - only the client initialisation changes. This means you can develop with the Gemini API and deploy to Vertex AI by changing three lines of code. The below example shows an enterprise retail analytics application using Vertex AI for Gemini access - structured JSON output, service account auth, and audit trail integration with Cloud Logging.
It gives the following output,
=== VERTEX AI RETAIL ANALYTICS ===
{
"top_region": "East",
"concern_region": "West",
"concern_reason": "Only region with negative YoY growth (-2.3%) and highest return rate",
"top_sku_by_revenue": "iPhone 15 Pro 256GB - Rs 15,50,000 from 124 units",
"payment_insight": "68% UPI dominance - consider UPI-exclusive flash sale promotions",
"recommended_actions": [
"Investigate West region decline with store manager review this week",
"Replicate East growth tactics (24.6% YoY) in South and West markets",
"Launch EMI promotion to grow 10% EMI share given high average order value"
]
}
Tokens used: 487
# Running on Vertex AI means:
# - No API key anywhere in code
# - This call is logged to Cloud Audit Logs with the service account identity
# - Quota is per-project and managed centrally by your GCP admin
Key differences between direct Gemini API and Vertex AI SDK,
Feature Gemini API (API Key) Vertex AI SDK
------------------------------------------------------------
Authentication API key in code IAM service account
Audit logging None Cloud Audit Logs
Access control Anyone with key GCP IAM roles
Data residency Shared Google infra Your GCP project
VPC controls No Yes (VPC-SC)
Quota management Per API key Per GCP project
Code change needed client = genai.Client( client = genai.Client(
api_key="...") vertexai=True,
project="...",
location="...")
# Same SDK, same models, same methods - only client init changes
# Use Gemini API for dev/prototyping; Vertex AI for production enterprise apps
When to use Vertex AI instead of the direct Gemini API: any application handling customer PII or sensitive business data, any regulated industry deployment (BFSI, healthcare, government), any production system requiring audit trails for compliance, and any large organisation where centralised quota management across multiple teams is needed. The migration from Gemini API to Vertex AI takes about 30 minutes - change the client initialisation, set up the service account, and deploy. Everything else - prompts, tools, streaming, function calling - works identically.
|
|