Skip to main content
POST
/
v1beta
/
models
/
gemini-2.5-flash-image-preview:generateContent
Text to Image
curl --request POST \
  --url https://api.example.com/v1beta/models/gemini-2.5-flash-image-preview:generateContent

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.

gemini-2.5-flash-image-preview (text to image)

Gemini’s official format for the text to image API.

Supported inputs & outputs :

Inputs: Text Outputs: Text and image
{
  "error": {
    "message": "Invalid signature",
    "type": "401"
  }
}

Parameters

ParameterTypeRequiredDefaultDescription
contentsarray✅ Yes-The prompt for the generation.
generationConfigobject❌ No-The model defaults to returning text and image responses (['Text', 'Image']). You can configure the response to return only images without text using ( ['Image']).
imageConfigobject❌ No-1:1, 3:2, 2:3, 3:4, 4:3, 4:5, 5:4, 9:16, 16:9, 21:9. default 1:1

Aspect ratios

The model defaults to 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": 16,
        "candidatesTokenCount": 1290,
        "totalTokenCount": 1306,
        "thoughtsTokenCount": 0,
        "promptTokensDetails": [
            {
                "modality": "TEXT",
                "tokenCount": 16
            }
        ]
    }
}