Vertex AI pass-through
The /vertex_ai route forwards any Vertex AI REST path, such as generateContent, countTokens, embeddings, batch prediction or Vertex AI Search, to Google. The path after /vertex_ai is the Vertex AI REST path including the project and location. Callers need no Google credentials at all. The gateway checks the virtual key, signs the request with its own service account and records the spend. /vertex_ai/discovery/... forwards to the Discovery Engine API behind Vertex AI Search.
A real-world scenario
A data science team uses the Vertex AI SDK for Gemini and for batch embeddings. Each notebook used to carry a service account file. The platform team registers one service account on the gateway, hands out virtual keys with budgets, and the notebooks set the SDK's API endpoint to the gateway. The service account file leaves every laptop and every batch job shows up on the Logs page with its cost.
Before you start
The gateway needs a Google service account. Register it as a Vertex AI deployment with vertex_project, vertex_location, vertex_credentials and use_in_pass_through: true, or set default_vertex_config in the config file. Without either, the gateway falls back to the environment below.
| Variable | Purpose |
|---|---|
GOOGLE_APPLICATION_CREDENTIALS | Path to the service account file the gateway signs with. |
VERTEXAI_PROJECT, VERTEXAI_LOCATION | Default project and location when the path carries none. |
model_list:
- model_name: gemini-passthrough
spanway_params:
model: vertex_ai/gemini-3.8-flash
vertex_project: my-project
vertex_location: us-central1
vertex_credentials: os.environ/VERTEX_SERVICE_ACCOUNT_JSON
use_in_pass_through: true
Steps
-
Give the gateway the credential. Open
/ui/models-and-endpoints, on the Add Model tab pick Vertex AI (Anthropic, Gemini, etc.) under Provider, fill in the project, location and service account JSON, open Advanced Settings, turn on Use in pass through routes and click Add Model. Or add the deployment above to the config file. -
Issue a virtual key on
/ui/api-keyswith + Create New Key, then Create Key. -
Call Vertex AI through the gateway with the full REST path.
curl -X POST "http://localhost:4000/vertex_ai/v1/projects/my-project/locations/us-central1/publishers/google/models/gemini-3.8-flash:generateContent" \-H "Authorization: Bearer $SPANWAY_API_KEY" \-H "Content-Type: application/json" \-d '{"contents": [{"role": "user", "parts": [{"text": "Summarise this ticket in one sentence."}]}]}' -
With the Vertex AI SDK, set the API endpoint to
localhost:4000/vertex_aiand send the virtual key as the bearer token. -
Open
/ui/logsand click the newest row to see the request, the key and its cost.
Expected result
Google's own response, with Google's status code and headers. Streaming (streamGenerateContent) is streamed through as it arrives.
{
"candidates": [{"content": {"role": "model", "parts": [{"text": "The customer wants one of two duplicate charges refunded."}]}, "finishReason": "STOP"}],
"usageMetadata": {"promptTokenCount": 18, "candidatesTokenCount": 12, "totalTokenCount": 30}
}
The spend log row carries the key, team and user and the cost from usageMetadata. When several Vertex AI deployments are marked for pass-through, the gateway load balances across them.
Errors
| Status | Message | What it means and how to fix it |
|---|---|---|
401 | Authentication Error, Invalid proxy server token passed | The virtual key is missing, wrong, expired or blocked. |
403 | Key/team denied access to passthrough route /vertex_ai/... | The key or team lists the route in denied_passthrough_routes. The message goes on with Matched <pattern> in denied_passthrough_routes, naming the pattern to remove from the key or team. |
400 | Vertex AI location is missing. Include the location in the path, set vertex_location in default_vertex_config ... | The path has no location and no default is set. Add the location to the path or register a deployment. |
401 or 403 from Google | Request had invalid authentication credentials | The gateway forwarded the call without a usable service account. Register the deployment with Use in pass through routes on. |
| Any other | Google's own error body | Google refused the request. The message is returned unchanged. |
Related
Pass-through endpoints lists every built-in route. The unified generateContent endpoint works with every provider. The Vertex AI provider page covers the unified integration, and Google AI Studio pass-through covers the Gemini API without a Google Cloud project.