# MAGI-2 — /videos/generations

MAGI-2 is Sand AI’s flagship video model. Submit an async job with `POST /v1/videos/generations`: no references for text-to-video, or up to 10 reference images, 3 reference videos and 3 reference audio clips together. 1080P only, 4-12 seconds, 6 aspect ratios, always with sound. Billed per second of output; references are free.

**Endpoint:** `POST https://kovapi.com/v1/videos/generations`

## Quick start

Three steps: submit a job, poll it, take the video link. Replace YOUR_API_KEY with your key and the commands below run as they are.

**Step 1 · Submit (returns a job id at once, HTTP 202)**

```
curl https://kovapi.com/v1/videos/generations \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"model": "magi-2", "prompt": "A tiny ramen stall at night in steady rain. An old chef looks up at the camera, smiles and says warmly: Last bowl of the night, it is on the house. Handheld close-up, warm lantern light", "duration": 5, "resolution": "1080P", "size": "16:9"}'
```

Response (HTTP 202)

```
{
  "id": "img_7d3a9c2e5b1f4a8d6c0e2b9f",
  "object": "video.generation.job",
  "status": "queued",
  "created": 1795782000,
  "model": "magi-2"
}
```

**Step 2 · Poll every 5–10 seconds until `status` is `succeeded` or `failed`**

```
curl https://kovapi.com/v1/videos/jobs/img_7d3a9c2e5b1f4a8d6c0e2b9f \
  -H "Authorization: Bearer YOUR_API_KEY"
```

Response when it succeeds

```
{
  "id": "img_7d3a9c2e5b1f4a8d6c0e2b9f",
  "object": "video.generation.job",
  "status": "succeeded",
  "created": 1795782000,
  "model": "magi-2",
  "data": [
    {"url": "https://img.kovapi.com/i/3e9b1c7a5d2f48e0b6a4c1d8f2e7a9b3.mp4"}
  ],
  "usage": {"clips": 1, "model": "magi-2"}
}
```

**Step 3 · `data[0].url` is the clip (MP4). It is kept for 7 days; download it to your own storage to keep it longer.**

**Complete example (Python: submit, wait, save to disk)**

```
import time
import requests

BASE = "https://kovapi.com/v1"
HEADERS = {"Authorization": "Bearer YOUR_API_KEY"}

# 1. submit
job = requests.post(f"{BASE}/videos/generations", headers=HEADERS, json={
    "model": "magi-2",
    "prompt": "A tiny ramen stall at night in steady rain. An old chef looks up at the camera, smiles and says warmly: Last bowl of the night, it is on the house. Handheld close-up, warm lantern light",
    "duration": 5,
    "resolution": "1080P",
    "size": "16:9",
}).json()
if "error" in job:
    raise SystemExit(job["error"]["message"])

# 2. poll every 10 seconds, for up to an hour
deadline = time.time() + 3600
while job["status"] not in ("succeeded", "failed") and time.time() < deadline:
    time.sleep(10)
    job = requests.get(f"{BASE}/videos/jobs/{job['id']}", headers=HEADERS).json()

# 3. download the video
if job["status"] == "succeeded":
    url = job["data"][0]["url"]
    with open("magi-2.mp4", "wb") as f:
        f.write(requests.get(url).content)
    print("saved", url)
elif job["status"] == "failed":
    print("failed:", job["error"]["code"], job["error"]["message"])
else:
    print("still", job["status"], job["id"])
```

While queued, the poll also returns `queue_position` (jobs ahead of yours) and `eta_seconds` (expected wait). If your time limit passes, do not resubmit: the job is still there, so keep polling the same id later.

## Authentication
```
Authorization: Bearer YOUR_API_KEY
Content-Type: application/json
```

## At a glance

| Duration | 4-12 s in one-second steps (default 5 s) |
| --- | --- |
| Resolution | 1080P |
| Aspect ratio | 21:9 / 16:9 / 4:3 / 1:1 / 3:4 / 9:16 |
| Reference images | up to 10 · all used as references (ask in the prompt to open on one), no first / last frame parameter |
| Reference videos | up to 3 · each at least 2 s, 30 s in all · not billed |
| Reference audio | up to 3 · each at least 2 s, 30 s in all, with a reference image or video · not billed |
| Sound | always on (dialogue, effects or music), cannot be switched off (`audio: false` is refused) |
| Prompt length | up to 15,000 characters (Chinese and English count the same) |
| Billing | per second: output seconds x the per-second rate; references are not billed |

## Request parameters

The JSON body of `POST /v1/videos/generations`:

