Google Gemini through one OpenAI-compatible gateway
Call Gemini with your OpenAI SDK. Routeplane translates your request into Google’s native generateContent shape and maps the response back — you keep one client, and add fallback, guardrails, and residency.
Gemini speaks Google’s own JSON dialect: contents, systemInstruction, camel-cased generationConfig, and an API key carried in the URL. Routeplane’s adapter translates the OpenAI shape to and from that native format, including tool/function-call mapping and finish-reason normalization.
The upside is uniformity: Gemini sits behind the same OpenAI-compatible endpoint as every other model, ready to drop into a fallback chain or a cost/latency routing strategy.
Drop in your OpenAI client
Point your existing OpenAI SDK at the gateway and add two headers — your virtual key and the provider. Nothing else about your code changes.
curl https://api.routeplane.ai/v1/chat/completions \
-H "content-type: application/json" \
-H "x-routeplane-api-key: rp_your_gateway_key" \
-H "x-routeplane-provider: gemini" \
-d '{"model":"gemini-2.5-flash","messages":[{"role":"user","content":"Hello!"}]}'
import openai
client = openai.OpenAI(
api_key="rp_your_gateway_key",
base_url="https://api.routeplane.ai/v1",
default_headers={
"x-routeplane-api-key": "rp_your_gateway_key",
"x-routeplane-provider": "gemini", # route to Google Gemini
},
)
resp = client.chat.completions.create(
model="gemini-2.5-flash",
messages=[{"role": "user", "content": "Hello!"}],
)
print(resp.choices[0].message.content)
import OpenAI from 'openai';
const client = new OpenAI({
apiKey: 'rp_your_gateway_key',
baseURL: 'https://api.routeplane.ai/v1',
defaultHeaders: {
'x-routeplane-api-key': 'rp_your_gateway_key',
'x-routeplane-provider': 'gemini', // route to Google Gemini
},
});
const completion = await client.chat.completions.create({
model: 'gemini-2.5-flash',
messages: [{ role: 'user', content: 'Hello!' }],
});
console.log(completion.choices[0]?.message.content);
Or use the Routeplane SDK
The Routeplane SDKs subclass the official OpenAI clients, wire up the x-routeplane-* headers for you, and add typed access to routing metadata and the non-OpenAI surfaces.
pip install routeplane
from routeplane import Routeplane
client = Routeplane(
api_key="rp_your_gateway_key",
provider="gemini", # route to Google Gemini
)
resp = client.chat.completions.create(
model="gemini-2.5-flash",
messages=[{"role": "user", "content": "Hello!"}],
)
print(resp.choices[0].message.content)
npm i @routeplane/sdk
import { Routeplane } from '@routeplane/sdk';
const client = new Routeplane({
apiKey: process.env.ROUTEPLANE_API_KEY!, // rp_...
provider: 'gemini', // route to Google Gemini
});
const completion = await client.chat.completions.create({
model: 'gemini-2.5-flash',
messages: [{ role: 'user', content: 'Hello!' }],
});
console.log(completion.choices[0]?.message.content);
Add a fallback chain
Try Gemini first; fall back to OpenAI. Make the provider header a comma-separated list and the gateway walks it in order, skipping any provider whose circuit is open.
curl https://api.routeplane.ai/v1/chat/completions \
-H "content-type: application/json" \
-H "x-routeplane-api-key: rp_your_gateway_key" \
-H "x-routeplane-provider: gemini,openai" \
-d '{"model":"gemini-2.5-flash","messages":[{"role":"user","content":"Hello!"}]}'
Google Gemini on the gateway
The adapter supports chat completions, native streaming, and embeddings (Google’s batchEmbedContents).
Images must be inline
Gemini’s API takes image parts as inline data, not URLs. The adapter passes data-URI image content through; an http(s) image URL returns a clean 422 so you know to inline it rather than getting a confusing provider error.
Thinking tokens folded in
Gemini’s thinking-token count is folded into completion usage and cached-content tokens are surfaced as cached tokens, so your accounting lines up with the OpenAI shape.
Google Gemini model pricing
List prices for the Google Gemini models you can call through the gateway — click any model for its per-token cost page.
Sovereign routing
Sovereign routing works with Google Gemini the same way it works everywhere: add x-routeplane-residency to a request, and when the gateway classifies regulated personal data in it, only providers resident in the requested region stay eligible — a hard constraint that overrides the provider header. Combine Google Gemini with a region-locked deployment and declare its region so it becomes eligible for in-region routing.
Keep reading
- Quickstart — send your first request in a few minutes.
- Providers & routing strategy — how eligibility, fallback, and strategies work.
- Python SDK and TypeScript SDK — the full typed clients.
- All providers — every model provider behind the gateway.
Frequently asked questions
Is Routeplane a drop-in replacement for calling Google Gemini directly?
Yes. The gateway is OpenAI-compatible, so switching is a base-URL change — point your existing OpenAI SDK at https://api.routeplane.ai/v1 and set the x-routeplane-provider header to gemini. You keep your code and gain automatic fallback, in-data-plane PII guardrails, sovereign routing, and per-team cost attribution. Routeplane translates your OpenAI-shaped request into Google Gemini's native API and maps the response back, so you never touch that format.
Which Google Gemini models can I use through Routeplane?
Any Google Gemini model the provider serves. See the list prices linked above for the ones we publish.
Can I enforce data residency on Google Gemini requests?
Yes. Add the x-routeplane-residency header (for example IN) and, when a request carries regulated personal data, the gateway restricts routing to providers eligible in that region — overriding the provider header if it has to. Declare the region your Google Gemini deployment serves so it becomes eligible.
Route your first request this week.
Point your existing OpenAI-compatible client at Routeplane, set one header, and get fallback, guardrails, and sovereign routing across every provider.