> ## Documentation Index
> Fetch the complete documentation index at: https://docs.apiany.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Image generation

> Generate images asynchronously or with sync-wait compatibility.

Use `/v1/images/generations` for production image generation.

```bash theme={null}
curl https://apiany.ai/v1/images/generations \
  -H "Authorization: Bearer $APIANY_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "nano-banana",
    "prompt": "A bright API dashboard rendered as a product hero image",
    "size": "1k"
  }'
```

The response returns a task:

```json theme={null}
{
  "task_id": "task_123",
  "status": "processing",
  "poll_url": "/v1/tasks/task_123"
}
```

APIAny schedules processing immediately after the task record is committed.
The `202` response does not wait for image generation to finish, so continue
polling `poll_url` until the task reaches a terminal state. The periodic task
worker remains a recovery mechanism for pending tasks.

## Prompt safety

Prompts that clearly combine a minor with exposure or emphasis of sensitive
body areas, or with explicit sexual or nudity content, return HTTP `400` with
code `content_policy`. Validation runs before task creation and credit
reservation, so no credits are charged. Revise the prompt to use an adult
subject (18+), remove sensitive-body close-ups, and keep the subject fully
clothed. Ordinary child-safe family, classroom, sports, and art scenes are not
blocked by this targeted rule.

## GPT-Image 2 size and quality

For `gpt-image-2`, send a native pixel size or `auto`:

```bash theme={null}
curl https://apiany.ai/v1/images/generations \
  -H "Authorization: Bearer $APIANY_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-image-2",
    "prompt": "A wide product launch visual for an AI API platform",
    "size": "2048x1152",
    "quality": "high",
    "n": 1
  }'
```

GPT-Image 2 outputs use `auto` or one of seven official popular sizes: `1024x1024`, `1536x1024`, `1024x1536`, `2048x2048`, `2048x1152`, `3840x2160`, and `2160x3840`. APIAny also accepts any positive integer `WIDTHxHEIGHT` as a target and maps it to the nearest popular size while preserving square, landscape, or portrait orientation. For example, `1280x720` maps to `1536x1024`, `1920x1080` maps to `2048x1152`, and `1440x2560` maps to `2160x3840`.

`quality` accepts `auto`, `low`, `medium`, or `high`; the default is `auto`. `n` accepts 1–10 and credits are charged for each generated image. Ratio shorthand such as `size: "4:3"` can be combined with the compatibility `resolution` values `"1K"`, `"2K"`, or `"4K"`; APIAny first derives a target and then applies the same nearest-popular-size mapping. Legacy requests that only send `aspect_ratio`, `resolution`, or `img_size` remain accepted. New integrations should prefer `auto` or one of the seven official popular sizes for predictable output and billing.

## Sync variant

`/v1/images/generations/sync` creates a task and waits up to the configured maximum wait time.

Use it for compatibility and demos. Use the async endpoint for production workloads.

## Image edits

`/v1/images/edits` supports OpenAI-style image editing workflows where the selected model supports reference images.
