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

# Generations

> Lifecycle, waiting for results, outputs and failures.

A **generation** is one model run. You create it with a model, a mode and an `input`; it ends with outputs stored in your library, or with a typed error and a refund.

## Lifecycle

```mermaid theme={null}
stateDiagram-v2
  [*] --> queued: POST /generations
  queued --> processing: the model starts
  processing --> succeeded: outputs stored
  processing --> failed: moderation, timeout, provider error
  queued --> failed: lost before it started
  succeeded --> [*]
  failed --> [*]
```

| `status` | `status_detail` | What is happening |
| - | - | - |
| `queued` | `waiting_for_capacity` | Credits are reserved; the model is busy. `queue.position` is your rank among the generations waiting for the same model, across Argil. |
| `processing` | `generating` | The model is running. |
| `processing` | `finalizing` | The model is done; Argil is storing the outputs. |
| `succeeded` | | Every output is stored in your library, in its `API` folder, and shows in your playground. |
| `failed` | | `error` says why. Refunded, unless the model had produced its output. |

`succeeded` and `failed` are final: the object never changes again. `status_detail` is informative and may gain values; branch on `status`.

## Creating

`POST /v2/generations` does everything that can fail on your side before answering:

1. checks the model and mode are enabled for your workspace, and validates `input` against the mode’s schema;
2. resolves the media: assets of your library, elements of your workspace or Argil’s public library, and URLs, imported into your library; it waits up to 60 seconds for files still uploading or processing;
3. reserves the credits and queues the generation.

An error at any step is a [problem](https://docs.argil.ai/v2/platform/errors.md): no generation, no charge. To retry a request whose answer you did not get, send an [`Idempotency-Key`](https://docs.argil.ai/v2/platform/idempotency): the retry returns the generation already created instead of paying for a second one. To cap what one generation may cost, send `max_credits`: a generation that would reserve more is refused with `402 credit_limit_exceeded` before anything is reserved. URL inputs may already be in your library, since they are imported before the credit and plan checks. A `201` means the generation is queued and will end `succeeded` or `failed`.

Its outputs go into the `API` folder of your library. `GET /v2/generations` lists your workspace’s generations, newest first: those created through the API, and those made in the Argil app, which have no `input`, `metadata` or `webhook_url`. Only generations created through the API send [webhook events](https://docs.argil.ai/v2/platform/webhooks.md).

## Waiting for results

> [accordion] Wait in the request — images, scripts, notebooks
>
> Send `Prefer: wait=60` on `POST /v2/generations` or `GET /v2/generations/{id}`. The server holds the response until the generation is final or 60 seconds pass, then returns the current object, with `Preference-Applied: wait=60`. More than 60 reads as 60. Under load (20 waits open in your workspace), the answer comes at once without `Preference-Applied`: poll as usual. Most images finish within the first call; a ten-minute video takes about ten calls.
>
> ```python theme={null}
> gen = client.post("/generations", json=body, headers={"Prefer": "wait=60"}).json()
> while gen["status"] in ("queued", "processing"):
>     gen = client.get(f"/generations/{gen['id']}", headers={"Prefer": "wait=60"}).json()
> ```

> [accordion] Webhooks — backends, video
>
> Register endpoints once with `POST /v2/webhook_endpoints`: each final generation sends them one signed `generation.succeeded` or `generation.failed` event carrying the full generation. A `webhook_url` on the request also receives this generation’s event, unsigned. See [Webhooks](https://docs.argil.ai/v2/platform/webhooks.md).

> [accordion] Polling — anything else
>
> `GET /v2/generations/{id}` without `Prefer` returns at once. Until the generation is final, `Retry-After` says when to poll again. Polling faster does not finish sooner and counts against your rate limit.

For long batches, combine webhooks with a periodic `GET /v2/generations?completed_after=…` to catch what your receiver missed during an outage.

## Outputs

`outputs[]` holds one entry per produced file. Each `asset` is already in your library: Argil stores every output before marking the generation `succeeded`, so its URL works as soon as you see it.

```json theme={null}
"outputs": [
  {
    "type": "video",
    "asset": {
      "id": "asset_e8b14d2c6a9f4b7e8c3d1a0f5b2e9c46",
      "status": "ready",
      "source": "generation",
      "url": "https://argildotai.s3-accelerate.amazonaws.com/external-assets/7b8d74e9/out.mp4",
      "expires_at": null,
      "mime_type": "video/mp4",
      "width": 720,
      "height": 1280,
      "duration_seconds": 5.04
    }
  }
]
```

* Outputs are kept **until you delete them**, and their URLs do not expire.
* Reuse an output as the input of another generation by its asset id. See [Inputs and prompt tags](https://docs.argil.ai/v2/generate/inputs.md#chain-generations).

## Cost

`cost` follows the credits: `estimated` is the price of the request, `reserved` the whole credits held at creation, `charged` the final price and `refunded` the difference, both known once the generation is final. Models settled on actual usage charge what they produced; see [Credits and pricing](https://docs.argil.ai/v2/account/credits.md).

## Failures

A failed generation has an `error` with a stable `code`, a message you can show to your users, and `retryable`:

```json theme={null}
"error": {
  "code": "content_moderated",
  "message": "The model’s safety filter blocked an output resembling protected content (copyright, brands or public figures).",
  "retryable": false,
  "moderation": { "stage": "output", "category": "copyright" }
}
```

| `code` | Retry? | Typical cause |
| - | - | - |
| `content_moderated` | Change the input | The model’s safety filter blocked the prompt, a reference (often a real face) or the output. `moderation` gives the category, and the stage when the category implies one. |
| `provider_key_failed` | After fixing the key | The platform refused your workspace’s own key: invalid or revoked, its account unusable, or its quota spent. `message` names the platform and the key (`••••a1b2`). Update it in your workspace settings › Provider keys, or let the workspace fall back to Argil’s keys. |
| `insufficient_credits` | After a top-up | The balance dropped below the price before the generation started. |
| `model_unavailable` | Yes | The model’s provider is unavailable. |
| `timeout` | Yes | The model did not answer in time. |
| `invalid_input` | Contact us | The model refused an input Argil accepted. That is our bug; we are notified. |
| `output_processing_failed` | Yes | The model succeeded but its output could not be stored. Charged: the model ran. |
| `internal_error` | Yes | |

A generation that fails before the model produced its output is refunded, and `cost.refunded` shows it. `output_processing_failed` is charged, since the model ran.

## Deleting

`DELETE /v2/generations/{id}` removes a final generation from your history and from your playground. Its output assets stay in your library until you delete them with `DELETE /v2/assets/{id}`. Deleting a generation still running is `409 generation_not_terminal`.

## Capacity and queueing

Model capacity is shared across Argil. Generations start by plan priority, then in creation order. Beyond 200 generations waiting in your workspace, creation returns `429 too_many_queued_generations`. See [Rate limits](https://docs.argil.ai/v2/platform/rate-limits.md).


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