GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Docs
  • Docs
  • AI Providers
  • Integrations
  • Enterprise
  • Changelog
  • Blog
  • Learn
  • Rust
  • Agent resources
  • LiteLLM Gateway
  • AI Gateway
  • MCP Gateway
  • Agent Gateway

This view

  • Original page
  • New address

GeezerVison is showing docs.litellm.ai — Vertex AI SDK | liteLLM

Pass-through endpoints for Vertex AI - call provider-specific endpoint, in native format (no translation).

FeatureSupportedNotes
Cost Tracking✅supports all models on /generateContent endpoint
Logging✅works across all integrations
End-user Tracking❌Tell us if you need this
Streaming✅

Supported Endpoints​

LiteLLM supports 3 vertex ai passthrough routes:

  1. /vertex_ai → routes to https://{vertex_location}-aiplatform.googleapis.com/
  2. /vertex_ai/discovery → routes to https://discoveryengine.googleapis.com - See Search Datastores Guide
  3. /vertex_ai/live → upgrades to the Vertex AI Live API WebSocket (google.cloud.aiplatform.v1.LlmBidiService/BidiGenerateContent) - See Live WebSocket Guide

How to use​

Just replace https://REGION-aiplatform.googleapis.com with LITELLM_PROXY_BASE_URL/vertex_ai

LiteLLM supports 3 flows for calling Vertex AI endpoints via pass-through:

  1. Specific Credentials: Admin sets passthrough credentials for a specific project/region.

  2. Default Credentials: Admin sets default credentials.

  3. Client-Side Credentials: User can send client-side credentials through to Vertex AI (default behavior - if no default or mapped credentials are found, the request is passed through directly).

Example Usage​

  • Specific Project/Region
  • Default Credentials
  • Client Credentials
model_list:
- model_name: gemini-3.1-pro-preview
litellm_params:
model: vertex_ai/gemini-3.1-pro-preview
vertex_project: adroit-crow-413218
vertex_location: us-central1
vertex_credentials: /path/to/credentials.json
use_in_pass_through: true # KEY CHANGE
  • Set in config.yaml
  • Set in environment variables
default_vertex_config:
vertex_project: adroit-crow-413218
vertex_location: us-central1
vertex_credentials: /path/to/credentials.json
export DEFAULT_VERTEXAI_PROJECT="adroit-crow-413218"
export DEFAULT_VERTEXAI_LOCATION="us-central1"
export DEFAULT_GOOGLE_APPLICATION_CREDENTIALS="/path/to/credentials.json"

Try Gemini 3.8 Flash (curl)

MODEL_ID="gemini-3.8-flash"
PROJECT_ID="YOUR_PROJECT_ID"
curl \
-X POST \
-H "Authorization: Bearer $(gcloud auth application-default print-access-token)" \
-H "Content-Type: application/json" \
"${LITELLM_PROXY_BASE_URL}/vertex_ai/v1/projects/${PROJECT_ID}/locations/us-central1/publishers/google/models/${MODEL_ID}:streamGenerateContent" -d \
$'{
"contents": {
"role": "user",
"parts": [
{
"fileData": {
"mimeType": "image/png",
"fileUri": "gs://generativeai-downloads/images/scones.jpg"
}
},
{
"text": "Describe this picture."
}
]
}
}'

Example Usage​

  • curl
  • Vertex Node.js SDK
curl http://localhost:4000/vertex_ai/v1/projects/${PROJECT_ID}/locations/us-central1/publishers/google/models/${MODEL_ID}:generateContent \
-H "Content-Type: application/json" \
-H "x-litellm-api-key: Bearer $LITELLM_API_KEY" \
-d '{
"contents":[{
"role": "user",
"parts":[{"text": "How are you doing today?"}]
}]
}'
const { VertexAI } = require('@google-cloud/vertexai');

const vertexAI = new VertexAI({
project: 'your-project-id', // enter your vertex project id
location: 'us-central1', // enter your vertex region
apiEndpoint: "localhost:4000/vertex_ai" // <proxy-server-url>/vertex_ai # note, do not include 'https://' in the url
});

