Video generation is asynchronous. You submit a task, poll it until it finishes, then download the file. It uses the same API key and host as every other endpoint.

## How it works

1. `POST /v1/videos` submits the task and returns it right away with status `queued`.
2. `GET /v1/videos/{id}` returns the task. Poll it every 10 seconds or so until the status is `completed`, `failed`, `cancelled`, or `expired`. Most videos take from under a minute to a few minutes.
3. `GET /v1/videos/{id}/content` downloads the video. Download it before `expires_at`. We don't keep a copy.

```bash
curl https://api.lune.io/v1/videos \
  -H "Authorization: Bearer $API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"model": "<video model id>", "prompt": "A red fox running through snow", "seconds": "5"}'
```

Pick a video model on [Models](/models?category=video). Its page has a ready-to-run example under **How to call**, with the model id filled in, and lists the sizes it sells. Without `size`, the model's default size is used.

Then poll, and download once it completes:

```bash
curl https://api.lune.io/v1/videos/$VIDEO_ID \
  -H "Authorization: Bearer $API_KEY"
```

Then download:

```bash
curl -o video.mp4 https://api.lune.io/v1/videos/$VIDEO_ID/content \
  -H "Authorization: Bearer $API_KEY"
```

The OpenAI SDK works too: point it at `https://api.lune.io/v1` and call `client.videos.create(model=..., prompt=..., seconds=..., size=...)`, then `client.videos.retrieve(id)` and `client.videos.download_content(id)`. An `input_reference` image is used as the first frame. `GET /v1/videos` also accepts the SDK's `after` cursor, and `client.videos.delete(id)` cancels a task (see [Cancelling](#cancelling)). The SDK's `remix`, `edit`, `extend` and `create_character` calls aren't supported.

## Request fields

