Skip to content

Gemini ​

Compatible with the Google Gemini API. You can use the Google GenAI SDK and Gemini CLI directly. For models in the gemini, gemini_vertex and gemini_image groups.

POSThttps://api.codingrouter.ai/v1beta/models/{model}:generateContent
POSThttps://api.codingrouter.ai/v1beta/models/{model}:streamGenerateContent?alt=sse

Authentication ​

Use any one of three forms:

FormExample
x-goog-api-key headerx-goog-api-key: sk-...
key URL parameter...:generateContent?key=sk-...
Authorization headerAuthorization: Bearer sk-...

URL parameters end up in logs and browser history, so use a header for server-side calls.

Request parameters ​

ParameterTypeRequiredDescription
contentsarrayYesThe conversation; each item has a role (user / model) and parts
systemInstructionobjectNoSystem instruction, {"parts": [{"text": "..."}]}
generationConfigobjectNoGeneration parameters, see the table below
toolsarrayNoFunction declarations {"functionDeclarations": [...]}
safetySettingsarrayNoSafety filter levels

Each item in parts can be {"text": "..."} or {"inlineData": {"mimeType": "image/png", "data": "<base64>"}} (image, audio).

generationConfig ​

FieldTypeDescription
temperature, topP, topKnumberSampling parameters
maxOutputTokensintegerMaximum number of tokens to generate
stopSequencesarrayStop sequences
responseMimeTypestringOutputs JSON when application/json
thinkingConfigobject{"thinkingBudget": 1024, "includeThoughts": true}
responseModalitiesarrayOutput types: ["TEXT", "IMAGE"] for image models, ["AUDIO"] for speech models
speechConfigobjectVoice settings for speech models

Request example ​

bash
curl "https://api.codingrouter.ai/v1beta/models/gemini-3.5-flash:generateContent" \
  -H "x-goog-api-key: $CODINGROUTER_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "contents": [{"role": "user", "parts": [{"text": "Explain what an API gateway is in one sentence"}]}]
  }'
python
from google import genai
from google.genai import types

client = genai.Client(
    api_key="sk-your-token",
    http_options=types.HttpOptions(base_url="https://api.codingrouter.ai"),
)

resp = client.models.generate_content(
    model="gemini-3.5-flash",
    contents="Explain what an API gateway is in one sentence",
)
print(resp.text)
js
import { GoogleGenAI } from "@google/genai";

const ai = new GoogleGenAI({
  apiKey: process.env.CODINGROUTER_KEY,
  httpOptions: { baseUrl: "https://api.codingrouter.ai" },
});

const resp = await ai.models.generateContent({
  model: "gemini-3.5-flash",
  contents: "Explain what an API gateway is in one sentence",
});
console.log(resp.text);

Response example ​

json
{
  "candidates": [{
    "content": {
      "role": "model",
      "parts": [{"text": "An API gateway is like the system's \"doorman\"..."}]
    },
    "finishReason": "STOP",
    "index": 0
  }],
  "usageMetadata": {"promptTokenCount": 9, "candidatesTokenCount": 50, "totalTokenCount": 59},
  "modelVersion": "gemini-3.5-flash"
}

The text may be split into several parts; concatenate them for the full answer. The SDK's resp.text is already concatenated. In multi-turn conversations, put the parts returned by the model (including the thoughtSignature field) back into contents unchanged.

Streaming ​

bash
curl "https://api.codingrouter.ai/v1beta/models/gemini-3.5-flash:streamGenerateContent?alt=sse" \
  -H "x-goog-api-key: $CODINGROUTER_KEY" \
  -H "Content-Type: application/json" \
  -d '{"contents": [{"role": "user", "parts": [{"text": "Write a short poem about the starry sky"}]}]}'
python
for chunk in client.models.generate_content_stream(model="gemini-3.5-flash", contents="Write a short poem about the starry sky"):
    print(chunk.text or "", end="", flush=True)

Each data: line is a response fragment with the same structure as above.

Thinking ​

json
{
  "contents": [{"role": "user", "parts": [{"text": "Design a rate-limiting algorithm"}]}],
  "generationConfig": {
    "thinkingConfig": {"thinkingBudget": 1024, "includeThoughts": true}
  }
}

When includeThoughts is true, the thinking summary is returned as a part with "thought": true.

Image input ​

json
{
  "contents": [{
    "role": "user",
    "parts": [
      {"inlineData": {"mimeType": "image/png", "data": "iVBORw0KGgo..."}},
      {"text": "What color is this image?"}
    ]
  }]
}

Image generation ​

Image models (such as gemini-3-pro-image and gemini-3.1-flash-image, in the gemini_image or gemini group) use the same API. The image is returned as base64 in inlineData:

bash
curl "https://api.codingrouter.ai/v1beta/models/gemini-3-pro-image:generateContent" \
  -H "x-goog-api-key: $CODINGROUTER_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "contents": [{"role": "user", "parts": [{"text": "A Shiba Inu running in the snow, cinematic lighting"}]}],
    "generationConfig": {"responseModalities": ["TEXT", "IMAGE"]}
  }'

Put both an image and text in parts to edit an image.

Text-to-speech ​

bash
curl "https://api.codingrouter.ai/v1beta/models/gemini-3.8-flash-tts:generateContent" \
  -H "x-goog-api-key: $CODINGROUTER_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "contents": [{"role": "user", "parts": [{"text": "Say cheerfully: Welcome to CodingRouter!"}]}],
    "generationConfig": {
      "responseModalities": ["AUDIO"],
      "speechConfig": {"voiceConfig": {"prebuiltVoiceConfig": {"voiceName": "Kore"}}}
    }
  }'

The audio is returned in inlineData (audio/wav).

Speech-to-text ​

Put the audio in inlineData and call gemini-3.5-transcribe:

json
{
  "contents": [{
    "role": "user",
    "parts": [
      {"inlineData": {"mimeType": "audio/wav", "data": "<audio base64>"}},
      {"text": "Transcribe this audio."}
    ]
  }]
}

The transcription is in parts[].audioTranscription.text.

Embeddings ​

POSThttps://api.codingrouter.ai/v1beta/models/gemini-embedding-001:embedContent
bash
curl "https://api.codingrouter.ai/v1beta/models/gemini-embedding-001:embedContent" \
  -H "x-goog-api-key: $CODINGROUTER_KEY" \
  -H "Content-Type: application/json" \
  -d '{"content": {"parts": [{"text": "First text"}]}}'

Returns {"embedding": {"values": [...]}}. You can also call the same model through the OpenAI-format Embeddings API.

Unsupported APIs ​

Other Gemini APIs such as countTokens are not supported yet.