| Parameter | Type | Required | Description |
| --- | --- | --- | --- |
| model | string | Yes | The model id: `magi-2`. |
| prompt | string | Yes | What happens, the camera, the action and the sound, up to 15,000 characters (Chinese and English count the same). Put what is said in quotes; timed shots work, e.g. "0-6 seconds: wide shot … 6-12 seconds: close-up …". Name references as @Image1 / @Video1 / @Audio1. |
| duration | integer | No | Output length, an integer 4-12, default 5; alias `seconds`. Billed per second of output. |
| resolution | string | No | `1080P` only (also the default); you may leave it out. |
| size | string | No | Aspect ratio: 21:9 / 16:9 / 4:3 / 1:1 / 3:4 / 9:16 (default 16:9); alias `aspect_ratio`. Other ratios are refused (400). |
| images | array | No | Up to 10 reference images (public links, `data:` URIs or base64, each up to 16 MB); alias `reference_images`. All are references; `start_frame`, `end_frame` and `image_role=first_frame` are refused. Over the cap is refused, never truncated. |
| video_references | array | No | Up to 3 reference videos (mp4 / mov, each at least 2 s and up to 50 MB, 30 s in all): direct download links, base64 (`data:video/mp4;base64,...`) or links from a Playground upload. They combine with reference images. Not billed. |
| audio_reference | array | No | Up to 3 reference audio clips (mp3 / wav / m4a, each at least 2 s, 30 s in all), e.g. for a character’s voice; send a reference image or video as well. Alias `audio_references` (not both). Not billed. |
| audio | boolean | No | Every clip has sound (dialogue, effects or music) and it cannot be switched off; `false` is refused (400), so leave it out. |
| callback_url | string | No | Where to push the result when the job ends; see Webhooks below. |
| n | integer | No | Each job makes one clip; leave it out. A value above 1 still makes one clip, but n clips are held at submit and the extra is returned when the job ends. |

Other fields (`seed`, `negative_prompt`, `fps`, `watermark` and the like) are not passed on and do not change the price; results are always MP4, returned as a `url`.

## Price

Billed per second: cost = the per-second rate x the output seconds (the length you ask for). Reference images, videos and audio are free. The amount is held at submit, settled at the same figure on success and refunded in full on failure. 1 credit = $0.005.

| Resolution | Credits / s | USD / s | A 5-second clip | 12 s video |
| --- | --- | --- | --- | --- |
| 1080P | 12 | $0.06 | $0.30 | $0.72 |

## Reference material

- **Reference images** are references. Say in the prompt what each one is for by its number, e.g. "the character in @Image1"; to open on an image, write "use @Image1 as the opening frame" (in our tests the reference image became the opening frame almost unchanged).

- **Reference videos** set camera moves, framing and motion, and combine with reference images. Each at least 2 s, 30 s in all.

- **Reference audio** sets, for example, a character’s voice: each clip at least 2 s, 30 s in all, with a reference image or video as well. Write what is said in the prompt, in quotes.

- **Shot lists**: write timed shots in the prompt, e.g. "0-6 seconds: wide shot … 6-12 seconds: close-up …".

- Each image is a public image URL, a `data:` URI or base64, up to 16 MB; send several as an array in `images`. We store the images before the job is queued; one that cannot be read is refused with 400, `message` says which, and nothing is charged.

- Reference files we store and the results are both kept for 7 days.

**With a reference video and reference audio**

```
curl https://kovapi.com/v1/videos/generations \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"model": "magi-2", "prompt": "Follow the camera movement and the motion of the star character in @Video1 exactly. Turn the scene into a real child bedroom in warm afternoon light; the yellow star becomes a plush toy that speaks with the voice of @Audio1: Last bowl of the night, it is on the house.", "video_references": ["https://example.com/camera-6s.mp4"], "audio_reference": ["https://example.com/voice-5s.mp3"], "duration": 5, "resolution": "1080P", "size": "16:9"}'
```

This job outputs 5 s, so 5 seconds are billed; the reference video and audio are free.

## Job status and fields

