# Vidu Q4 Preview 视频生成 API 对接文档

## 概述

Vidu Q4 Preview 支持图生视频(i2v)与参考生视频(r2v)，视频时长 3-16 秒，分辨率最高 4K，可生成带音效的视频。

> 文生视频(t2v)暂不支持，请使用图生视频或参考生视频。

**Base URL**: `https://mm-internal-cn.leonecloud.com`

---

## 认证方式

```
Authorization: Bearer {YOUR_AUTH_TOKEN}
```

## 快速开始

**创建图生视频任务**
```bash
curl -X POST "https://mm-internal-cn.leonecloud.com/api/v2/open/aigc/vidu-q4-preview" \
  -H "Authorization: Bearer your_auth_token_here" \
  -H "Content-Type: application/json" \
  -d '{
    "prompt": "让图片中的人物缓缓转头微笑",
    "genType": "i2v",
    "imageUrls": ["https://example.com/reference.jpg"],
    "resolution": "720p",
    "duration": 5
  }'
```

**创建参考生视频任务**
```bash
curl -X POST "https://mm-internal-cn.leonecloud.com/api/v2/open/aigc/vidu-q4-preview" \
  -H "Authorization: Bearer your_auth_token_here" \
  -H "Content-Type: application/json" \
  -d '{
    "prompt": "画面中的角色在樱花树下并肩走过，镜头缓慢跟随",
    "genType": "r2v",
    "imageUrls": [
      "https://example.com/character.jpg",
      "https://example.com/scene.jpg"
    ],
    "resolution": "1080p",
    "aspectRatio": "16:9",
    "duration": 8
  }'
```

**查询任务状态**
```bash
curl -X GET "https://mm-internal-cn.leonecloud.com/api/v2/open/aigc/task_abc123" \
  -H "Authorization: Bearer your_auth_token_here"
```

---

## 创建任务

**POST** `/api/v2/open/aigc/vidu-q4-preview`

**Content-Type**: `application/json`

### 请求参数

| 参数 | 类型 | 必填 | 说明 |
|-----|------|-----|------|
| genType | string | 否 | 生成类型：`i2v` 图生视频 / `r2v` 参考生视频。不传时按素材自动判定（多于 1 张图或带 sounds 按 r2v；否则按 i2v）。`t2v` 文生视频暂不支持 |
| prompt | string | 条件 | 提示词，最多 20000 字符。`r2v` 必填，`i2v` 可选 |
| imageUrls | string[] | 是 | 图片素材。`i2v` 恰好 1 张；`r2v` 1-15 张 |
| sounds | string[] | 否 | 参考音频，仅 `r2v` 支持，最多 3 段，每段时长 3-12 秒 |
| resolution | string | 否 | 分辨率：`540p` / `720p`(默认) / `1080p` / `2K` / `4K` |
| duration | int | 否 | 视频时长(秒)，默认 5，范围 3-16 |
| aspectRatio | string | 否 | 宽高比，仅 `r2v` 支持：`16:9`(默认) / `9:16` / `1:1` / `4:3` / `3:4` |
| audio | bool | 否 | 是否同时生成音频，不传按服务默认值 |
| isRec | bool | 否 | 是否对提示词做智能改写，仅 `i2v` 支持，不传按服务默认值 |
| seed | int | 否 | 随机种子，取值 `[0, 2147483647]`。不传或传 0 表示随机 |
| watermark | bool | 否 | 是否添加水印，不传按服务默认值 |
| wmPosition | int | 否 | 水印位置：`1` 左上 / `2` 右上 / `3` 右下 / `4` 左下 |
| wmUrl | string | 否 | 自定义水印图片 URL |
| payload | string | 否 | 透传字段，最多 1048576 字符，原样回显 |
| taskNickname | string | 否 | 任务昵称，便于在任务列表中识别 |
| callbackUrl | string | 否 | 任务完成后的回调通知URL |

### 支持的 genType

| genType | 说明 | imageUrls 要求 | prompt | 可用参数 |
|---------|------|---------------|--------|---------|
| i2v | 图生视频 | 恰好 1 张 | 可选 | `isRec` |
| r2v | 参考生视频 | 1-15 张 | 必填 | `sounds`、`aspectRatio` |