const model = vertexAI.getGenerativeModel({
model: 'gemini-3.1-pro-preview'
}, {
customHeaders: {
"x-litellm-api-key": "sk-<your-litellm-api-key>" // Your litellm Virtual Key
}
});

async function generateContent() {
try {
const prompt = {
contents: [{
role: 'user',
parts: [{ text: 'How are you doing today?' }]
}]
};

const response = await model.generateContent(prompt);
console.log('Response:', response);
} catch (error) {
console.error('Error:', error);
}
}

generateContent();

Vertex AI Live API WebSocket​

LiteLLM can now proxy the Vertex AI Live API to help you experiment with streaming audio/text from Gemini Live models without exposing Google credentials to clients.

  • Configure default Vertex credentials via default_vertex_config or environment variables (see examples above).
  • Connect to wss://<PROXY_URL>/vertex_ai/live. LiteLLM will exchange your saved credentials for a short-lived access token and forward messages bidirectionally.
  • Optional query params vertex_project, vertex_location, and model let you override defaults for multi-project setups or global-only models.
client.py
import asyncio
import json

from websockets.asyncio.client import connect


async def main() -> None:
headers = {
"x-litellm-api-key": "Bearer sk-your-litellm-key",
"Content-Type": "application/json",
}
async with connect(
"ws://localhost:4000/vertex_ai/live",
additional_headers=headers,
) as ws:
await ws.send(
json.dumps(
{
"setup": {
"model": "projects/your-project/locations/us-central1/publishers/google/models/gemini-2.0-flash-live-preview-04-09",
"generation_config": {"response_modalities": ["TEXT"]},
}
}
)
)

async for message in ws:
print("server:", message)


if __name__ == "__main__":
asyncio.run(main())

Quick Start​

Let's call the Vertex AI /generateContent endpoint

  1. Add Vertex AI Credentials to your environment
export DEFAULT_VERTEXAI_PROJECT="" # "adroit-crow-413218"
export DEFAULT_VERTEXAI_LOCATION="" # "us-central1"
export DEFAULT_GOOGLE_APPLICATION_CREDENTIALS="" # "/Users/Downloads/adroit-crow-413218-a956eef1a2a8.json"
  1. Start LiteLLM Proxy
litellm

# RUNNING on http://0.0.0.0:4000
  1. Test it!

Let's call the Google AI Studio token counting endpoint

curl http://localhost:4000/vertex-ai/v1/projects/${PROJECT_ID}/locations/us-central1/publishers/google/models/gemini-3.1-pro-preview:generateContent \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $LITELLM_API_KEY" \
-d '{
"contents":[{
"role": "user",
"parts":[{"text": "How are you doing today?"}]
}]
}'

Supported API Endpoints​

  • Gemini API
  • Embeddings API
  • Imagen API
  • Code Completion API
  • Batch prediction API
  • Tuning API
  • CountTokens API

Authentication to Vertex AI​

LiteLLM Proxy Server supports two methods of authentication to Vertex AI:

  1. Pass Vertex Credentials client side to proxy server

  2. Set Vertex AI credentials on proxy server

Usage Examples​

Gemini API (Generate Content)​

curl http://localhost:4000/vertex_ai/v1/projects/${PROJECT_ID}/locations/us-central1/publishers/google/models/gemini-3.8-flash:generateContent \
-H "Content-Type: application/json" \
-H "x-litellm-api-key: Bearer $LITELLM_API_KEY" \
-d '{"contents":[{"role": "user", "parts":[{"text": "hi"}]}]}'

Embeddings API​

curl http://localhost:4000/vertex_ai/v1/projects/${PROJECT_ID}/locations/us-central1/publishers/google/models/textembedding-gecko@001:predict \
-H "Content-Type: application/json" \
-H "x-litellm-api-key: Bearer $LITELLM_API_KEY" \
-d '{"instances":[{"content": "gm"}]}'

Imagen API​

