# WAN Video Generation

OpenAI compatible: `POST /v1/video/generations`. Native path: `/api/v1/services/aigc/video-generation/video-synthesis`. [Video Generation API](https://help.aliyun.com/zh/model-studio/wan3-video-generation-api-reference?spm=a2c4g.11186623.help-menu-2400256.d_2_3_1_0.204b56c3vDOeBa&scm=20140722.H_3049634._.OR_help-T_cn~zh-V_1)

- Submit: `POST /v1/video/generations`
- Poll: `GET /v1/video/generations/{task_id}` or `GET /v1/tasks/{task_id}`

> **Mutually Exclusive Modes**: Start/end frames (`first_frame` / `last_frame`) and reference assets (`reference_*`, `file`, `link`) cannot be mixed.

---

## 1. OpenAI-Compatible Integration (POST)

* **Path**: `https://www.tokenpad.ai/v1/video/generations`
* **Auth**: `Authorization: Bearer sk-your_token`

### A. Text-to-Video

```bash
curl -X POST https://www.tokenpad.ai/v1/video/generations \
  -H "Authorization: Bearer sk-your_token_here" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "wan3.0-video",
    "prompt": "A golden retriever running through golden autumn leaves, cinematic slow motion, sunlight filtering through the woods",
    "resolution": "1080P",
    "ratio": "16:9",
    "duration": 5
  }'
```

### B. Image-to-Video (First Frame / Start & End Frames)

1 image -> first frame; 2 images -> start & end frames. You can also specify `{ "url", "role" }` explicitly (`role` can be written as `type`).

```bash
curl -X POST https://www.tokenpad.ai/v1/video/generations \
  -H "Authorization: Bearer sk-your_token_here" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "wan3.0-video",
    "prompt": "Camera slowly pushes in as the subject naturally turns around, consistent lighting and shadows",
    "images": [
      { "url": "https://example.com/first.png", "role": "first_frame" },
      { "url": "https://example.com/last.png", "role": "last_frame" }
    ],
    "resolution": "720P",
    "duration": 5
  }'
```

### C. Multi-Image Reference Video Generation

```bash
curl -X POST https://www.tokenpad.ai/v1/video/generations \
  -H "Authorization: Bearer sk-your_token_here" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "wan3.0-video",
    "prompt": "Use the character appearance from image 1 and street scene from image 2, smooth tracking shot, character walking naturally",
    "images": [
      { "url": "https://example.com/character.png", "role": "reference_image" },
      { "url": "https://example.com/street.png", "role": "reference_image" }
    ],
    "resolution": "1080P",
    "ratio": "16:9",
    "duration": 5
  }'
```

### D. Image + Video + Audio Multimodal Reference

Requires at least one reference image or reference video; **audio-only is not supported**.

```bash
curl -X POST https://www.tokenpad.ai/v1/video/generations \
  -H "Authorization: Bearer sk-your_token_here" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "wan3.0-video",
    "prompt": "Character movements follow the reference video with lip-sync matching the reference audio",
    "images": [
      { "url": "https://example.com/character.png", "role": "reference_image" }
    ],
    "videos": ["https://example.com/motion_ref.mp4"],
    "audios": ["https://example.com/voice_ref.mp3"],
    "resolution": "1080P",
    "duration": 5
  }'
```

### E. File / Webpage Link Reference

`files` and `links` are OpenAI flat extension fields; mapped by default to `file` and `link` roles.

```bash
curl -X POST https://www.tokenpad.ai/v1/video/generations \
  -H "Authorization: Bearer sk-your_token_here" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "wan3.0-video",
    "prompt": "Generate an explainer video based on the reference document and product page content",
    "files": ["https://example.com/brief.pdf"],
    "links": ["https://example.com/product-page"],
    "resolution": "1080P",
    "ratio": "16:9",
    "duration": 5
  }'
```

---

## 2. Polling Result (GET)

```bash
curl -X GET https://www.tokenpad.ai/v1/video/generations/video_task_001 \
  -H "Authorization: Bearer sk-your_token_here"
```

---

## 3. OpenAI-Compatible Parameter Dictionary

| Param | Type | Required | Description |
| :--- | :--- | :---: | :--- |
| `model` | `string` | Yes | e.g., `wan3.0-video` |
| `prompt` | `string` | Yes | Text description |
| `images` / `image_urls` | `array` | No | See "Media Formats" and the role table below |
| `videos` | `array` | No | Reference videos; default role `reference_video` |
| `audios` | `array` | No | Reference audio; default role `reference_audio`; cannot be used as the sole reference |
| `files` | `array` | No | Reference file URLs; default role `file` |
| `links` | `array` | No | Reference webpage URLs; default role `link` |
| `resolution` / `size` | `string` | No | e.g., `720P`, `1080P` (`size` is converted to uppercase) |
| `ratio` | `string` | No | `16:9`, `9:16`, `1:1`, etc. |
| `duration` | `integer` | No | Seconds, default `5` |

**Media Formats** (applies to `images` / `videos` / `audios` / `files` / `links`):

- Plain URL string: `"https://..."`
- Object with role: `{ "url": "https://...", "role": "reference_image" }` (`role` can be written as `type`)

**Default `images` Role by Count** (when not explicitly specified):

| Count | Default role |
| :--- | :--- |
| 1 | `first_frame` |
| 2 | `first_frame` + `last_frame` |
| 3+ | All `reference_image` |

**All `role` Values**:

| role | Source Field | Description |
| :--- | :--- | :--- |
| `first_frame` | `images` / `image_urls` | First frame |
| `last_frame` | `images` / `image_urls` | Last frame |
| `reference_image` | `images` / `image_urls` | Reference image |
| `reference_video` | `videos` | Reference video (Wan default) |
| `reference_audio` | `audios` | Reference audio |
| `file` | `files` | Reference file |
| `link` | `links` | Reference webpage |

---

## 4. Alibaba Bailian Native Routes (Brief)

| Capability | Path |
| :--- | :--- |
| Video submit | `POST /api/v1/services/aigc/video-generation/video-synthesis` |
| Task query | `GET /api/v1/tasks/{task_id}` |

Payloads already containing the official `input` / `parameters` structure are passed through verbatim; async tasks require `X-DashScope-Async: enable`.

---

## 5. Response Examples

**Submit**:

```json
{
  "id": "video_task_001",
  "task_id": "video_task_001",
  "status": "pending"
}
```

**Completed**:

```json
{
  "id": "video_task_001",
  "status": "completed",
  "data": [{ "url": "https://example.com/output/wan_video.mp4" }]
}
```

Async polling may return `"status": "failed"` even with HTTP 200; see [Gateway Error Codes & Troubleshooting](/docs/errors/error-codes).



### 5. Common Error Codes & Troubleshooting

HTTP codes, error body format, and troubleshooting are **maintained in one dedicated page** (not duplicated under each example).

👉 **[Gateway Error Codes & Troubleshooting](/docs/errors/error-codes)**

**Quick reference**:

| Code | Meaning |
| :---: | :--- |
| **400** | Invalid parameters / content moderation or copyright block |
| **402** | Insufficient account balance (**not** 429) |
| **429** | RPS/RPM limits or in-flight task cap (low balance) |
| **403** | Token / IP / model permission (balance → 402; content filter → 400) |
| **200 + `status: failed`** | Async video/long-task business failure on poll |

HTTP status matches call log `status_code` for traceability by `log_id`.

> **Maintenance**: update the `error-codes` article only; this appendix links to it.
