Skip to main content

Gemini Native Format

Crazyrouter supports Google Gemini’s native API format, including the generateContent and streamGenerateContent endpoints.

Endpoints

POST /v1beta/models/{model}:generateContent
POST /v1beta/models/{model}:streamGenerateContent

Authentication

Pass the API Key via URL parameter:
?key=YOUR_API_KEY

Text Generation

curl "https://crazyrouter.com/v1beta/models/gemini-2.5-flash:generateContent?key=YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "contents": [
      {
        "role": "user",
        "parts": [
          {"text": "Explain what machine learning is in simple terms"}
        ]
      }
    ],
    "generationConfig": {
      "temperature": 0.7,
      "maxOutputTokens": 1024
    }
  }'

Response Format

{
  "candidates": [
    {
      "content": {
        "parts": [
          {
            "text": "Machine learning is a branch of artificial intelligence..."
          }
        ],
        "role": "model"
      },
      "finishReason": "STOP",
      "index": 0
    }
  ],
  "usageMetadata": {
    "promptTokenCount": 12,
    "candidatesTokenCount": 150,
    "totalTokenCount": 162
  }
}

Streaming Generation

curl "https://crazyrouter.com/v1beta/models/gemini-2.5-flash:streamGenerateContent?key=YOUR_API_KEY&alt=sse" \
  -H "Content-Type: application/json" \
  -d '{
    "contents": [
      {
        "role": "user",
        "parts": [{"text": "Write a short essay about the future of artificial intelligence"}]
      }
    ]
  }'

Multi-Turn Conversation

cURL
curl "https://crazyrouter.com/v1beta/models/gemini-2.5-flash:generateContent?key=YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "contents": [
      {
        "role": "user",
        "parts": [{"text": "Hi, I want to learn programming"}]
      },
      {
        "role": "model",
        "parts": [{"text": "Hello! Learning to program is a great choice. Do you have a specific direction in mind?"}]
      },
      {
        "role": "user",
        "parts": [{"text": "I want to learn Python, where should I start?"}]
      }
    ]
  }'

Thinking Mode

Gemini thinking models support reasoning before answering:
cURL
curl "https://crazyrouter.com/v1beta/models/gemini-2.5-flash:generateContent?key=YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "contents": [
      {
        "role": "user",
        "parts": [{"text": "Solve this equation: x^3 - 6x^2 + 11x - 6 = 0"}]
      }
    ],
    "generationConfig": {
      "thinkingConfig": {
        "thinkingBudget": 8000
      },
      "maxOutputTokens": 16000
    }
  }'

generationConfig Parameters

ParameterTypeDescription
temperaturenumberSampling temperature, 0-2
maxOutputTokensintegerMaximum output tokens
topPnumberNucleus sampling parameter
topKintegerTop-K sampling
stopSequencesarrayStop sequences
responseMimeTypestringResponse MIME type, e.g. application/json
responseSchemaobjectJSON Schema to constrain output format
thinkingConfigobjectThinking mode configuration
Gemini native format uses contents arrays and parts structures, which differ from OpenAI’s messages format. If you prefer the OpenAI format, you can use the Gemini OpenAI-compatible format.