Chat
Gemini generateContent
Call models in the native Google Gemini API format.
POST
/v1beta/models/{model}:generateContent
Compatible with the Google Gemini API (v1beta), so the official google-genai SDKs and Gemini-native tools work with RuToken. Use :generateContent for a single response and :streamGenerateContent for streaming.
Authentication
x-goog-api-key: sk-xxxx, or the query parameter ?key=sk-xxxx. Authorization: Bearer sk-xxxx also works.
Path parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
model |
string | Yes | Model ID, e.g. gemini-2.5-flash. |
The action after the colon is generateContent or streamGenerateContent.
Query parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
key |
string | No | API key, if not sent in a header. |
alt |
string | No | sse — return the stream as Server-Sent Events. Use with streamGenerateContent. |
Request body
| Parameter | Type | Required | Description |
|---|---|---|---|
contents |
array | Yes | Conversation turns. Each item has role (user or model) and parts. |
systemInstruction |
object | No | System prompt: {"parts": [{"text": "..."}]}. |
generationConfig |
object | No | Generation settings. See generationConfig below. |
tools |
array | No | functionDeclarations, googleSearch, codeExecution, urlContext — as supported by the model. |
toolConfig |
object | No | functionCallingConfig.mode: AUTO, ANY, NONE; optional allowedFunctionNames. |
safetySettings |
array | No | Items with category (e.g. HARM_CATEGORY_HARASSMENT) and threshold (e.g. BLOCK_ONLY_HIGH, BLOCK_NONE). |
cachedContent |
string | No | Name of cached content to use as context. |
Parts
| Part | Description |
|---|---|
text |
Plain text. |
inlineData |
{"mimeType": "image/png", "data": "<base64>"} — images, audio, video, PDF. |
fileData |
{"mimeType": "...", "fileUri": "..."} — a file referenced by URI. |
functionCall / functionResponse |
Tool call by the model and the result returned by your code. |
generationConfig
| Field | Type | Description |
|---|---|---|
temperature |
number | Sampling temperature, 0–2. |
topP |
number | Nucleus sampling. |
topK |
integer | Top-K sampling. |
maxOutputTokens |
integer | Maximum number of tokens to generate. |
candidateCount |
integer | Number of candidates to return. |
stopSequences |
array | Up to 5 strings that stop generation. |
responseMimeType |
string | text/plain or application/json. |
responseSchema |
object | Output schema when responseMimeType is application/json. |
responseModalities |
array | e.g. ["TEXT", "IMAGE"] for image-capable models. |
thinkingConfig |
object | thinkingBudget (tokens, 0 disables thinking on supported models, -1 dynamic), includeThoughts, or thinkingLevel. |
seed |
integer | Seed for more deterministic output. |
presencePenalty / frequencyPenalty |
number | Repetition penalties. |
Request example
cURL
curl "https://rutoken.ai/v1beta/models/gemini-2.5-flash:generateContent" \
-H "Content-Type: application/json" \
-H "x-goog-api-key: $API_KEY" \
-d '{
"systemInstruction": {"parts": [{"text": "You are a helpful assistant."}]},
"contents": [
{"role": "user", "parts": [{"text": "Explain recursion in one sentence."}]}
],
"generationConfig": {"temperature": 0.7, "maxOutputTokens": 512}
}'
Python
from google import genai
from google.genai import types
client = genai.Client(api_key="sk-xxxx", http_options={"base_url": "https://rutoken.ai"})
resp = client.models.generate_content(
model="gemini-2.5-flash",
contents="Explain recursion in one sentence.",
config=types.GenerateContentConfig(
system_instruction="You are a helpful assistant.",
temperature=0.7,
max_output_tokens=512,
),
)
print(resp.text)
Node.js
import { GoogleGenAI } from "@google/genai";
const ai = new GoogleGenAI({ apiKey: "sk-xxxx", httpOptions: { baseUrl: "https://rutoken.ai" } });
const resp = await ai.models.generateContent({
model: "gemini-2.5-flash",
contents: "Explain recursion in one sentence.",
config: {
systemInstruction: "You are a helpful assistant.",
temperature: 0.7,
maxOutputTokens: 512,
},
});
console.log(resp.text);
Response
json
{
"candidates": [
{
"content": {
"role": "model",
"parts": [
{"text": "Recursion is when a function calls itself to solve smaller versions of the same problem."}
]
},
"finishReason": "STOP",
"index": 0
}
],
"usageMetadata": {
"promptTokenCount": 12,
"candidatesTokenCount": 18,
"thoughtsTokenCount": 0,
"totalTokenCount": 30
},
"modelVersion": "gemini-2.5-flash"
}
| Field | Type | Description |
|---|---|---|
candidates[].content.parts |
array | Generated parts: text, inlineData (e.g. images), functionCall. Parts with thought: true contain thinking summaries. |
candidates[].finishReason |
string | STOP, MAX_TOKENS, SAFETY, RECITATION, etc. |
usageMetadata |
object | Token counts: prompt, candidates, thoughts and total. |
Streaming
bash
curl "https://rutoken.ai/v1beta/models/gemini-2.5-flash:streamGenerateContent?alt=sse" \
-H "Content-Type: application/json" \
-H "x-goog-api-key: $API_KEY" \
-N \
-d '{"contents": [{"role": "user", "parts": [{"text": "Write a short poem."}]}]}'
Each data: event is a GenerateContentResponse with the next fragment. See Streaming.
Notes
- Gemini models can also be called through Chat Completions in OpenAI format.
- Errors on this endpoint are returned in the OpenAI error format. See Errors.
- List models in Gemini format with
GET /v1beta/models. See List models.