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

# Generate images with Viggle Image

> Generate 1–6 PNG images from a text prompt, optionally guided by up to 8 reference images, at 1K or 2K.

Viggle Image generates PNG images from a text prompt. Add reference images to carry a subject, a product or a style into the result. One request makes 1 to 6 images at a fixed size you choose, and returns an `img_` job that you poll until the images are ready. Use it for character sheets, first frames for [video generation](https://docs.viggle.ai/v1/video/first-frame-to-video.md), thumbnails and marketing stills.

## Parameters

Send `multipart/form-data`, even without reference images. A JSON or URL-encoded body is rejected with `400`.

| Parameter | Required | Default | Values |
| - | - | - | - |
| `prompt` | Yes | | What to draw, up to 4000 characters (Unicode code points, so one CJK character counts as one) |
| `n` | No | `1` | 1–6 images |
| `resolution` | No | `1K` | `1K` or `2K`. Sets the size tier and the price |
| `aspect_ratio` | No | `1:1` | `1:1`, `16:9`, `9:16`, `4:3`, `3:4`, `3:2`, `2:3` |
| `seed` | No | random | 0–2147483647. Image `i` (from 0) uses `seed + i`, so a seed reproduces the whole set |
| `reference_image` | No | | Uploaded image, repeatable |
| `reference_image_url` | No | | Public `http(s)` image URL, repeatable |

You can send up to 8 reference images in total, in any mix of files and URLs. Each can be up to 24 MiB with a long-to-short side ratio of at most 8, in JPEG, PNG, WebP, GIF, BMP, TIFF or HEIC. The model reads uploads first, then URLs, in the order you sent them. Every field is in the [API reference](https://docs.viggle.ai/v1/api-reference/images/generate-images.md).

### Output sizes

`aspect_ratio` and `resolution` pick one fixed size. Reference images make `2K` smaller, at the same price.

| `aspect_ratio` | `1K` | `2K` | `2K` with reference images |
| - | - | - | - |
| `1:1` | 1024 × 1024 | 2048 × 2048 | 1536 × 1536 |
| `16:9` | 1376 × 768 | 2720 × 1536 | 2048 × 1152 |
| `9:16` | 768 × 1376 | 1536 × 2720 | 1152 × 2048 |
| `4:3` | 1184 × 896 | 2368 × 1760 | 1760 × 1344 |
| `3:4` | 896 × 1184 | 1760 × 2368 | 1344 × 1760 |
| `3:2` | 1248 × 832 | 2496 × 1664 | 1888 × 1248 |
| `2:3` | 832 × 1248 | 1664 × 2496 | 1248 × 1888 |

## Price

You pay per image: 1 credit ($0.01) at `1K`, 2 credits ($0.02) at `2K`. `aspect_ratio`, `seed` and reference images don't change it.

```
cost = n × (1 credit at 1K, or 2 credits at 2K)
```

Three `2K` images cost 6 credits (\$0.06). The whole amount is reserved when you create the job and refunded in full if the job fails.

If your balance cannot cover the job, the create call answers `402 INSUFFICIENT_CREDITS`, its message states the cost, and nothing starts. A `429 RATE_LIMITED` means the credit reservation gate was busy; retry with backoff.

## Generate, wait and download

The script asks for two `16:9` images at `1K` (2 credits), polls every 3 seconds and saves `image_0.png` and `image_1.png`. It needs no input files.

```bash cURL theme={null}
#!/usr/bin/env bash
set -euo pipefail
API="https://apis.viggle.ai/v1"
AUTH="Authorization: Bearer $VIGGLE_API_KEY"

image_id=$(curl -sf -X POST "$API/images" -H "$AUTH" \
  -F prompt="A watercolor fox reading a book under a maple tree" \
  -F aspect_ratio=16:9 \
  -F resolution=1K \
  -F n=2 | jq -r '.id')
echo "created $image_id"

while true; do
  job=$(curl -sf "$API/images/$image_id" -H "$AUTH")
  case "$(echo "$job" | jq -r '.status')" in
    ready) break ;;
    failed) echo "failed: $(echo "$job" | jq -c '.error')" >&2; exit 1 ;;
  esac
  sleep 3
done

i=0
for url in $(echo "$job" | jq -r '.images[].url'); do
  curl -sf -o "image_$i.png" "$url"
  echo "saved image_$i.png from $url"
  i=$((i + 1))
done
```

```javascript Node.js theme={null}
import { writeFile } from "node:fs/promises";

const API = "https://apis.viggle.ai/v1";
const headers = { Authorization: `Bearer ${process.env.VIGGLE_API_KEY}` };

async function call(path, init = {}) {
  const res = await fetch(`${API}${path}`, { ...init, headers });
  const body = await res.json();
  if (!res.ok) throw new Error(`HTTP ${res.status}: ${JSON.stringify(body.error)}`);
  return body;
}

const form = new FormData();
form.append("prompt", "A watercolor fox reading a book under a maple tree");
form.append("aspect_ratio", "16:9");
form.append("resolution", "1K");
form.append("n", "2");
let job = await call("/images", { method: "POST", body: form });
console.log(`created ${job.id}`);

while (job.status === "queued" || job.status === "processing") {
  await new Promise((r) => setTimeout(r, 3000));
  job = await call(`/images/${job.id}`);
}
if (job.status !== "ready") throw new Error(`failed: ${JSON.stringify(job.error)}`);

for (const [i, image] of job.images.entries()) {
  const png = await fetch(image.url);
  await writeFile(`image_${i}.png`, Buffer.from(await png.arrayBuffer()));
  console.log(`saved image_${i}.png (${image.width}x${image.height}, seed ${image.seed})`);
}
```

```python Python theme={null}
import os
import time
import requests

API = "https://apis.viggle.ai/v1"
headers = {"Authorization": f"Bearer {os.environ['VIGGLE_API_KEY']}"}

fields = {
    "prompt": "A watercolor fox reading a book under a maple tree",
    "aspect_ratio": "16:9",
    "resolution": "1K",
    "n": "2",
}
# files= makes requests send multipart/form-data, which the endpoint requires.
res = requests.post(
    f"{API}/images",
    headers=headers,
    files={name: (None, value) for name, value in fields.items()},
)
res.raise_for_status()
job = res.json()
print(f"created {job['id']}")

while job["status"] in ("queued", "processing"):
    time.sleep(3)
    res = requests.get(f"{API}/images/{job['id']}", headers=headers)
    res.raise_for_status()
    job = res.json()
if job["status"] != "ready":
    raise RuntimeError(f"failed: {job.get('error')}")

for i, image in enumerate(job["images"]):
    with open(f"image_{i}.png", "wb") as f:
        f.write(requests.get(image["url"]).content)
    print(f"saved image_{i}.png ({image['width']}x{image['height']}, seed {image['seed']})")
```

## Add reference images

Upload files with `reference_image`, pass URLs with `reference_image_url`, or mix both. Poll and download the same way.

```bash theme={null}
curl -X POST https://apis.viggle.ai/v1/images \
  -H "Authorization: Bearer $VIGGLE_API_KEY" \
  -F prompt="The same fox, now in winter, snow falling" \
  -F aspect_ratio=1:1 \
  -F resolution=2K \
  -F reference_image=@fox.png \
  -F reference_image_url=https://example.com/style.jpg
```

This makes one 1536 × 1536 image for 2 credits (\$0.02).

## Get the result

The create call answers with a `queued` job:

```json theme={null}
{
  "id": "img_b16a190d-2d44-41a0-8056-ef68183c3b9e",
  "status": "queued",
  "model": "viggle-image",
  "progress": 0,
  "images": [],
  "created_at": "2026-11-20T08:20:00Z",
  "completed_at": null,
  "error": null
}
```

Poll `GET /v1/images/{image_id}` every 2–3 seconds. `progress` rises as each image finishes. When `status` is `ready`, `images` lists all `n` images in order, each with `url`, `width`, `height` and the `seed` it used. A job makes the full set or fails as a whole, and one that hasn't finished within 15 minutes of starting to run fails.

> [!WARNING]
>
> **Download right away.** Each `url` lasts one hour, and every read of the job returns a fresh one. The files are deleted 24 hours after the job finishes; after that the job still reads `ready` with each `url` set to `null`.

Only the API key that created a job can read it; any other key gets `404 NOT_FOUND`. A failed job carries `error.code`, `error.message` and `error.retryable`. When `retryable` is `true`, create a new job with the same parameters; otherwise change the prompt or reference images first. Failed jobs are refunded. [Task lifecycle](https://docs.viggle.ai/v1/concepts/task-lifecycle.md) covers statuses and errors across the API.

## Next steps

> [card] [First frame to video](https://docs.viggle.ai/v1/video/first-frame-to-video.md)
>
> Animate an image with Viggle H3.

> [card] [3D characters](https://docs.viggle.ai/v1/3d/characters.md)
>
> Turn a character image into a rigged 3D character.

> [card] [API reference](https://docs.viggle.ai/v1/api-reference/images/get-an-image-job.md)
>
> The full image job object and every error.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.