# Gemini Image Generation

Generate Gemini images, use reference images, and poll asynchronous image jobs.

## Endpoints

Gemini image models use the OpenAI-compatible image task endpoint:

```http
POST /v1/images/generations/jobs
GET /v1/images/generations/jobs/{job_id}
```

The synchronous endpoint is also available when the client can wait for the result:

```http
POST /v1/images/generations
```

## Model IDs

Common model IDs include:

```text
gemini-3.1-flash-image-preview
gemini-3-pro-image-preview
```

Use the model list endpoint to confirm the IDs available to the current API key.

## Text-to-image

```bash
curl https://kaienapi.com/v1/images/generations/jobs \\
  -H "Authorization: Bearer <YOUR_API_KEY>" \\
  -H "Content-Type: application/json" \\
  -d '{
    "model": "gemini-3.1-flash-image-preview",
    "prompt": "Create a clean editorial illustration of a city at sunrise",
    "aspect_ratio": "16:9",
    "image_size": "1K"
  }'
```

## Reference images

Pass one or more public image URLs in `image`:

```json
{
  "model": "gemini-3.1-flash-image-preview",
  "prompt": "Use image 1 as the subject and image 2 as the color reference.",
  "image": [
    "https://oss.example.com/subject.jpg",
    "https://oss.example.com/style.jpg"
  ],
  "aspect_ratio": "4:3",
  "image_size": "2K"
}
```

Make sure reference URLs are public and will not expire before the task completes.

## Reading results

Save the returned task ID and poll until the status is `succeeded` or `failed`. On success, read the `data` array. On failure, read `error.message` and preserve the full response for diagnosis.

`aspect_ratio` controls the frame, while `image_size` controls the output tier. Supported values depend on the model, so keep the model's error response when a combination is rejected.