`GET /v1/videos/jobs/{id}` reports these statuses; every field is described in [Async jobs](https://docs.kovapi.com/guide/async-jobs#fields). Poll every 5–10 seconds, or let a webhook (below) push the result. Polling is free, and any key of the same account can read the job.

| Status | Meaning |
| --- | --- |
| queued | Waiting in line. Carries `queue_position` (jobs ahead of yours) and `eta_seconds` (expected wait). |
| processing | Rendering. |
| succeeded | Done. The result is in `data[0].url`, the billing detail in `usage`. |
| failed | Failed. The reason is in `error`; the credits held for the job are refunded in full. |

- `processing` can go back to `queued`, for example while the service is busy, while a finished clip is fetched again, or after a restart. If a job cannot be finished, the gateway may render it again automatically; however many retries it takes, a job is charged once.

- One account runs up to 50 jobs at a time; further jobs wait in submission order, and a job that has not started after 15 minutes fails and is refunded in full. Job records are kept for 3 days and video links for 7 days.

## How long it takes

Our tests (1080P, 5-25 s) usually rendered in 4-10 minutes, longer with a reference video. We wait up to 120 minutes and refund in full on a timeout.

Real calls over the last 7 days: median 4.5 min, 90% done within 8 min.

## Errors and refunds

An error at submit comes back at once as HTTP 4xx / 5xx: no job is created and nothing is charged. A failure after the job was accepted is reported by the job endpoint, and the hold is refunded in full. Every code is listed under [Error codes](https://docs.kovapi.com/guide/errors).

### Errors at submit

| HTTP | code | Cause | What to do |
| --- | --- | --- | --- |
| 400 | invalid_request | A parameter is not valid: the duration, resolution, ratio or number of references is outside this model's range, the prompt is too long, a reference image or video cannot be read, `audio: false` was sent to a model whose clips always have sound, and so on. `message` says which. | Fix what `message` says and submit again. |
| 400 | invalid_callback_url | `callback_url` is not a public http(s) address, or is longer than 2000 characters. | Use an address that can be reached from the internet. |
| 400 | model_not_found | The model id is misspelled, `model` is missing, or the model cannot be used on this endpoint (a chat model on the image endpoint, for example). | Use a model id from `GET /v1/models` or the [API reference](https://docs.kovapi.com/api). |
| 401 | invalid_api_key | The key does not exist, was deleted or is disabled, or the account is disabled. | Check the key on the API Keys page of the console. |
| 402 | insufficient_quota | Not enough balance to hold this request. The gateway holds the highest possible cost of the request first, so a burst of concurrent calls can trigger it too. | After a burst, wait a few seconds and retry; otherwise top up. |
| 429 | rate_limit_exceeded | Over the requests-per-minute limit set on this key (counted over the last 60 seconds). No `Retry-After` header. | Wait a few seconds and retry, or raise the key's limit in the console. |
| 503 | model_maintenance | The model is under maintenance and takes no requests; no other model answers in its place meanwhile. | Retry when maintenance ends; see [Status](https://kovapi.com/status). |
| 503 | service_unavailable | A temporary failure on our side, such as storing a reference file. No job was created and nothing was charged. | Retry shortly. |

### Failed jobs (`status` `failed`)

| code | When you see it | What to do |
| --- | --- | --- |
| content_policy | Video: the prompt, a reference, or the generated picture or sound did not pass content review (`param` is `audio` when the sound was flagged). Wan Standard and Prime: input material did not pass review. `error.reason` is `FaceDetectionSuspect` (possible real human face) or `DataInspectionFailed` (input content review failed). `error.message` explains the cause and recommended change. Failed tasks are not billed. | Rewrite the prompt or replace the reference before you submit again; the same input is refused again. |
| invalid_reference | A reference was not accepted: a reference video or audio clip is too short (each at least 2 s), the total is over the cap, or the file could not be read. | Trim reference videos / audio to 2 s or longer and within the total, use direct mp4 / mp3 links, then resubmit; unchanged it fails again. |
| render_failed | Video: no clip came out this time, usually a one-off. | Submitting the same request again usually works. |
| render_timeout | Video: queueing or rendering took too long and the upstream gave the job up. | Submit again. |
| result_fetch_failed | The video was rendered, but downloading or storing it kept failing on our side. | Submit again. |
| upstream_error | Any other failure: the automatic retries did not help, the job waited 15 minutes without starting, the upstream refused without a reason, and so on; `message` says which. | Submitting again usually works. |

Branch on `code`, not on the text of `message`. Treat any `code` you do not recognise (or a missing one) as `upstream_error`: resubmitting usually works. Every failed job is refunded in full.

## Webhooks instead of polling

Add `callback_url` when you submit and the moment the job ends, success or failure, the gateway pushes exactly what the poll endpoint returns to that URL, signed and retried on failure. You can also set an account-wide address under Settings → Webhook in the console. [Webhook docs →](https://docs.kovapi.com/webhooks)

```
curl https://kovapi.com/v1/videos/generations \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"model": "magi-2", "prompt": "A tiny ramen stall at night in steady rain. An old chef looks up at the camera, smiles and says warmly: Last bowl of the night, it is on the house. Handheld close-up, warm lantern light", "duration": 5, "resolution": "1080P", "size": "16:9", "callback_url": "https://your-domain.com/webhook"}'
```
