OriginCoder

Gemini API Through an OpenAI-Compatible Gateway: curl, Python and Node

Published 2026-11-11

If you searched for "Gemini API" or "Gemini API proxy", you most likely want to call Gemini models without rewriting your existing code, or you want one key for several models. The short version: create a key in a Gemini group, point your OpenAI client at https://origincoder.com/v1, and pass a Gemini model name. This guide uses OriginCoder, the AI API gateway, to show curl, Python and Node.js, and also covers the Gemini-native paths the gateway exposes.

Disclosure: we run OriginCoder, so we have a stake in the gateway route. You can also use Google's own Gemini API directly; the code below can be compared against it by swapping in Google's address and key. Information here is current as of November 2026.

Which model name to use

Use the exact model name shown for Gemini in the console's model plaza. The set of Gemini models and their names change as Google releases new versions, so we do not list names here; the live list on the model pricing page is the source of truth. The examples use your-gemini-model as a placeholder. Replace it with a name copied from that page.

What you need

  • An OriginCoder account with a balance. Create an account.
  • An API key in a group that serves Gemini models. The group decides which models the key can call, and which groups exist today is shown in the console. A key from another group will answer "model not found" or a permission error for Gemini names.
  • Any OpenAI-compatible client: the official OpenAI SDK for Python or Node.js, or plain HTTP.

Option 1: the OpenAI-compatible format

This is the least work: keep the Chat Completions format and change only the Base URL, the key and the model name. The gateway converts the request into a form Gemini understands before forwarding it.

curl

curl https://origincoder.com/v1/chat/completions \
  -H "Authorization: Bearer sk-xxxx" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "your-gemini-model",
    "messages": [{"role": "user", "content": "Explain what a mutex is in two sentences."}]
  }'

Python

from openai import OpenAI

client = OpenAI(
    base_url="https://origincoder.com/v1",
    api_key="sk-xxxx",
)

resp = client.chat.completions.create(
    model="your-gemini-model",
    messages=[{"role": "user", "content": "Explain what a mutex is in two sentences."}],
)
print(resp.choices[0].message.content)

Node.js

import OpenAI from "openai";

const client = new OpenAI({
  baseURL: "https://origincoder.com/v1",
  apiKey: "sk-xxxx",
});

const resp = await client.chat.completions.create({
  model: "your-gemini-model",
  messages: [{ role: "user", content: "Explain what a mutex is in two sentences." }],
});
console.log(resp.choices[0].message.content);

Do not hard-code a real key. Read it from an environment variable such as process.env.ORIGINCODER_API_KEY or os.environ["ORIGINCODER_API_KEY"].

Streaming works as it does with the OpenAI API: set stream=True (Python) or stream: true (Node.js) and iterate over the chunks.

Option 2: the Gemini-native format

If your code or tool is already written against Google's own interface (for example generateContent), the gateway also exposes paths under /v1beta that follow the same shape as Google's, including /v1beta/models/{model}:generateContent and /v1beta/models/{model}:streamGenerateContent?alt=sse. You can authenticate with the x-goog-api-key header, an Authorization: Bearer header, or a key query parameter.

curl "https://origincoder.com/v1beta/models/your-gemini-model:generateContent" \
  -H "x-goog-api-key: sk-xxxx" \
  -H "Content-Type: application/json" \
  -d '{
    "contents": [{"role": "user", "parts": [{"text": "Explain what a mutex is in two sentences."}]}]
  }'

With Google's official SDKs, point the API address at https://origincoder.com. The option has a different name in each SDK, so follow the SDK's own documentation. Which methods and parameters work on the native format is best confirmed by testing and in the console; do not assume it matches Google's service exactly.

Why call Gemini through a gateway

  • One key for several providers. Change the model name and the same code moves between Gemini, Claude, GPT and DeepSeek on one balance. When that matters is covered in What is an AI gateway. The same pattern for DeepSeek is in the DeepSeek API guide.
  • Per-request records. Each call appears in the console usage records with token counts and cost.
  • One bill, instead of an account per provider.

The trade-offs are the usual gateway ones: your prompts pass through a third party, and a gateway can lag behind a provider's newest features. The full list is in the LLM gateway comparison. How the two settings switch providers and how to debug the usual differences is in What is an OpenAI-compatible API.

Troubleshooting

Symptom Likely cause Fix
401 or "invalid API key" Wrong or disabled key Copy the key again from the console
404 OpenAI-format Base URL missing /v1 or doubled; mistyped :generateContent in a native path Use https://origincoder.com/v1 for OpenAI clients; recheck the native path
"model not found" or 403 The key's group does not serve this model, or the name is misspelled Copy the name from the pricing page and use a key from a Gemini group
429 Rate limit hit Retry with backoff and check the key's limits in the console
Balance-related error No balance Top up in the console

Pricing and safety

Per-token prices for Gemini on OriginCoder are shown on the model pricing page and can differ from Google's own, so compare before you decide. Read the Terms of Service to see how your data is handled, and avoid sending confidential information. OriginCoder is an independent platform and is not affiliated with Google.

All guides

More guides