Gemini format: generateContent
Call Gemini models in the native Gemini format (/v1beta/models/…:generateContent), including streaming, thinking settings, image, audio and video input, image generation and speech generation.
The native Gemini API matches the Google Gemini API. Paths start with /v1beta/models/, and the model name is part of the path. It serves the models marked with the Gemini endpoint type in Model Square; the key's group decides which of them you can use (see Groups). If you only want to chat with Gemini models, you can also use the OpenAI format; see Gemini via the OpenAI format.
POST https://codaapi.com/v1beta/models/{model}:generateContent
POST https://codaapi.com/v1beta/models/{model}:streamGenerateContent?alt=sse
Request headers
| Name | Required | Description |
|---|---|---|
x-goog-api-key |
One of three ways | sk-…. The google-genai SDK uses this header |
Authorization |
One of three ways | Bearer sk-… |
Content-Type |
Yes | application/json |
The third way is to send no authentication header and add ?key=sk-… after the address (?alt=sse&key=sk-… when streaming).
Address and authentication
- Base URL:
https://codaapi.com. Use paths under/v1beta/models/…; the gateway also forwards/v1/models/…in the Gemini format. - Key: put it in the
x-goog-api-keyheader, add?key=sk-…after the address, or useAuthorization: Bearer. A header is less likely to be recorded by logs and proxies. For where each form works, see Overview and auth.
Request body
The request body matches Google's official format. The gateway passes the fields upstream, and whether a parameter takes effect depends on the model itself. Use the camelCase field names from Google's documentation (generationConfig). The gateway parses the body by the camelCase names before forwarding it: at the top level it also accepts only two snake_case names, system_instruction and continuation_token, and any other top-level field written in snake_case (such as generation_config or safety_settings) is silently dropped and never reaches the upstream. Fields inside generationConfig (such as max_output_tokens or thinking_config) are accepted in either form, and so are inlineData in parts and the mimeType inside it, which can also be written inline_data and mime_type. Only the common parameters are listed below; Google's official documentation is authoritative for the full set.
| Parameter | Type | Required | Description |
|---|---|---|---|
contents |
array | Yes | The conversation, in order |
contents[].role |
string | No | user or model (what the model said) |
contents[].parts |
array | Yes | This turn's content, one part per element: text, inlineData (images, audio, video, PDFs and other files, as base64), or functionCall / functionResponse (tool calling) |
contents[].parts[].inlineData |
object | No | {"mimeType": "image/png", "data": "<base64>"}; see Images, Audio and Video |
systemInstruction |
object | No | System prompt, written as {"parts": [{"text": "…"}]} |
generationConfig.maxOutputTokens |
integer | No | The most tokens to generate |
generationConfig.temperature, topP, topK |
number | No | Sampling parameters |
generationConfig.stopSequences |
array | No | Stop generating when one of these strings appears |
generationConfig.responseMimeType, responseSchema |
— | No | To get JSON output, set responseMimeType to application/json and give the structure in responseSchema |
generationConfig.thinkingConfig |
object | No | Thinking settings. The Gemini 2.5 series uses thinkingBudget (a thinking budget in tokens); the Gemini 3 series uses thinkingLevel (minimal, low, medium or high; the levels available differ by model). includeThoughts: true returns thought summaries. The gateway forwards it unchanged; Google's documentation is authoritative for the values |
tools |
array | No | Tools, for example [{"functionDeclarations": [ … ]}] |
toolConfig |
object | No | How tools are called, for example {"functionCallingConfig": {"mode": "AUTO"}} |
Images
Images go in inline_data (or inlineData) as base64, in a part of their own next to the text. The request body:
{
"contents": [{
"parts": [
{"text": "Write a title and tags for this image"},
{"inline_data": {"mimeType": "image/png", "data": "iVBORw0KGgo…"}}
]
}]
}
data is only the base64 encoding itself, without a data:image/png;base64, prefix, and mimeType must match the image's actual format. Images count toward input tokens. The gateway doesn't provide Gemini's file upload API (Files API), so send images, audio and video directly in inline_data.
Audio
Audio is sent the same way as images, with the audio format in mime_type, for example audio/mp3 or audio/wav. You can ask the model to transcribe or summarize a recording, or answer questions about it. The request body:
{
"contents": [{
"role": "user",
"parts": [
{"text": "Transcribe this recording, then summarize it in three points"},
{"inline_data": {"mime_type": "audio/mp3", "data": "//MYxA…"}}
]
}]
}
usageMetadata.promptTokensDetails in the response lists the input tokens by type; audio is AUDIO:
"usageMetadata": {
"promptTokenCount": 191,
"candidatesTokenCount": 587,
"thoughtsTokenCount": 1709,
"totalTokenCount": 2487,
"promptTokensDetails": [
{"modality": "TEXT", "tokenCount": 10},
{"modality": "AUDIO", "tokenCount": 181}
]
}
Video
Video also goes in inline_data, with a mime_type such as video/mp4. The model both watches the frames and listens to the sound:
{
"contents": [{
"role": "user",
"parts": [
{"text": "Summarize this video in three sentences"},
{"inline_data": {"mime_type": "video/mp4", "data": "AAAAIGZ0eXBpc29t…"}}
]
}]
}
The frames and the sound count separately as VIDEO and AUDIO in promptTokensDetails, and a video a few minutes long can come to tens of thousands of tokens. The file travels as base64 in the request body, so compress or trim long audio and video first; the upstream sets the size limit.
Request examples
curl
curl "https://codaapi.com/v1beta/models/gemini-2.5-flash:generateContent" \
-H "x-goog-api-key: $GEMINI_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"systemInstruction": {"parts": [{"text": "Answer in one sentence."}]},
"contents": [{"role": "user", "parts": [{"text": "Introduce Gemini in one sentence"}]}],
"generationConfig": {"maxOutputTokens": 1024}
}'
google-genai SDK
Python (pip install google-genai)
from google import genai
from google.genai import types
client = genai.Client(
api_key="sk-your-key",
http_options=types.HttpOptions(
base_url="https://codaapi.com",
# Setting v1beta explicitly is recommended to match the Gemini API docs (SDK 3.x defaults to v1; the gateway forwards both paths)
api_version="v1beta",
),
)
response = client.models.generate_content(model="gemini-2.5-flash", contents="Hello, Gemini")
print(response.text)
Node.js (npm install @google/genai)
import { GoogleGenAI } from '@google/genai';
const ai = new GoogleGenAI({
apiKey: process.env.GEMINI_API_KEY,
httpOptions: { baseUrl: 'https://codaapi.com', apiVersion: 'v1beta' },
});
const response = await ai.models.generateContent({
model: 'gemini-2.5-flash',
contents: 'Hello, Gemini',
});
console.log(response.text);
Response
{
"candidates": [
{
"content": {"role": "model", "parts": [{"text": "Gemini is Google's multimodal model."}]},
"finishReason": "STOP",
"index": 0
}
],
"usageMetadata": {
"promptTokenCount": 15,
"candidatesTokenCount": 12,
"thoughtsTokenCount": 230,
"totalTokenCount": 257
},
"modelVersion": "gemini-2.5-flash"
}
| Field | Description |
|---|---|
candidates[0].content.parts |
The answer. Text is in text; parts with "thought": true are thought summaries; image models put images in inlineData; a tool call is a functionCall |
candidates[0].finishReason |
Why generation stopped: STOP (finished normally), MAX_TOKENS (cut off at the limit), SAFETY (blocked by safety filters) and so on |
usageMetadata.promptTokenCount |
Input tokens |
usageMetadata.candidatesTokenCount |
Output tokens (excluding thinking) |
usageMetadata.thoughtsTokenCount |
Tokens used for thinking, billed as output |
Streaming
Replace :generateContent with :streamGenerateContent and add alt=sse:
curl "https://codaapi.com/v1beta/models/gemini-2.5-flash:streamGenerateContent?alt=sse" \
-H "x-goog-api-key: $GEMINI_API_KEY" \
-H "Content-Type: application/json" \
-d '{"contents": [{"parts": [{"text": "Write a four-line poem"}]}]}'
The response is SSE, one data: {…} line per chunk. Each chunk has the structure shown above and contains only the newly generated part; the last chunk's usageMetadata is authoritative. In the SDKs, use generate_content_stream (Python) or generateContentStream (Node.js).
Model names
Gemini model names look like gemini-2.5-flash, gemini-2.5-pro and gemini-3-flash-preview. Model Square has the full list.
Model Square also lists names with a suffix, for example gemini-2.5-flash-nothinking and gemini-3-pro-preview-thinking. This is a form the gateway provides: the gateway strips the suffix, sends the base model name upstream, and rewrites thinkingConfig according to the suffix (-thinking turns thinking on and returns thought summaries, -nothinking turns thinking off). It works on both the native API and the OpenAI format; for details, see Model name suffixes.
Image generation
Gemini image models (for example gemini-2.5-flash-image) also use generateContent, and the generated image comes back as base64 in the response's inlineData. For usage, see Nano Banana.
Speech generation
Models with tts in their names turn text into speech. They are currently gemini-3.1-flash-tts-preview, gemini-3.8-flash-tts and gemini-3.8-flash-lite-tts, in the Gemini-官转 group. They also use generateContent: set generationConfig.responseModalities to ["AUDIO"] and choose voices in speechConfig. Below is a two-speaker conversation; each speaker must match a speaker's name in the text:
curl "https://codaapi.com/v1beta/models/gemini-3.1-flash-tts-preview:generateContent" \
-H "x-goog-api-key: $GEMINI_API_KEY" \
-H "Content-Type: application/json" \
-o response.json \
-d '{
"contents": [{
"role": "user",
"parts": [{"text": "Read this conversation aloud:\nAnya: What a lovely day!\nLiam: Perfect for a walk in the park."}]
}],
"generationConfig": {
"responseModalities": ["AUDIO"],
"speechConfig": {
"multiSpeakerVoiceConfig": {
"speakerVoiceConfigs": [
{"speaker": "Anya", "voiceConfig": {"prebuiltVoiceConfig": {"voiceName": "Kore"}}},
{"speaker": "Liam", "voiceConfig": {"prebuiltVoiceConfig": {"voiceName": "Puck"}}}
]
}
}
}
}'
For a single speaker, replace multiSpeakerVoiceConfig with "voiceConfig": {"prebuiltVoiceConfig": {"voiceName": "Kore"}}. Google's documentation lists the available voices.
The audio comes back as base64 in inlineData, as 16-bit mono PCM at 24000 Hz with no file header:
{
"candidates": [{
"content": {
"role": "model",
"parts": [{"inlineData": {"mimeType": "audio/L16;codec=pcm;rate=24000", "data": "+f/3//r/…"}}]
},
"finishReason": "STOP",
"index": 0
}],
"usageMetadata": {"promptTokenCount": 29, "candidatesTokenCount": 180, "totalTokenCount": 209}
}
To get a file you can play directly, decode it and add a WAV header. This Python reads the response.json saved above:
import base64
import json
import wave
with open("response.json", encoding="utf-8") as f:
part = json.load(f)["candidates"][0]["content"]["parts"][0]
pcm = base64.b64decode(part["inlineData"]["data"])
with wave.open("speech.wav", "wb") as wav:
wav.setnchannels(1) # mono
wav.setsampwidth(2) # 16-bit
wav.setframerate(24000) # 24000 Hz
wav.writeframes(pcm)
Speech generation is billed by tokens as well, with the generated audio counted in candidatesTokenCount. These models can only be called through the native API, since the OpenAI format can't express speechConfig.
Errors
On an error, the native Gemini API returns an OpenAI-format error body, not Google's official form:
{"error": {"message": "… (request id: 20261130…)", "type": "…", "code": "…"}}
The google-genai SDK raises an exception based on the HTTP status code, with the reason in error.message, ending with the request id. See Error formats; for what to do about each status code, see Troubleshooting.
Billing
Charged at this model's price in Model Square, based on the usageMetadata in the response, with thinking tokens counted as output. Models marked Per Request in Model Square (mostly image models) are charged per call. For the rules, see Pricing and multipliers; for each group's prices, see the price list.
What isn't supported yet
:countTokens(token counting) isn't supported yet and returns 404.- Gemini's file upload (Files API), cached content (cachedContents) and similar endpoints aren't provided on the gateway.
- Google's official OpenAI-compatible address (
/v1beta/openai/) only has the model list on the gateway. To call Gemini in the OpenAI format, usehttps://codaapi.com/v1; see Gemini via the OpenAI format.