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.
https://api.codingrouter.ai/v1beta/models/{model}:generateContenthttps://api.codingrouter.ai/v1beta/models/{model}:streamGenerateContent?alt=sseAuthentication
Use any one of three forms:
| Form | Example |
|---|---|
x-goog-api-key header | x-goog-api-key: sk-... |
key URL parameter | ...:generateContent?key=sk-... |
Authorization header | Authorization: Bearer sk-... |
URL parameters end up in logs and browser history, so use a header for server-side calls.
Request parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
contents | array | Yes | The conversation; each item has a role (user / model) and parts |
systemInstruction | object | No | System instruction, {"parts": [{"text": "..."}]} |
generationConfig | object | No | Generation parameters, see the table below |
tools | array | No | Function declarations {"functionDeclarations": [...]} |
safetySettings | array | No | Safety filter levels |
Each item in parts can be {"text": "..."} or {"inlineData": {"mimeType": "image/png", "data": "<base64>"}} (image, audio).
generationConfig
| Field | Type | Description |
|---|---|---|
temperature, topP, topK | number | Sampling parameters |
maxOutputTokens | integer | Maximum number of tokens to generate |
stopSequences | array | Stop sequences |
responseMimeType | string | Outputs JSON when application/json |
thinkingConfig | object | {"thinkingBudget": 1024, "includeThoughts": true} |
responseModalities | array | Output types: ["TEXT", "IMAGE"] for image models, ["AUDIO"] for speech models |
speechConfig | object | Voice settings for speech models |
Request example
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"}]}]
}'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)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
{
"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
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"}]}]}'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
{
"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
{
"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:
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
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:
{
"contents": [{
"role": "user",
"parts": [
{"inlineData": {"mimeType": "audio/wav", "data": "<audio base64>"}},
{"text": "Transcribe this audio."}
]
}]
}The transcription is in parts[].audioTranscription.text.
Embeddings
https://api.codingrouter.ai/v1beta/models/gemini-embedding-001:embedContentcurl "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.
