Skip to content

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-preview
  • gemini-3-flash-preview
  • gemini-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

ParameterTypeRequiredDescriptionExample
Content-TypestringYesThe request content type. Must be application/json.application/json
AcceptstringYesThe expected response content type. It's recommended to use application/json.application/json
AuthorizationstringYesThe API Key for authentication. Format: Bearer $YOUR_API_KEY.Bearer $YOUR_API_KEY

3.2 Body Parameters (application/json)

ParameterTypeRequiredDescriptionExample
contentsarrayYesThe 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.rolestringYesThe role of the message author. Must be user or model.user
content.partsarrayNoAn ordered list of parts that make up a single message. Parts can have different MIME types.[{"text":"A cute baby sea otter"}]
content.parts.textstringNoInline text content.A cute baby sea otter
content.parts.inlineDatastructNoInline media bytes.-
content.parts.inlineData.mimeTypestringYesThe IANA standard MIME type of the source data.image/png
content.parts.inlineData.datastringYesThe raw bytes of the media format. A base64-encoded string.-
generationConfigstructNoConfiguration options for model generation and output.-

Complete Code Examples

1. Text Generation

bash
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?"
          }
        ]
      }
    ]
  }'
python
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

bash
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"
      }
    }
  }'
python
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 LevelGemini 3 ProGemini 3 FlashDescription
minimalNot SupportedSupportedMatches 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.
lowSupportedSupportedMinimizes latency and cost. Best for simple instruction following, chat, or high-throughput applications.
mediumNot SupportedSupportedBalanced thinking, suitable for most tasks.
highSupported (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.

ModelDefault Setting (no budget set)RangeDisable ThinkingEnable Dynamic Thinking
2.5 ProDynamic Thinking128 to 32768Not applicable: Thinking cannot be disabledthinkingBudget = -1 (Default)
2.5 FlashDynamic Thinking0 to 24576thinkingBudget = 0thinkingBudget = -1 (Default)
2.5 Flash LiteModel does not think512 to 24576thinkingBudget = 0thinkingBudget = -1

3. System Instruction

bash
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"
          }
        ]
      }
    ]
  }'
python
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

bash
# 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"
python
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

bash
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"
          }
        ]
      }
    ]
  }'
python
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'))