curl http://localhost:4000/vertex_ai/v1/projects/${PROJECT_ID}/locations/us-central1/publishers/google/models/imagen-3.0-generate-001:predict \
-H "Content-Type: application/json" \
-H "x-litellm-api-key: Bearer $LITELLM_API_KEY" \
-d '{"instances":[{"prompt": "make an otter"}], "parameters": {"sampleCount": 1}}'

Count Tokens API​

curl http://localhost:4000/vertex_ai/v1/projects/${PROJECT_ID}/locations/us-central1/publishers/google/models/gemini-3.8-flash:countTokens \
-H "Content-Type: application/json" \
-H "x-litellm-api-key: Bearer $LITELLM_API_KEY" \
-d '{"contents":[{"role": "user", "parts":[{"text": "hi"}]}]}'

Tuning API​

Create Fine Tuning Job

curl http://localhost:4000/vertex_ai/v1/projects/${PROJECT_ID}/locations/us-central1/publishers/google/models/gemini-3.8-flash:tuningJobs \
-H "Content-Type: application/json" \
-H "x-litellm-api-key: Bearer $LITELLM_API_KEY" \
-d '{
"baseModel": "gemini-3.8-flash",
"supervisedTuningSpec" : {
"training_dataset_uri": "gs://cloud-samples-data/ai-platform/generative_ai/sft_train_data.jsonl"
}
}'

Advanced​

Pre-requisites

  • Setup proxy with DB

Use this, to avoid giving developers the raw Anthropic API key, but still letting them use Anthropic endpoints.

Use with Virtual Keys​

  1. Setup environment
export DATABASE_URL=""
export LITELLM_MASTER_KEY=""

# vertex ai credentials
export DEFAULT_VERTEXAI_PROJECT="" # "adroit-crow-413218"
export DEFAULT_VERTEXAI_LOCATION="" # "us-central1"
export DEFAULT_GOOGLE_APPLICATION_CREDENTIALS="" # "/Users/Downloads/adroit-crow-413218-a956eef1a2a8.json"
litellm

# RUNNING on http://0.0.0.0:4000
  1. Generate virtual key
curl -X POST 'http://0.0.0.0:4000/key/generate' \
-H "x-litellm-api-key: Bearer $LITELLM_API_KEY" \
-H 'Content-Type: application/json' \
-d '{}'

Expected Response

{
...
"key": "sk-<virtual-key>"
}
  1. Test it!
curl http://localhost:4000/vertex_ai/v1/projects/${PROJECT_ID}/locations/us-central1/publishers/google/models/gemini-3.1-pro-preview:generateContent \
-H "Content-Type: application/json" \
-H "x-litellm-api-key: Bearer $LITELLM_API_KEY" \
-d '{
"contents":[{
"role": "user",
"parts":[{"text": "How are you doing today?"}]
}]
}'

Send tags in request headers​

Use this if you wants tags to be tracked in the LiteLLM DB and on logging callbacks

Pass tags in request headers as a comma separated list. In the example below the following tags will be tracked

tags: ["vertex-js-sdk", "pass-through-endpoint"]
  • curl
  • Vertex Node.js SDK
curl http://localhost:4000/vertex_ai/v1/projects/${PROJECT_ID}/locations/us-central1/publishers/google/models/gemini-3.1-pro-preview:generateContent \
-H "Content-Type: application/json" \
-H "x-litellm-api-key: Bearer $LITELLM_API_KEY" \
-H "tags: vertex-js-sdk,pass-through-endpoint" \
-d '{
"contents":[{
"role": "user",
"parts":[{"text": "How are you doing today?"}]
}]
}'
const { VertexAI } = require('@google-cloud/vertexai');

const vertexAI = new VertexAI({
project: 'your-project-id', // enter your vertex project id
location: 'us-central1', // enter your vertex region
apiEndpoint: "localhost:4000/vertex_ai" // <proxy-server-url>/vertex_ai # note, do not include 'https://' in the url
});

const model = vertexAI.getGenerativeModel({
model: 'gemini-3.1-pro-preview'
}, {
customHeaders: {
"x-litellm-api-key": "sk-<your-litellm-api-key>", // Your litellm Virtual Key
"tags": "vertex-js-sdk,pass-through-endpoint"
}
});

