Guides

Use Google Gemini

LLMs Text

Using Google Gemini

4AICode's Gemini models use the OpenAI-compatible chat/completions protocol. Users only need to use their own sk-4ai-... token and change model to google/gemini-*. The platform routes requests through AI Studio or Vertex AI, depending on availability.

Available Models

ModelRecommended Use Cases
google/gemini-3.1-pro-previewComplex reasoning, long context, preview features
google/gemini-3-flash-previewFaster responses, preview features
google/gemini-2.5-flashEveryday Q&A, lightweight coding, low cost
google/gemini-2.5-proComplex tasks, code analysis, consistent quality

Model Routing

Use the google/gemini-* model name in your request. The platform manages upstream routing; current model availability and prices are shown in the console. Upstream quota limits or service interruptions can affect availability.

Python

from openai import OpenAI

client = OpenAI(
    base_url="https://relay.4aicode.com/v1",
    api_key="sk-4ai-xxxxxxxxxxxxxxxx",
)

resp = client.chat.completions.create(
    model="google/gemini-2.5-flash",
    messages=[
        {"role": "user", "content": "Introduce Gemini in one sentence"},
    ],
)

print(resp.choices[0].message.content)

TypeScript / Node.js

import OpenAI from "openai";

const client = new OpenAI({
  baseURL: "https://relay.4aicode.com/v1",
  apiKey: "sk-4ai-xxxxxxxxxxxxxxxx",
});

const resp = await client.chat.completions.create({
  model: "google/gemini-2.5-flash",
  messages: [{ role: "user", content: "Write a TypeScript hello world" }],
});

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

curl

curl https://relay.4aicode.com/v1/chat/completions \
  -H "Authorization: Bearer sk-4ai-xxxxxxxxxxxxxxxx" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "google/gemini-2.5-flash",
    "messages": [
      {"role": "user", "content": "ping"}
    ]
  }'

Streaming Output

curl https://relay.4aicode.com/v1/chat/completions \
  -H "Authorization: Bearer sk-4ai-xxxxxxxxxxxxxxxx" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "google/gemini-2.5-flash",
    "stream": true,
    "messages": [
      {"role": "user", "content": "Write a Go hello world"}
    ]
  }'

The response format remains OpenAI SSE:

data: {"choices":[{"delta":{"content":"Hello"}}]}
data: [DONE]

Image Input

Gemini currently supports base64 data URL image input:

resp = client.chat.completions.create(
    model="google/gemini-2.5-flash",
    messages=[{
        "role": "user",
        "content": [
            {"type": "text", "text": "Describe this image"},
            {
                "type": "image_url",
                "image_url": {
                    "url": "data:image/png;base64,iVBORw0KGgo..."
                },
            },
        ],
    }],
)

Remote https://... image URLs currently return a clear error. Download the image and convert it to a base64 data URL before sending it.

Common Errors

ErrorResolution
model not supportedConfirm that the model name is one of those listed above
no available google accountThe upstream Gemini service is temporarily unavailable; contact support
quota exceededInsufficient balance or quota; recharge or contact your team administrator
upstream errorGoogle upstream instability or API key quota issues; try again later