All postsGemini

How to call the Gemini API with the OpenAI SDK

Use Gemini 4 Argon and Gemini 3.8 Flash from the OpenAI Python or Node SDK by changing two lines. No new client library, no code rewrite.

2 min readUtopixel team

Most apps already talk to models through the OpenAI SDK. If you want to try Google's Gemini models, you do not need to add the Google client library or rewrite your prompts. Point the OpenAI SDK at Utopixel and change the model name.

This guide shows the two lines to change, then how to pick between Gemini models and how to add a backup model.

What you need

  1. A Utopixel account. Sign in and add credits.
  2. An API key from the API keys page. It starts with sk-vb-.

Python

Install the OpenAI SDK if you do not have it yet:

pip install openai

Set the base URL and your key, then call a Gemini model by its id:

from openai import OpenAI

client = OpenAI(
    base_url="https://utopixel.online/api/v1",
    api_key="sk-vb-...",
)

resp = client.chat.completions.create(
    model="google/gemini-4-argon",
    messages=[{"role": "user", "content": "Explain vector databases in two sentences."}],
)

print(resp.choices[0].message.content)
print(resp.usage.cost)  # what this request cost, in USD

Those are the only changes: base_url and api_key. Everything else, including streaming and tool calls, uses the normal OpenAI SDK.

Node.js

npm install openai
import OpenAI from "openai";

const client = new OpenAI({
  baseURL: "https://utopixel.online/api/v1",
  apiKey: process.env.UTOPIXEL_API_KEY,
});

const resp = await client.chat.completions.create({
  model: "google/gemini-4-argon",
  messages: [{ role: "user", content: "Explain vector databases in two sentences." }],
});

console.log(resp.choices[0].message.content);

Which Gemini model to use

  • Gemini 4 Argon is Google's flagship reasoning model. Use it for hard coding tasks, long documents and multi step agents.
  • Gemini 3.8 Flash is fast and much cheaper. Use it for chat, summaries, extraction and anything with high volume.

A common pattern is to start every request on Flash and only send the hard ones to Argon. Since both use the same client, switching is a one word change:

model = "google/gemini-4-argon" if task.is_hard else "google/gemini-3.8-flash"

Current prices per million tokens are on each model page and on the pricing page.

Add a backup model

Providers have bad minutes. Pass a models list and Utopixel tries the next model if the first one fails. In the Python SDK, send it through extra_body:

resp = client.chat.completions.create(
    model="google/gemini-3.8-flash",
    messages=[{"role": "user", "content": "Summarize this ticket."}],
    extra_body={"models": ["deepseek/deepseek-v4.1-flash"]},
)

print(resp.model)  # the model that actually answered

The model field in the response always names the model that answered, so your logs stay honest.

Already using the Anthropic SDK?

That works too. Set the base URL to https://utopixel.online/api and keep your code:

import anthropic

client = anthropic.Anthropic(base_url="https://utopixel.online/api", api_key="sk-vb-...")
msg = client.messages.create(
    model="google/gemini-3.8-flash",
    max_tokens=1024,
    messages=[{"role": "user", "content": "Hello"}],
)

Next steps

  • Browse every model and price on the models page.
  • Read the docs for streaming, the Responses API and error codes.
Questions? Write to us and a person answers: [email protected]

More from the blog

Start building in minutes.

One API key for the models of OpenAI, Google, DeepSeek, Moonshot AI, Qwen, xAI, Z.ai, Meta, Amazon, AionLabs, Anthropic, Baidu, ByteDance Seed, Cohere, Elorian, Fireworks AI, IBM, inclusionAI, Inference.net, KT, Liquid AI, Meituan, Meta, MiniMax, Mistral AI, Moondream, Motif Technologies, Nex AGI, NVIDIA, Particle AI, Perceptron, Prism ML, Reflection AI, Reka, Relace, Ricursive AI, Sakana AI, StepFun, Tencent, Thinking Machines, Unbiased, Upstage, Writer and Xiaomi. Start free, no card needed.