async function generateContent() {
try {
const prompt = {
contents: [{
role: 'user',
parts: [{ text: 'How are you doing today?' }]
}]
};

const response = await model.generateContent(prompt);
console.log('Response:', response);
} catch (error) {
console.error('Error:', error);
}
}

generateContent();

Using Anthropic Beta Features on Vertex AI​

When using Anthropic models via Vertex AI passthrough (e.g., Claude on Vertex), you can enable Anthropic beta features like extended context windows.

The anthropic-beta header is automatically forwarded to Vertex AI when calling Anthropic models.

curl http://localhost:4000/vertex_ai/v1/projects/${PROJECT_ID}/locations/us-east5/publishers/anthropic/models/claude-sonnet-5:rawPredict \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $LITELLM_API_KEY" \
-H "anthropic-beta: context-1m-2025-08-07" \
-d '{
"anthropic_version": "vertex-2023-10-16",
"messages": [{"role": "user", "content": "Hello"}],
"max_tokens": 500
}'

Forwarding Custom Headers with x-pass- Prefix​

You can forward any custom header to the provider by prefixing it with x-pass-. The prefix is stripped before the header is sent to the provider.

For example:

  • x-pass-anthropic-beta: value becomes anthropic-beta: value
  • x-pass-custom-header: value becomes custom-header: value

This is useful when you need to send provider-specific headers that aren't in the default allowlist.

curl http://localhost:4000/vertex_ai/v1/projects/${PROJECT_ID}/locations/us-east5/publishers/anthropic/models/claude-sonnet-5:rawPredict \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $LITELLM_API_KEY" \
-H "x-pass-anthropic-beta: context-1m-2025-08-07" \
-H "x-pass-custom-feature: enabled" \
-d '{
"anthropic_version": "vertex-2023-10-16",
"messages": [{"role": "user", "content": "Hello"}],
"max_tokens": 500
}'
info

The x-pass- prefix works for all LLM pass-through endpoints, not just Vertex AI.

Removing Anthropic Beta Values Vertex AI Rejects​

Since v1.108.0

Some anthropic-beta values that the Anthropic API accepts get a 400 from Claude on Vertex AI, such as Unexpected value(s) `files-api-2025-04-14` for the `anthropic-beta` header. When a client you do not control sends one, list it in general_settings.vertex_ai_pass_through_drop_anthropic_betas, and the /vertex_ai/* and /vertex-ai/* routes remove it before calling Vertex AI.

general_settings:
vertex_ai_pass_through_drop_anthropic_betas: ["files-api-2025-04-14"]

With this config, a request sent with anthropic-beta: interleaved-thinking-2025-05-14,files-api-2025-04-14 reaches Vertex AI with anthropic-beta: interleaved-thinking-2025-05-14. The client's other values keep their order, and the header is left out when no value remains. A value sent as x-pass-anthropic-beta is removed too. Matching is exact and case-sensitive after trimming spaces, and an entry that holds several comma-separated values is split like the header.

The list applies to every Vertex AI Claude model. If you list a beta that another model needs, it is removed for that model too, and a request that uses that feature's body field then gets the 400 from Vertex AI. A value that is not a list of strings stops the proxy at startup with a validation error that names the key. A config reload applies a change without a restart, and so does /config/field/update on a proxy with store_model_in_db: true.

  • Supported Endpoints
  • How to use
  • Example Usage
  • Vertex AI Live API WebSocket
  • Quick Start
  • Supported API Endpoints
  • Usage Examples
    • Gemini API (Generate Content)
    • Embeddings API
    • Imagen API
    • Count Tokens API
    • Tuning API
  • Advanced
    • Use with Virtual Keys
    • Send tags in request headers
    • Using Anthropic Beta Features on Vertex AI
    • Forwarding Custom Headers with x-pass- Prefix
    • Removing Anthropic Beta Values Vertex AI Rejects
LiteLLM Enterprise
SSO/SAML, audit logs, spend tracking, multi-team management, and guardrails, built for production.
Learn more →
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.