> **注意**：两种类型的参数互斥，传错会直接返回参数错误而不会被静默忽略：
> - `i2v` 不接受 `sounds` 与 `aspectRatio`，且 `imageUrls` 只能 1 张；
> - `r2v` 不接受 `isRec`。
>
> 传 `genType=t2v` 或不带任何 `imageUrls` 会返回参数错误（文生视频暂不支持），任务不会创建、不会产生费用。
>
> `resolution` 直接决定计费单价，传入不在白名单内的值会返回参数错误，不会自动回落到默认档。

### 请求示例

**图生视频（540p / 3 秒）：**
```json
{
  "prompt": "镜头缓慢推进，人物睁开眼睛",
  "genType": "i2v",
  "imageUrls": ["https://example.com/portrait.jpg"],
  "resolution": "540p",
  "duration": 3,
  "isRec": true
}
```

**参考生视频（带参考音频）：**
```json
{
  "prompt": "两位角色在雨中对话，氛围安静",
  "genType": "r2v",
  "imageUrls": [
    "https://example.com/char-a.jpg",
    "https://example.com/char-b.jpg",
    "https://example.com/street.jpg"
  ],
  "sounds": ["https://example.com/rain.mp3"],
  "resolution": "1080p",
  "aspectRatio": "9:16",
  "duration": 8,
  "audio": true
}
```

**4K 高分辨率：**
```json
{
  "prompt": "航拍雪山，云海翻涌",
  "genType": "i2v",
  "imageUrls": ["https://example.com/mountain.jpg"],
  "resolution": "4K",
  "duration": 5
}
```

### 响应示例

```json
{
  "code": 0,
  "msg": "success",
  "data": {
    "taskId": "task_20260507103000_abc12345",
    "status": "processing",
    "createdAt": "2026-05-07 10:30:00"
  }
}
```

---

## 计费说明

按「分辨率档单价 × 视频时长(秒)」计费，时长以请求中的 `duration` 为准。

任务创建时按上述金额预冻结，**仅在生成成功时扣费**；生成失败全额解冻退回。

---

## 查询任务状态

**GET** `/api/v2/open/aigc/{taskId}`

### 响应参数

| 参数 | 类型 | 说明 |
|-----|------|------|
| code | int | 状态码，0 表示成功 |
| msg | string | 状态信息 |
| data.taskId | string | 任务 ID |
| data.status | string | `processing` / `success` / `failed` |
| data.result | string[] | 生成的视频 URL 列表（成功时返回） |
| data.errorMsg | string | 错误信息（失败时返回） |
| data.createdAt | string | 创建时间 |
| data.updatedAt | string | 更新时间 |

> **结果链接有效期 24 小时**：`data.result` 中的视频链接为限时直链，自生成后 24 小时失效，超时后访问会返回鉴权错误。请在获取链接后尽快下载并转存至自有永久存储。

### 响应示例

```json
{
  "code": 0,
  "msg": "success",
  "data": {
    "taskId": "task_20260507103000_abc12345",
    "status": "success",
    "result": [
      "https://example-video-store.s3.amazonaws.com/tasks/2026/05/07/video.mp4?X-Amz-Expires=86400&X-Amz-Signature=xxx"
    ],
    "createdAt": "2026-05-07 10:30:00",
    "updatedAt": "2026-05-07 10:32:30"
  }
}
```

---

## 批量查询任务状态

**POST** `/api/v2/open/aigc/batch`

```json
{
  "taskIds": ["task_20260507103000_abc12345", "task_20260507103200_def67890"]
}
```

---

## 回调通知

当任务完成时，如果提供了 `callbackUrl`，系统会发送 POST 请求：

```json
{
  "event": "task.completed",
  "taskId": "task_20260507103000_abc12345",
  "status": "success",
  "result": ["https://example-video-store.s3.amazonaws.com/tasks/video.mp4?X-Amz-Expires=86400&X-Amz-Signature=xxx"],
  "errorMsg": "",
  "timestamp": "2026-05-07T10:32:30+08:00"
}
```

---

## 错误码

| code | 说明 |
|------|------|
| 0 | 成功 |
| 10002 | 参数缺失或格式错误 |
| 10005 | API Key 无效或缺失 |
| 10007 | 余额不足 |
| 30003 | 任务不存在 |
| 90003 | 服务器内部错误 |