| Field | Required | Description |
|---|---|---|
| `model` | Yes | A video [model id](/docs/endpoints#model-ids) from [Models](/models?category=video), in the form `vendor/model`. |
| `prompt` | Yes | What to generate. Prompts are not stored. |
| `seconds` | No | Output length in whole seconds. Range and default depend on the model; see [Sizes and lengths](#sizes-and-lengths). |
| `size` | No | `<width>x<height>`, for example `1280x720`. Which sizes are accepted, and the default, depend on the model; see [Sizes and lengths](#sizes-and-lengths). |
| `first_frame` | No | Image to start from: an `http://` or `https://` URL, or a `data:image/…;base64,` URI. |
| `last_frame` | No | Image to end on. Send it together with `first_frame`. |
| `reference_images` | No | Up to 9 reference images (5 on some models). Can't be combined with `first_frame` or `last_frame`. |

Image inputs work on Seedance, Vega and MiniMax models. Some models accept image URLs only.

The size decides the resolution, and the resolution decides the price. Each model page lists the resolutions it sells. A size whose resolution isn't listed is rejected with `400 unsupported_video_option` — you are never silently billed at a different resolution. Send `seconds` and `size` explicitly so you know which price applies.

## Sizes and lengths

| Models | Accepted sizes | Default size | Seconds |
|---|---|---|---|
| Seedance | Exact sizes only, listed below | `1280x720` (720p) | Depends on the version: 2–12 (1.0), 4–15 (2.0), 4–30 (2.5). Default 5 |
| WAND Vega | Aspect ratio 21:9, 16:9, 4:3, 1:1, 3:4 or 9:16. The short side sets the resolution: 768 → 768p, 1080 → 1080p, 1440 → 2k, 2160 → 4k | `1366x768` (768p) | 4–15. Default 5 |
| MiniMax H3 | Same rule as Vega; 768p and 2k only | `1366x768` (768p) | 4–15. Default 5 |
| MiniMax H3-Max | Same rule as Vega; 480p and 768p only | `1366x768` (768p) | 5–15. Default 5 |
| Other models | The short side sets the resolution, for example `1280x720` and `720x1280` are both 720p | `1280x720` (720p) | 1–60. Default 4 |

Seedance sizes by resolution (16:9, 4:3, 1:1, 3:4, 9:16, 21:9):

| Resolution | Sizes |
|---|---|
| 480p | `854x480`, `752x560`, `640x640`, `560x752`, `480x854`, `992x432` |
| 720p | `1280x720`, `1112x834`, `960x960`, `834x1112`, `720x1280`, `1470x630` |
| 1080p | `1920x1080`, `1664x1248`, `1440x1440`, `1248x1664`, `1080x1920`, `2206x946` |
| 4k | `3840x2160`, `3326x2494`, `2880x2880`, `2494x3326`, `2160x3840`, `4398x1886` |

A request without `size` is priced at the default size's resolution. If the model doesn't sell that resolution, the request is rejected.

For Seedance we only reject lengths outside 2–30 seconds ourselves. A length inside that range but outside what the chosen version supports is rejected by the model: you get `400 upstream_error` and nothing is charged.

Send an `Idempotency-Key` header (1–128 characters) to retry a submit safely: the same key and body return the same task instead of starting a new one.

## The task object

```json
{
  "id": "video_01JD3Z8M2K7Q9R4T6V8X0Y2B4C",
  "object": "video",
  "model": "<video model id>",
  "status": "completed",
  "progress": 100,
  "created_at": 1763452800,
  "completed_at": 1763452950,
  "expires_at": 1763539350,
  "seconds": "5",
  "size": "1280x720",
  "error": null
}
```

Times are Unix seconds. `expires_at` is set once the task completes: you can download for 24 hours, or less when the upstream keeps files for a shorter time (12 hours on some models). Always read `expires_at` rather than assuming 24 hours.

Videos are visible to keys in the same workspace: any key there can retrieve and download a task by its id. Tasks from another workspace in the same organization, such as Sandbox and Prod, return `404`. `GET /v1/videos` is narrower: it lists only the tasks submitted by the key's owner, with any of their keys, newest first, with `offset` and `limit`. Teammates' tasks don't appear in the list.

## Cancelling

`DELETE /v1/videos/{id}` cancels a task that is still waiting in the upstream queue. The reservation is refunded in full and the status becomes `cancelled`. A task that has started generating can't be cancelled; it finishes and is billed as usual. Today only Seedance models support cancelling. Cancelling the same task twice returns the same result. Only the person who submitted a task can cancel it, with any of their keys; a teammate's key gets `409` with `reason` `not_owner`.

## Pricing

Video models are priced per resolution, in one of three units. Each model page shows the unit and the price for every resolution.

| Unit | You pay |
|---|---|
| Per second | Output seconds × the price for that resolution |
| Per 1M video tokens | Video tokens the upstream reports × price / 1M. The model page shows an approximate per-second price for comparison. |
| Per video | The price per video |

When you submit, we reserve the maximum the request can cost, so a submit fails with `402` if your balance, API key limit or budget can't cover it. See [Errors](#errors) for which code you get. When the task finishes, you're charged the actual amount and the rest is returned. Per-token prices are estimates until the upstream reports usage, so the final charge can be slightly higher than the reservation.

### What you pay when a task doesn't complete

| Outcome | Charge |
|---|---|
| Completed | The actual amount |
| Failed, or blocked by content moderation | Refunded in full |
| Failed, but the upstream still billed the generation | Charged for what the upstream reported |
| Cancelled while queued | Refunded in full |
| Timed out while still queued | Refunded in full |
| We can't confirm the outcome with the upstream | Refunded in full. Occasionally we review it by hand first (shown as Under review in Usage); you are charged only if the upstream confirms it billed the generation |

Occasionally an upstream queue is slow and a task stays `in_progress` well past the usual time. It still completes, can be downloaded, and is billed as normal.

## Errors

Submitting, downloading and cancelling return standard [error responses](/docs/errors):

| Code | Status | Meaning |
|---|---|---|
| `content_policy_violation` | 400 | The prompt or an input image was blocked by content moderation. |
| `content_policy_limit_exceeded` | 403 | Too many moderation blocks recently. Video submits are paused; see [Moderation limit](#moderation-limit). |
| `unsupported_video_option` | 400 | The duration, size or resolution isn't supported, or image input isn't available on this model. The message says which. |
| `invalid_request_error` | 400 | The request is malformed: `model` or `prompt` is missing or empty, the body isn't a JSON object or multipart form, the `Idempotency-Key` isn't 1–128 characters, or the `after` id on the list call isn't one of the tasks that list returns. |
| `unsupported_parameter` | 400 | The request has a field this endpoint doesn't accept. |
| `model_endpoint_mismatch` | 400 | The model can't generate video. |
| `insufficient_quota` | 402 | Your balance or the API key's spending limit can't cover the reservation. |
| `period_quota_exceeded` | 402 | A daily, weekly or monthly [budget](/docs/budgets) can't cover the reservation. The error also carries `period`, `limit`, `used`, `resets_at` and `target_type`; see [Spend-limit errors](/docs/errors#spend-limit-errors). |
| `upstream_error` | The upstream's own status, for example 400 | The model's provider rejected the submit, for example a length outside what a Seedance version supports. Nothing is charged. |
| `rate_limit_exceeded` | 429 | Over the request limit; see [Rate limit](#rate-limit). |
| `idempotency_key_conflict` | 409 | The `Idempotency-Key` was already used for a different request, or in another workspace. |
| `video_not_found` | 404 | No task with this id in this key's workspace. |
| `video_not_ready` | 409 | The task hasn't completed, so there's nothing to download. |
| `video_expired` | 410 | The download window has passed. |
| `video_not_cancellable` | 409 | The task can't be cancelled. `reason` is `finished`, `generating`, `unsupported`, `busy` (retry in a few seconds), or `not_owner` (a teammate submitted it). |

A task that fails returns `200` with `error.code` set on the task object:

| `error.code` | Status | Meaning |
|---|---|---|
| `submit_failed` | `failed` | The submit was rejected on every route. The submit request already returned an error, and you are not charged. The task still shows in `GET /v1/videos` and `GET /v1/videos/{id}`. |
| `generation_failed` | `failed` | The upstream failed to generate the video. This includes an input image the upstream couldn't use. |
| `content_policy_violation` | `failed` | The prompt or an input image was blocked at submit, or the generated video was blocked. |
| `cancelled` | `cancelled` or `failed` | You cancelled the task (`cancelled`), or the upstream cancelled it (`failed`). |
| `timeout` | `failed` or `expired` | The task didn't finish in time. `failed` when the upstream ended it for taking too long. `expired` when we stopped waiting for it. |
| `upstream_task_lost` | `expired` | The upstream no longer has the task. |
| `submit_unconfirmed` | `expired` | We couldn't confirm the task with the upstream. |

Failed tasks are not resubmitted automatically, since that could bill you twice. Submit again if you want another attempt.

## Moderation limit

When content moderation blocks a video — the prompt or input images at submit, or the generated video — it counts against the person who owns the API key. By default, after 5 blocks within 24 hours, video submits are refused with `403 content_policy_limit_exceeded`:

- The limit is per key owner, not per key. It covers every API key that person owns, in every workspace and organization.
- Submits work again once the oldest of those blocks is more than 24 hours old.
- If you pass your own users' prompts through, have keys for different products owned by different people, so one user's blocked prompts can't pause everything.

## Rate limit

Video submits are limited to 60 per minute per API key owner, and image requests share that limit. The count is the same one that applies to chat and the other endpoints (600 per minute): every request from every key the person owns counts toward it, whatever the endpoint. Once the total passes 60 in a minute, video and image requests get `429 rate_limit_exceeded` while chat and the other endpoints keep working up to 600. Polling and downloading a task don't count.
