Gemini 4 OpenAI-Compatible API: Migrating from Google AI Studio & google-genai
Replace google-genai generateContent calls with standard OpenAI SDK POST /v1/chat/completions behind DeepClub (https://deepclub.net/v1) to run Gemini 4 Carbon, Neon, Argon, and Hydrogen with 1M context, ZDR, and unified pay-as-you-go billing.
Why Teams Move Gemini 4 Workloads to an OpenAI-Compatible Gateway
Google AI Studio is great for quick experiments, but production coding agents and multi-model apps often hit three friction points: tight free/low-tier 429 rate limits, Google Cloud billing setup hurdles, and maintaining a separate google-genai client alongside OpenAI and Anthropic SDKs.
On DeepClub, all four Gemini 4 models (gemini-4-carbon, gemini-4-neon, gemini-4-argon, gemini-4-hydrogen) are served over standard OpenAI-compatible POST /v1/chat/completions with site-wide Zero Data Retention (ZDR) and pay-as-you-go top-ups.
Drop-In Migration: google-genai → Official OpenAI SDK
Python (Streaming + Usage Audit)
import os
from openai import OpenAI
client = OpenAI(
base_url="https://deepclub.net/v1",
api_key=os.environ["DEEPCLUB_API_KEY"],
timeout=180.0,
)
stream = client.chat.completions.create(
model="gemini-4-neon", # swap freely with gemini-4-carbon / argon / hydrogen
stream=True,
stream_options={"include_usage": True},
messages=[
{"role": "system", "content": "You are a senior backend engineer. Output concise, runnable code."},
{"role": "user", "content": "Write a Go HTTP client factory with sane dial, TLS, and response timeouts."},
],
)
for chunk in stream:
if chunk.choices and chunk.choices[0].delta.content:
print(chunk.choices[0].delta.content, end="", flush=True)
elif chunk.usage:
print(f"\n[usage] in={chunk.usage.prompt_tokens} out={chunk.usage.completion_tokens}")
TypeScript (Vercel AI SDK 5+ — Avoid the /v1/responses 404 Trap)
In @ai-sdk/openai v5+, calling deepclub("gemini-4-neon") defaults to /v1/responses. Always use .chat() for Gemini 4:
import { createOpenAI } from '@ai-sdk/openai'
import { generateText } from 'ai'
const deepclub = createOpenAI({
baseURL: 'https://deepclub.net/v1',
apiKey: process.env.DEEPCLUB_API_KEY,
})
const { text, usage } = await generateText({
model: deepclub.chat('gemini-4-neon'),
prompt: 'Summarize three ways to avoid N+1 queries in GORM.',
})
console.log(text, usage)
Field Mapping Cheat Sheet
google-genai Native |
OpenAI Compatible (/v1/chat/completions) |
Notes |
|---|---|---|
system_instruction |
First {"role": "system", ...} message |
Keep static prefix unchanged to hit cache_read discounts |
role: "model" |
role: "assistant" |
Standard OpenAI message history |
response_mime_type="application/json" |
response_format={"type": "json_object"} |
Validate output with Zod or Pydantic |
function_declarations |
tools=[{"type": "function", ...}] |
Always append the full assistant tool_calls turn before role: "tool" |
Compare live per-1M-token rates across all four tiers on Gemini 4 API Pricing & Tier Guide or check Cline & Roo Code Custom API Setup.
Frequently Asked Questions
- Why does pointing the Google GenAI SDK at DeepClub return 404?
- google-genai sends requests to Google-native /v1beta/models/...:generateContent paths. DeepClub serves Gemini 4 text models over standard OpenAI-compatible POST /v1/chat/completions—use the official OpenAI SDK or OpenAI-compatible IDE mode with base_url="https://deepclub.net/v1".
- Can I fail over between Gemini 4 and DeepSeek V4.1 using the exact same code?
- Yes. Both Gemini 4 (carbon/neon/argon/hydrogen) and DeepSeek V4.1 Flash share POST /v1/chat/completions behind one DeepClub API key, so failover only requires swapping the model string.
Updated