# MAGI-2 Video Generation

Create MAGI-2 (Sand AI) `1080p` videos with audio using `magi-2`. Pass reference images, reference videos, and reference audio via `ref`.

> A model is callable only when it appears in `GET /v1/models` for your current API key. A successful creation response, task ID, or in-progress status does not mean a deliverable video has been obtained.

## Endpoints & Authentication

```http
POST https://vip.brioi.com/v1/videos
GET  https://vip.brioi.com/v1/videos/{task_id}
Authorization: Bearer YOUR_API_KEY
Content-Type: application/json
```

## Request Parameters

| Parameter | Type | Required | Default | Description |
|---|---|---:|---|---|
| `model` | string | Yes | — | Must be `magi-2`. |
| `prompt` | string | Yes | — | Non-empty video description, up to 20,000 characters. Reference input assets with the literal model tags `@图片1`, `@视频1`, `@音频1`, etc. |
| `ref` | object[] | Yes | — | Reference assets (at least 1 item required); see `ref` items below. |
| `duration` | integer | No | `5` | Output duration in integer seconds (`4–30`). |
| `aspect_ratio` | string | No | `16:9` | Supports `16:9`, `9:16`, `21:9`, `4:3`, `1:1`, `3:4`. |
| `resolution` | string | No | `1080p` | Only `1080p` is supported. |

### `ref` Items

Each item passes `type` and `url`. Every URL must be a publicly accessible HTTPS address readable throughout task execution without login, cookies, or custom request headers.

| Field | Required | Description |
|---|---:|---|
| `type` | Yes | `image`, `video`, or `audio`. |
| `url` | Yes | Asset URL. |

| Modality | Max Count | Description |
|---|---|---|
| Image | 10 images | Reference for characters, objects, scenes, or visual style. |
| Video | 3 clips | Reference for motion, camera movement, or pacing. |
| Audio | 5 clips | Reference for voice or soundtrack; max 15 seconds combined across reference audio clips (MP3 or WAV recommended). |

- All three modalities can be used individually or together, provided `ref` contains at least 1 item.
- Assets are numbered separately per modality starting from 1 according to their order in `ref`: the first image is `@图片1`, the first video is `@视频1`, and the first audio clip is `@音频1` (note: `@图片1`, `@视频1`, and `@音频1` are literal Chinese model syntax tags—keep them unchanged in prompts).
- Strict first and last frames (`role=first_frame` / `last_frame`) are not supported.

## Examples

### 3 Reference Images, Landscape 10s

```bash
curl --request POST 'https://vip.brioi.com/v1/videos' \
  --header 'Authorization: Bearer YOUR_API_KEY' \
  --header 'Content-Type: application/json' \
  --data '{
    "model": "magi-2",
    "prompt": "The three characters in @图片1, @图片2, and @图片3 walk side by side down a rainy neon-lit street as the camera slowly tracks them, then turn back together to look at the camera",
    "duration": 10,
    "aspect_ratio": "16:9",
    "ref": [
      { "type": "image", "url": "https://example.com/person-1.png" },
      { "type": "image", "url": "https://example.com/person-2.png" },
      { "type": "image", "url": "https://example.com/person-3.png" }
    ]
  }'
```

### Image + Reference Video + Reference Audio, Portrait 15s

```json
{
  "model": "magi-2",
  "prompt": "The character in @图片1 dances following the choreography in @视频1, with soundtrack matching @音频1",
  "duration": 15,
  "aspect_ratio": "9:16",
  "ref": [
    { "type": "image", "url": "https://example.com/dancer.png" },
    { "type": "video", "url": "https://example.com/dance-motion.mp4" },
    { "type": "audio", "url": "https://example.com/music.mp3" }
  ]
}
```

## Billing

Billed per second based on the requested `duration` (defaulting to `5` seconds when omitted). Requests that include a reference video (`type=video`) in `ref` are billed at 2× the per-second rate of requests without reference video; reference images and reference audio do not affect pricing. Refer to the Model Marketplace for per-second rates.

## Asynchronous Responses

Save `id` from the creation response and poll the same task via `GET /v1/videos/{task_id}`. Generation typically takes 5–15 minutes; poll every 15–30 seconds. Public statuses:

| Status | Action |
|---|---|
| `queued` | Queued; continue polling. |
| `in_progress` | Generating; continue polling. |
| `completed` | Read `metadata.url`. |
| `failed` | Read `error` and stop polling. |

Treat any status value not listed above as incomplete and continue polling. A deliverable video is obtained only when `status=completed` and `metadata.url` is non-empty and downloadable (`result_url` holds the same value as a fallback). Result URLs expire—download or persist the video immediately upon completion. If a creation request times out or returns a transient `5xx`, verify whether the task was already created before submitting a second task.

## Unsupported Parameters

The following are not currently exposed: resolutions other than `1080p`, durations under 4 seconds or over 30 seconds, pure text-to-video (without reference assets), strict first and last frames, and Chat Completions parameters (`messages`, `temperature`, `top_p`, `stream`).

## Error Handling

| HTTP Status | Common Cause |
|---:|---|
| `400` | Invalid parameters; querying a non-existent task also returns `400` with `code` set to `task_not_exist` |
| `401` | Missing or invalid API key |
| `403` | Insufficient balance/quota, or no permission for the requested model |
| `429` | Rate limit exceeded |
| `503` | Service temporarily unavailable |
| `500` / `502` | Transient service error |

