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.

In short: Gemini is reachable through an OpenAI-compatible route: point any OpenAI SDK at the base URL and pass a Gemini model ID. The critical step is reading the exact model string off GET /models, because Gemini IDs carry version and preview suffixes that differ between providers.
You need a key before the code below runs. Create an account, generate a key, and copy the base URL (https://aicomp.ai/v1). Create one free →
Check current rates → Free to sign up · $1 minimum top-up · No prepayment
Confirm the key works first. One command, no SDK, costs nothing:
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

Gemini models through the gateway — USD per 1M tokens
ModelGateway 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.

Cost note. Flash-class Gemini models are among the cheapest routes to long-context work, and the Lite variants cheaper still. If a task is mechanical — classification, extraction, routing — starting on the cheapest tier and stepping up only when quality demands it is usually the largest single saving available.

Troubleshooting

SymptomCause and fix
404 model not foundWrong ID string. Copy it from /models, suffixes included.
401 invalid keyKey truncated on copy, or env var not loaded in this runtime.
Unexpected response shapeYou hit a Gemini-native path with an OpenAI-shaped client. Use the compatible route.
Streaming returns nothingSome builds require SSE-compatible headers; test with curl before debugging the SDK.
429 immediatelyPer-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.

Related

Get API access