Skip to main content
POST
/
v1beta
/
models
/
gemini-2.5-flash-image-preview:generateContent
Image to Image
curl --request POST \
  --url https://gptproto.com/v1beta/models/gemini-2.5-flash-image-preview:generateContent \
  --header 'Authorization: <authorization>' \
  --header 'Content-Type: application/json' \
  --data '{
  "contents": [
    {
      "parts": [
        {
          "text": "<string>",
          "inline_data": {
            "mime_type": "<string>",
            "data": "<string>"
          }
        }
      ]
    }
  ],
  "generationConfig": {
    "responseModalities": [
      "<string>"
    ],
    "imageConfig": {
      "aspectRatio": "<string>"
    }
  }
}'
{
  "error": {
    "message": "Invalid signature",
    "type": "401"
  }
}

Caution

The gemini-2.0-flash-preview-image-generation and gemini-2.5-flash-image-preview models will be retired on October 31, 2025. Migrate any workflows to gemini-2.5-flash-image before that date to avoid service disruption.

Overview

Google Gemini 2.5 Flash Image preview, a powerful new image generation and editing model with advanced features and creative control.

Supported inputs & outputs :

Inputs: Text and Images Outputs: Text and image

Authentication

This endpoint requires authentication using a Bearer token.
Authorization
string
default:"sk-***********"
required
Your API key in the format: YOUR_API_KEY

Request Body

contents
array
required
generationConfig
object

Image to Image

curl -X POST "https://gptproto.com/v1beta/models/gemini-2.5-flash-image-preview:generateContent" \
  -H "Authorization: YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "contents": [
    {
      "parts": [
        {
          "text": "Using the provided image of my cat, please add a small, knitted wizard hat on its head. Make it look like it's sitting comfortably and not falling off."
        },
        {
          "inline_data": {
            "mime_type": "image/jpeg",
            "data": "iVBORw0KGgoAAAANSUhEUgAAANQAAAFPCA...."
          }
        }
      ]
    }
  ],
  "generationConfig": {
    "responseModalities": [
      "TEXT",
      "IMAGE"
    ]
  }
}'
Technical specifications
  • Maximum images per prompt: 3
  • Maximum image size: 7 MB
  • Supported aspect ratios: 1:1, 3:2, 2:3, 3:4, 4:3, 4:5, 5:4, 9:16, 16:9, 21:9
  • Supported MIME types: image/png, image/jpeg, image/webp

Generate Content

You can optionally configure the response modalities and aspect ratio of the model’s output in the config field of generate_content calls.

Output types

The model defaults to returning text and image responses (i.e. response_modalities=['Text', 'Image']). You can configure the response to return only images without text using response_modalities=['Image'].

Aspect ratios

The model defaults to matching the output image size to that of your input image, or otherwise generates 1:1 squares. You can control the aspect ratio of the output image using the aspect_ratio field under image_config in the response request: The different ratios available and the size of the image generated are listed in this table:
Aspect ratioResolution
1:11024x1024
2:3832x1248
3:21248x832
3:4864x1184
4:31184x864
4:5896x1152
5:41152x896
9:16768x1344
16:91344x768
21:91536x672

Response

{
    "candidates": [
        {
            "content": {
                "role": "model",
                "parts": [
                    {
                        "inlineData": {
                            "mimeType": "image/png",
                            "data": "image base64"
                        }
                    }
                ]
            },
            "finishReason": "STOP"
        }
    ],
    "usageMetadata": {
        "promptTokenCount": 1302,
        "candidatesTokenCount": 1290,
        "totalTokenCount": 2592,
        "thoughtsTokenCount": 0,
        "promptTokensDetails": [
            {
                "modality": "IMAGE",
                "tokenCount": 1290
            },
            {
                "modality": "TEXT",
                "tokenCount": 12
            }
        ]
    },
    "modelVersion": "gemini-2.5-flash-image-preview"
}
{
  "error": {
    "message": "Invalid signature",
    "type": "401"
  }
}