Use Gemini through a custom endpoint
The simplest reliable route to Gemini on a third-party endpoint is the OpenAI-compatible one: point any OpenAI SDK at the base URL, pass a Gemini model ID, and both chat and streaming work without a second SDK.
https://aicomp.ai/v1).
Create one free →
curl https://aicomp.ai/v1/models \
-H "Authorization: Bearer sk-your-gateway-key"
A JSON list of model IDs means the key is good. Invalid token means it was copied wrong.
Get the exact model ID first
This matters more for Gemini than for any other family. Model strings carry version and preview suffixes, and they differ between providers — copying an ID from generic documentation for a different platform is the most common source of a 404. Read yours off the models endpoint and use it verbatim:
curl "$GATEWAY_BASE/chat/completions" \
-H "Authorization: Bearer $GATEWAY_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gemini-3.1-flash-lite",
"messages": [{"role": "user", "content": "Say OK"}],
"max_tokens": 64
}'
# First confirm the exact model ID your gateway exposes:
curl "$GATEWAY_BASE/models" -H "Authorization: Bearer $GATEWAY_KEY"
Through the OpenAI SDK
One client across OpenAI, Anthropic-shaped and Gemini models. This is the reason most teams prefer the compatible route — there is nothing new to learn and nothing vendor-specific to maintain:
import OpenAI from "openai";
// Gemini is reachable through an OpenAI-compatible route on many gateways.
const client = new OpenAI({
apiKey: process.env.GATEWAY_KEY,
baseURL: process.env.GATEWAY_BASE,
});
const res = await client.chat.completions.create({
model: "gemini-3.5-flash",
messages: [
{ role: "system", content: "Answer in one sentence." },
{ role: "user", content: "Why is Neptune blue?" },
],
max_tokens: 200,
});
console.log(res.choices[0].message.content);
Streaming
const stream = await client.chat.completions.create({
model: "gemini-3-flash-preview",
messages: [{ role: "user", content: "Summarise rate limiting in three bullets." }],
max_tokens: 300,
stream: true,
});
for await (const chunk of stream) {
process.stdout.write(chunk.choices[0]?.delta?.content ?? "");
}
If the chunks arrive together rather than incrementally, the endpoint is buffering. The response is still correct, you just lose the perceived-speed benefit — worth knowing before you build a typing UI on it.
Rates
| Model | Gateway rate in / out per 1M tokens | Official list in / out per 1M tokens |
|---|---|---|
| gemini-3.5-flash | $0.75 / $4.5 | — / — |
| gemini-3-flash-preview | $0.25 / $1.5 | — / — |
| gemini-3.1-flash-lite | $0.125 / $0.75 | — / — |
Rates checked 2026-09-16. Gateway rates move with upstream promotions — verify the current number in your dashboard before committing to a budget.
These are gateway rates and none of them carry a verified official list price in our data — unlike the OpenAI and Anthropic rows elsewhere on this site, the gateway column here cannot be cross-checked against published figures. Treat them as what the gateway charges, not as a discount claim.
Troubleshooting
| Symptom | Cause and fix |
|---|---|
| 404 model not found | Wrong ID string. Copy it from /models, suffixes included. |
| 401 invalid key | Key truncated on copy, or env var not loaded in this runtime. |
| Unexpected response shape | You hit a Gemini-native path with an OpenAI-shaped client. Use the compatible route. |
| Streaming returns nothing | Some builds require SSE-compatible headers; test with curl before debugging the SDK. |
| 429 immediately | Per-model quota, not a global one. Back off exponentially and retry. |
FAQ
Can I use the official Google SDK with a custom endpoint?
Usually yes, but the parameter name has changed between SDK generations — earlier releases used different option names for the endpoint than recent ones. Check the docs for the exact version you have installed. The OpenAI-compatible route avoids the question entirely and works with the SDK most projects already depend on.
Which Gemini model IDs work?
Whatever your provider exposes, and they do differ — some carry -preview or date suffixes. Always read them off GET /models rather than guessing from documentation for a different platform.
Does streaming work?
Usually on the OpenAI-compatible route, but verify it. If chunks arrive as one block the endpoint is buffering, which is functionally fine but removes the time-to-first-token benefit.
Do Gemini rate limits work differently?
The quota dimensions are vendor-specific and enforced per model rather than per account. Treat a 429 as a signal to back off exponentially rather than to change model.
Why does the same Gemini model cost different amounts at different providers?
Providers resell the same models at different markups, and some expose versioned variants at the same rate as the stable one. Compare the exact string — the table above lists the IDs we track.