Skip to main content

Imagen 4

Google Imagen 4 is a professional image generation model, called through the Gemini API endpoint.
Imagen 4 is currently in development. Features and availability may change.
POST /v1beta/models/imagen-4:generateContent

Basic Usage

curl "https://crazyrouter.com/v1beta/models/imagen-4:generateContent?key=YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "contents": [
      {
        "role": "user",
        "parts": [
          {"text": "A golden Labrador retriever running on a sunny meadow, photographic quality, shallow depth of field"}
        ]
      }
    ],
    "generationConfig": {
      "responseModalities": ["IMAGE"],
      "imageGenerationConfig": {
        "numberOfImages": 1,
        "aspectRatio": "16:9"
      }
    }
  }'

Response Format

{
  "candidates": [
    {
      "content": {
        "parts": [
          {
            "inlineData": {
              "mimeType": "image/png",
              "data": "iVBORw0KGgoAAAANSUhEUg..."
            }
          }
        ],
        "role": "model"
      },
      "finishReason": "STOP"
    }
  ]
}

Parameter Description

imageGenerationConfig

ParameterTypeDescription
numberOfImagesintegerNumber of images to generate, 1-4
aspectRatiostringAspect ratio: 1:1, 16:9, 9:16, 4:3, 3:4

Batch Generation

{
  "generationConfig": {
    "responseModalities": ["IMAGE"],
    "imageGenerationConfig": {
      "numberOfImages": 4,
      "aspectRatio": "1:1"
    }
  }
}
Imagen 4 is a pure image generation model, so responseModalities should be set to ["IMAGE"]. If you need text descriptions alongside images, use the Gemini image generation model instead.
For Imagen 4 prompts, it is recommended to use detailed descriptive language including style, lighting, composition, and other details for better generation results.