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

# Generations

> Submit image and video generations, poll their status, and list past generations.

`POST /image/generate` and `POST /video/generate` return `202` with a pending generation. Poll `GET /generations/{id}/status` until it ends.

## Request body

| Field | Type | Description |
| - | - | - |
| `model` | string | Required. A model ID from GET /models |
| `input` | object | Required. Only the inputs GET /models lists for the model; any other field is a 400 |

## Status

| data.status | Final | Meaning |
| - | - | - |
| pending | No | Queued |
| processing | No | Running |
| completed | Yes | Outputs are ready in images or videos |
| failed | Yes | Every attempt failed, and the credits are refunded |

The top-level `status` is about your HTTP request; `data.status` is the generation's progress.

## Polling

Poll every 3 seconds for images and 5 for video, and stop after about 10 minutes. Polls count toward the rate limit; on `429`, wait `Retry-After` seconds.

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

API = "https://api.imagine.art/v1"
headers = {"Authorization": f"Bearer {os.environ['IMAGINE_API_KEY']}"}

generation = requests.post(f"{API}/image/generate", headers=headers, json={
    "model": "imagineart-2.0",
    "input": {"prompt": "A red convertible above Cinque Terre"},
}).json()["data"]

while generation["status"] not in ("completed", "failed"):
    time.sleep(3)
    response = requests.get(f"{API}/generations/{generation['id']}/status", headers=headers)
    if response.status_code == 429:
        time.sleep(int(response.headers.get("Retry-After", 3)))
        continue
    generation = response.json()["data"]

print(generation["images"])
```

## History

`GET /generations` lists past generations, newest first. Filter by `model` or `status`; page with `limit` and `cursor`. Output URLs are signed and valid for 166 hours, so download the outputs you want to keep. A generation that fails upstream is retried up to 3 times under the same id and charged once.


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