Skip to content

Gemini Image Generation · OpenAI Chat Format

Besides the Gemini native format (the generateContent endpoint), Gemini image generation models can also be invoked through the standard /v1/chat/completions endpoint using the OpenAI Chat request shape, passing image-specific parameters via extra_body.google.image_config.

Endpoint

POST /v1/chat/completions

Request parameters

ParameterTypeRequiredDescription
modelstringYesGemini image model identifier
messages[].rolestringYesMessage role, e.g. user
messages[].contentstringYesImage description prompt
streambooleanNoWhether to stream the response
extra_body.google.image_config.aspect_ratiostringYesAspect ratio, e.g. 1:1, 16:9
extra_body.google.image_config.image_sizestringYesImage size tier, e.g. 1K, 2K

Request example

bash
curl https://ai.youqi.tech/v1/chat/completions \
  -H "Authorization: Bearer sk-YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gemini-2.5-flash-image",
    "messages": [
      { "role": "user", "content": "A white fox running under a starry sky, photorealistic" }
    ],
    "extra_body": {
      "google": {
        "image_config": { "aspect_ratio": "1:1", "image_size": "1K" }
      }
    }
  }'

Response example

The response shape matches the standard Chat endpoint; image data is embedded in choices[].message.content:

json
{
  "id": "chatcmpl-abc123",
  "object": "chat.completion",
  "model": "gemini-2.5-flash-image",
  "created": 1715367049,
  "choices": [
    {
      "index": 0,
      "message": { "role": "assistant", "content": "..." },
      "finish_reason": "stop"
    }
  ],
  "usage": { "prompt_tokens": 15, "completion_tokens": 0, "total_tokens": 15 }
}

TIP

If your client already integrates with the standard Chat format, prefer this endpoint. For finer-grained image control fields, see the Gemini native format.