Skip to main content

Gemini Image Generation

Gemini image generation models (such as gemini-2-5-flash-image, gemini-3-pro-image-preview) support generating images through conversation.
POST /v1beta/models/{model}:generateContent

Basic Image Generation

curl "https://crazyrouter.com/v1beta/models/gemini-2-5-flash-image:generateContent?key=YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "contents": [
      {
        "role": "user",
        "parts": [
          {"text": "Generate a seaside landscape painting at sunset, oil painting style"}
        ]
      }
    ],
    "generationConfig": {
      "responseModalities": ["TEXT", "IMAGE"]
    }
  }'

Response Format

{
  "candidates": [
    {
      "content": {
        "parts": [
          {
            "text": "Here is an oil painting of a seaside sunset:"
          },
          {
            "inlineData": {
              "mimeType": "image/png",
              "data": "iVBORw0KGgoAAAANSUhEUg..."
            }
          }
        ],
        "role": "model"
      },
      "finishReason": "STOP"
    }
  ]
}

Aspect Ratio Control

Control the aspect ratio of generated images through prompts or parameters:
cURL
curl "https://crazyrouter.com/v1beta/models/gemini-2-5-flash-image:generateContent?key=YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "contents": [
      {
        "role": "user",
        "parts": [
          {"text": "Generate a 16:9 widescreen landscape painting"}
        ]
      }
    ],
    "generationConfig": {
      "responseModalities": ["TEXT", "IMAGE"],
      "imageGenerationConfig": {
        "aspectRatio": "16:9"
      }
    }
  }'

Supported Aspect Ratios

Aspect RatioDescription
1:1Square
16:9Widescreen landscape
9:16Portrait vertical
4:3Standard landscape
3:4Standard portrait

Image Count Control

{
  "generationConfig": {
    "responseModalities": ["TEXT", "IMAGE"],
    "imageGenerationConfig": {
      "numberOfImages": 4
    }
  }
}
responseModalities must include "IMAGE" for the model to generate images. If only "TEXT" is set, the model will only return text descriptions.
Image generation consumes a significant number of tokens, and the Base64 image data in responses can be large. It is recommended to control the number of generated images appropriately.