Gemini (Google Protocol)
1. Overview
A multimodal AI model from Google, designed to handle various data types including text, images, audio, video, and code.
API Compliance
This API is compliant with the Google Gemini interface specification and supports all official parameters.
Documentation Reference
This document lists only a subset of parameters. For a complete list, please refer to the official documentation.
Supported Google Models
gemini-3.1-pro-preview(Newest)gemini-3.1-flash-lite-previewgemini-3-flash-previewgemini-3-pro-preview(Deprecated, migrated to gemini-3.1-pro-preview)gemini-2.5-flash(Planned for deprecation in Oct 2026)gemini-2.5-pro(Planned for deprecation in Oct 2026)gemini-2.5-flash-lite
2. Request Instructions
- Request Method:
POST - Request URL:
https://api.exchangetoken.ai/v1beta/models/{model}:generateContent - Request URL (Streaming):
https://api.exchangetoken.ai/v1beta/models/{model}:streamGenerateContent?alt=sse
3. Request Parameters
3.1 Header Parameters
| Parameter | Type | Required | Description | Example |
|---|---|---|---|---|
| Content-Type | string | Yes | The request content type. Must be application/json. | application/json |
| Accept | string | Yes | The expected response content type. It's recommended to use application/json. | application/json |
| Authorization | string | Yes | The API Key for authentication. Format: Bearer $YOUR_API_KEY. | Bearer $YOUR_API_KEY |
3.2 Body Parameters (application/json)
| Parameter | Type | Required | Description | Example |
|---|---|---|---|---|
| contents | array | Yes | The content of the conversation with the model. For a single-turn query, this is a single instance. For multi-turn queries (like chat), this is a repeated field containing the conversation history. | [{"role":"user", "parts":[{"text":"A cute baby sea otter"}]}] |
| content.role | string | Yes | The role of the message author. Must be user or model. | user |
| content.parts | array | No | An ordered list of parts that make up a single message. Parts can have different MIME types. | [{"text":"A cute baby sea otter"}] |
| content.parts.text | string | No | Inline text content. | A cute baby sea otter |
| content.parts.inlineData | struct | No | Inline media bytes. | - |
| content.parts.inlineData.mimeType | string | Yes | The IANA standard MIME type of the source data. | image/png |
| content.parts.inlineData.data | string | Yes | The raw bytes of the media format. A base64-encoded string. | - |
| generationConfig | struct | No | Configuration options for model generation and output. | - |
Complete Code Examples
1. Text Generation
curl "https://api.exchangetoken.ai/v1beta/models/gemini-3-flash-preview:generateContent" \
-H "Authorization: Bearer $YOUR_API_KEY" \
-H "Content-Type: application/json" \
-X POST \
-d '{
"contents": [
{
"role": "user",
"parts": [
{
"text": "How does AI work?"
}
]
}
]
}'import requests
import json
url = "https://api.exchangetoken.ai/v1beta/models/gemini-3-flash-preview:generateContent"
headers = {
"Authorization": "Bearer YOUR_API_KEY",
"Content-Type": "application/json"
}
data = {
"contents": [
{
"role": "user",
"parts": [
{"text": "How does AI work?"}
]
}
]
}
response = requests.post(url, headers=headers, json=data)
print(response.json())2. Thinking Model
curl "https://api.exchangetoken.ai/v1beta/models/gemini-3-flash-preview:generateContent" \
-H "Authorization: Bearer $YOUR_API_KEY" \
-H "Content-Type: application/json" \
-X POST \
-d '{
"contents": [
{
"role": "user",
"parts": [
{
"text": "How does AI work?"
}
]
}
],
"generationConfig": {
"thinkingConfig": {
"thinkingLevel": "low"
}
}
}'import requests
import json
url = "https://api.exchangetoken.ai/v1beta/models/gemini-3-flash-preview:generateContent"
headers = {
"Authorization": "Bearer YOUR_API_KEY",
"Content-Type": "application/json"
}
data = {
"contents": [
{
"role": "user",
"parts": [
{"text": "How does AI work?"}
]
}
],
"generationConfig": {
"thinkingConfig": {
"thinkingLevel": "low"
}
}
}
response = requests.post(url, headers=headers, json=data)
print(response.json())Controlling Thinking
The Gemini model uses dynamic thinking by default, automatically adjusting its reasoning effort based on the complexity of the user's request. However, if you have specific latency constraints or need the model to engage in deeper reasoning, you can use parameters to control its thinking behavior.
Thinking Level (Gemini 3)
The thinkingLevel parameter (recommended for Gemini 3 and later models) can be used to control reasoning behavior.
The following table details the thinkingLevel settings for each model type:
| Thinking Level | Gemini 3 Pro | Gemini 3 Flash | Description |
|---|---|---|---|
| minimal | Not Supported | Supported | Matches the "no thinking" setting for most queries. For complex coding tasks, the model may perform very simple thinking. Minimizes latency for chat or high-throughput applications. Note that minimal does not guarantee that thinking is turned off. |
| low | Supported | Supported | Minimizes latency and cost. Best for simple instruction following, chat, or high-throughput applications. |
| medium | Not Supported | Supported | Balanced thinking, suitable for most tasks. |
| high | Supported (Default, Dynamic) | Supported (Default, Dynamic) | Maximizes reasoning depth. The model may take longer to generate the first (non-thinking) output token, but the result will be more carefully reasoned. |
For Gemini 3 Pro, you cannot disable thinking. Gemini 3 Flash also doesn't support completely turning off thinking, but the minimal setting implies the model might not think (though it still could). If you don't specify a thinking level, Gemini will use the default dynamic thinking level of "high" for Gemini 3 models.
Gemini 2.5 series models do not support thinkingLevel; use thinkingBudget instead.
Thinking Budget
The thinkingBudget parameter, introduced with the Gemini 2.5 series, provides guidance to the model on the specific number of thinking tokens to use for reasoning.
Important Note
Use the thinkingLevel parameter with Gemini 3 models. While thinkingBudget can be used for backward compatibility, using it with Gemini 3 Pro may result in suboptimal performance.
Below are the details for the thinkingBudget configuration for each model type. You can disable thinking by setting thinkingBudget to 0. Setting it to -1 enables dynamic thinking, meaning the model adjusts the budget based on the request's complexity.
| Model | Default Setting (no budget set) | Range | Disable Thinking | Enable Dynamic Thinking |
|---|---|---|---|---|
| 2.5 Pro | Dynamic Thinking | 128 to 32768 | Not applicable: Thinking cannot be disabled | thinkingBudget = -1 (Default) |
| 2.5 Flash | Dynamic Thinking | 0 to 24576 | thinkingBudget = 0 | thinkingBudget = -1 (Default) |
| 2.5 Flash Lite | Model does not think | 512 to 24576 | thinkingBudget = 0 | thinkingBudget = -1 |
3. System Instruction
curl "https://api.exchangetoken.ai/v1beta/models/gemini-3-flash-preview:generateContent" \
-H "Authorization: Bearer $YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"system_instruction": {
"parts": [
{
"text": "You are a cat. Your name is Neko."
}
]
},
"contents": [
{
"role": "user",
"parts": [
{
"text": "Hello there"
}
]
}
]
}'import requests
import json
url = "https://api.exchangetoken.ai/v1beta/models/gemini-3-flash-preview:generateContent"
headers = {
"Authorization": "Bearer YOUR_API_KEY",
"Content-Type": "application/json"
}
data = {
"system_instruction": {
"parts": [
{"text": "You are a cat. Your name is Neko."}
]
},
"contents": [
{
"role": "user",
"parts": [
{"text": "Hello there"}
]
}
]
}
response = requests.post(url, headers=headers, json=data)
print(response.json())4. Multimodal Input
# Use a temporary file to hold the base64 encoded image data
TEMP_B64=$(mktemp)
trap 'rm -f "$TEMP_B64"' EXIT
base64 $B64FLAGS $IMG_PATH > "$TEMP_B64"
# Use a temporary file to hold the JSON payload
TEMP_JSON=$(mktemp)
trap 'rm -f "$TEMP_JSON"' EXIT
cat > "$TEMP_JSON" << EOF
{
"contents": [
{
"role": "user",
"parts": [
{
"text": "Tell me about this instrument"
},
{
"inline_data": {
"mime_type": "image/jpeg",
"data": "$(cat "$TEMP_B64")"
}
}
]
}
]
}
EOF
curl "https://api.exchangetoken.ai/v1beta/models/gemini-3-flash-preview:generateContent" \
-H "Authorization: Bearer $YOUR_API_KEY" \
-H "Content-Type: application/json" \
-X POST \
-d "@$TEMP_JSON"import requests
import base64
import json
url = "https://api.exchangetoken.ai/v1beta/models/gemini-3-flash-preview:generateContent"
headers = {
"Authorization": "Bearer YOUR_API_KEY",
"Content-Type": "application/json"
}
# Read and encode the image
image_path = "path/to/image.jpeg"
with open(image_path, "rb") as image_file:
image_data = base64.b64encode(image_file.read()).decode('utf-8')
data = {
"contents": [
{
"role": "user",
"parts": [
{"text": "Tell me about this instrument"},
{
"inline_data": {
"mime_type": "image/jpeg",
"data": image_data
}
}
]
}
]
}
response = requests.post(url, headers=headers, json=data)
print(response.json())Supported Image Formats
Gemini supports the following image format MIME types:
- PNG -
image/png - JPEG -
image/jpeg - WEBP -
image/webp - HEIC -
image/heic - HEIF -
image/heif
To learn about other file input methods, see the guide on file input methods.
5. Streaming Response
curl "https://api.exchangetoken.ai/v1beta/models/gemini-3-flash-preview:streamGenerateContent?alt=sse" \
-H "Authorization: Bearer $YOUR_API_KEY" \
-H "Content-Type: application/json" \
--no-buffer \
-d '{
"contents": [
{
"role": "user",
"parts": [
{
"text": "Explain how AI works"
}
]
}
]
}'import requests
import json
# Note: Streaming requests use streamGenerateContent and the alt=sse parameter
url = "https://api.exchangetoken.ai/v1beta/models/gemini-3-flash-preview:streamGenerateContent?alt=sse"
headers = {
"Authorization": "Bearer YOUR_API_KEY",
"Content-Type": "application/json"
}
data = {
"contents": [
{
"role": "user",
"parts": [
{"text": "Explain how AI works"}
]
}
]
}
response = requests.post(url, headers=headers, json=data, stream=True)
for line in response.iter_lines():
if line:
print(line.decode('utf-8'))