Gemini API through the gateway¶
Code written for Google's Gemini API keeps its shape. Point it at the gateway and every call is governed, recorded in
Request logs and charged to the right team, and generateContent can answer from GPT and Claude models as well as
Gemini, in the Gemini shape your code already reads.
What it is¶
The pages in this group describe each Gemini endpoint as the gateway serves it: the paths Google's GenAI SDKs call
(google-genai for Python, @google/genai for TypeScript), with Python, TypeScript and curl samples. To set up the SDK
itself, start with Google GenAI SDK for Python or
Google GenAI SDK for TypeScript.
The two settings¶
| Setting | Environment variable | Python | TypeScript | Value |
|---|---|---|---|---|
| Base address | GOOGLE_GEMINI_BASE_URL |
http_options=types.HttpOptions(base_url=…) |
httpOptions: { baseUrl } |
https://<your-gateway> (the SDK adds /v1beta/models/…) |
| Key | GEMINI_API_KEY or GOOGLE_API_KEY |
api_key |
apiKey |
Your Vidai key (starts vk_), never a Google key |
And one more, on current SDK versions: set the API version to v1beta. Since version 3.0 (November 2026) both SDKs
call /v1/… by default; the gateway serves the Gemini API at /v1beta/…. Set api_version="v1beta" in
HttpOptions (Python), apiVersion: "v1beta" (TypeScript), or GOOGLE_GENAI_API_VERSION=v1beta. Older versions
already use v1beta; setting it does no harm.
export GOOGLE_GEMINI_BASE_URL="https://<your-gateway>"
export GOOGLE_GENAI_API_VERSION="v1beta"
export GEMINI_API_KEY="vk_…"
The SDK sends the key in the x-goog-api-key header, which the gateway accepts. The address and paths are under
Connect your app on the Keys page and in System › Settings › Gateway; the key comes from Keys › Issue a key (its
secret is shown once).
What goes through the gateway¶
| Endpoint | Page | Reaches |
|---|---|---|
POST /v1beta/models/{m}:generateContent, :streamGenerateContent |
Generate content | Gemini and Vertex AI as sent; OpenAI, Azure OpenAI, Anthropic and Bedrock translated |
POST /v1beta/models/{m}:countTokens |
Count tokens | Gemini, Vertex AI; for another provider's model the gateway counts itself |
POST /v1beta/models/{m}:embedContent |
Embed content | Gemini only |
/v1beta/files, /upload/v1beta/files |
Files | Gemini (Google AI Studio) only |
/v1/projects/{p}/locations/{l}/publishers/… (Vertex AI's own paths) |
Vertex AI | As for generate content |
GET /v1beta/models |
Model names | Answered by the gateway: the models your key may call |
Generating content is translated to any provider; embeddings, cached contents and files stay with Google; a token count for another provider's model is answered by the gateway.
Errors¶
The gateway writes its own errors in Google's shape, so the SDK raises its usual APIError:
{"error":{"code":401,"message":"…","status":"UNAUTHENTICATED"}}
Match on the x-vidai-error-code response header, not the message. The full list is in
Headers and errors.
Good to know¶
?key=in the URL is not accepted: send the key as a header (the SDKs do).- Gemini batch mode (
/v1beta/batches) doesn't go through the gateway. - Cost is never in the answer: find the call in Request logs.