Skip to content

Gemini Image Generation (Gemini Native Format)

Besides the OpenAI-compatible Images endpoint, YouQi AI also supports Gemini's native image generation models, reusing the generateContent endpoint with responseModalities and imageConfig to request image output. See also the OpenAI Chat format variant (invoked via /v1/chat/completions).

Endpoint

POST /v1beta/models/{model}:generateContent

Base URL and auth are the same as Gemini Text Chat: https://ai.youqi.tech/v1beta, authenticated via the ?key= query parameter or the x-goog-api-key header.

Request parameters

ParameterTypeRequiredDescription
contents[].parts[].textstringYesImage description prompt
generationConfig.responseModalitiesarrayYesFixed to ["IMAGE"]
generationConfig.imageConfig.aspectRatiostringYesAspect ratio, e.g. 1:1, 16:9
generationConfig.imageConfig.imageSizestringYesImage size tier, e.g. 1K, 2K

Request example

bash
curl "https://ai.youqi.tech/v1beta/models/gemini-2.5-flash-image:generateContent?key=sk-YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "contents": [
      { "parts": [{ "text": "A white fox running under a starry sky, photorealistic" }] }
    ],
    "generationConfig": {
      "responseModalities": ["IMAGE"],
      "imageConfig": { "aspectRatio": "1:1", "imageSize": "1K" }
    }
  }'

Response example

The image is returned as inline Base64 data inside parts:

json
{
  "candidates": [
    {
      "content": {
        "role": "model",
        "parts": [
          {
            "inlineData": {
              "mimeType": "image/png",
              "data": "BASE64_ENCODED_IMAGE_DATA"
            }
          }
        ]
      },
      "finishReason": "STOP"
    }
  ],
  "usageMetadata": {
    "promptTokenCount": 15,
    "candidatesTokenCount": 0,
    "totalTokenCount": 15
  }
}

TIP

For generic text-to-image, /v1/images/generations (OpenAI-compatible format) covers more models and is simpler. Support for extra fields like thinkingConfig depends on the selected model.