> ## Documentation Index
> Fetch the complete documentation index at: https://apixo.ai/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Wan 2.7 Video API：视频生成与编辑

> 用于文本、图像、参考和视频编辑工作流程的阿里巴巴视频生成和编辑 API

## 概览

Wan 2.7 Video 是阿里巴巴的视频模型，支持文生视频、图生视频、参考素材引导生成和视频编辑。在 APIXO Playground 试用后，可以按本页示例调用 API。

| 功能 | 值 |
| - | - |
| 模型 ID | `wan-2-7-video` |
| 模式 | `text-to-video`, `image-to-video`, `reference-to-video`, `video-edit` |
| 提示词 | `text-to-video`、`reference-to-video` 和 `video-edit` 必需；`image-to-video` 可选 |
| 可选分辨率 | `720p`, `1080p` |
| 纵横比 | `16:9`, `9:16`, `1:1`, `4:3`, `3:4` |
| 特定模式的比率规则 | `text-to-video` 和 `reference-to-video` 的默认比例为 `16:9`；`image-to-video` 不支持该比例；`video-edit` 模式可选 |
| 时长 | `text-to-video`/`image-to-video`：范围为 `2-15`（默认值为 `5`）；`reference-to-video`：当使用任何参考视频时，范围为 `2-15` 或 `2-10`（默认值为 `5`）；`video-edit`：范围为 `0` 或 `2-10`（默认值为 `0`） |
| 公共媒体字段 | `image_urls`, `video_urls`, `audio_urls` |

## 公开输入规范

* 公共媒体输入字段为`image_urls`、`video_urls`和`audio_urls`。
* 使用`audio_urls`作为音频输入。
* 对于 `reference-to-video`，`audio_urls` 按槽顺序对齐：首先是 `image_urls`，然后是 `video_urls`。
* 为了 `reference-to-video`，使用空字符串 `""` 在 `audio_urls` 跳过特定的参考插槽而不移动以后的音频绑定。

## 接口与身份验证

API 基础地址：

```text theme={null}
https://api.apixo.ai/api/v1
```

| 方法 | 端点 | 用途 |
| - | - | - |
| `POST` | `/generateTask/wan-2-7-video` | 提交生成或编辑任务 |
| `GET` | `/statusTask/wan-2-7-video?taskId={taskId}` | 查询任务状态并获取结果 |

每个请求都必须携带 APIXO API 密钥：

```http theme={null}
Authorization: Bearer YOUR_API_KEY
```

提交任务时，还需要设置以下请求头：

```http theme={null}
Content-Type: application/json
```

## 异步请求示例

以下示例提交一个最简单的文生视频任务，响应中会返回 `taskId`。

```bash theme={null}
curl -X POST "https://api.apixo.ai/api/v1/generateTask/wan-2-7-video" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "request_type": "async",
    "input": {
      "mode": "text-to-video",
      "prompt": "a cinematic rainy night in tokyo",
      "resolution": "1080p",
      "ratio": "16:9",
      "duration": 5
    }
  }'
```

成功响应：

```json theme={null}
{
  "code": 200,
  "message": "success",
  "data": {
    "taskId": "task_12345678"
  }
}
```

保存 `taskId`，后续轮询结果时需要用到它。

## 轮询结果

```bash theme={null}
curl -X GET "https://api.apixo.ai/api/v1/statusTask/wan-2-7-video?taskId=task_12345678" \
  -H "Authorization: Bearer YOUR_API_KEY"
```

任务处理中的响应示例：

```json theme={null}
{
  "code": 200,
  "message": "success",
  "data": {
    "taskId": "task_12345678",
    "state": "processing",
    "createTime": 1767965610929
  }
}
```

成功响应：

```json theme={null}
{
  "code": 200,
  "message": "success",
  "data": {
    "taskId": "task_12345678",
    "state": "success",
    "resultJson": "{\"resultUrls\":[\"https://file.apixo.ai/video.mp4\"]}",
    "createTime": 1767965610929,
    "completeTime": 1767965652317,
    "costTime": 41388
  }
}
```

任务失败时的响应示例：

```json theme={null}
{
  "code": 200,
  "message": "success",
  "data": {
    "taskId": "task_12345678",
    "state": "failed",
    "failCode": "PromptInvalid",
    "failMsg": "Prompt is invalid or rejected",
    "createTime": 1767965610929,
    "completeTime": 1767965620132
  }
}
```

等 `state` 变为 `success` 后，再解析 `resultJson`：

```javascript theme={null}
const payload = JSON.parse(data.resultJson);
const videoUrls = payload.resultUrls;
```

## 请求体

### 文生视频

```json theme={null}
{
  "request_type": "async",
  "input": {
    "mode": "text-to-video",
    "prompt": "a cinematic rainy night in tokyo",
    "audio_urls": [
      "https://example.com/background.mp3"
    ],
    "negative_prompt": "blurry, low quality",
    "resolution": "1080p",
    "ratio": "16:9",
    "duration": 8,
    "prompt_extend": true,
    "watermark": false,
    "seed": 12345
  }
}
```

### 图生视频（第一帧和可选的最后一帧）

```json theme={null}
{
  "request_type": "async",
  "input": {
    "mode": "image-to-video",
    "image_urls": [
      "https://example.com/first-frame.png",
      "https://example.com/last-frame.png"
    ],
    "audio_urls": [
      "https://example.com/driving-audio.mp3"
    ],
    "prompt": "smooth camera motion with gentle wind",
    "resolution": "720p",
    "duration": 6
  }
}
```

### 参考生成视频

```json theme={null}
{
  "request_type": "async",
  "input": {
    "mode": "reference-to-video",
    "prompt": "keep character style and outfit consistency, but only image 1 should speak",
    "image_urls": [
      "https://example.com/ref-1.png"
    ],
    "video_urls": [
      "https://example.com/ref-clip.mp4"
    ],
    "audio_urls": [
      "https://example.com/ref-voice-1.mp3",
      ""
    ],
    "resolution": "1080p",
    "ratio": "16:9",
    "duration": 6
  }
}
```

### 视频编辑

```json theme={null}
{
  "request_type": "async",
  "input": {
    "mode": "video-edit",
    "video_urls": [
      "https://example.com/input.mp4"
    ],
    "image_urls": [
      "https://example.com/reference.png"
    ],
    "prompt": "change the style into clay animation",
    "negative_prompt": "blurry, low quality",
    "resolution": "720p",
    "ratio": "1:1",
    "duration": 0,
    "audio_setting": "auto",
    "prompt_extend": true,
    "watermark": false
  }
}
```

## 参数

**request\_type** `string` *required* (default: async)

结果获取方式。选择 `async` 时，通过 `statusTask` 轮询结果；选择 `callback` 时，通过 Webhook 接收结果。

**callback\_url** `string`

当 `request_type` 为 `callback` 时必填。请提供公网可访问的 HTTPS 地址，用于接收任务的最终结果。详见 [Webhook](https://apixo.ai/docs/zh/api-reference/webhooks.md)。

**input** `object` *required*

Wan 2.7 Video 的输入参数。

**属性**

**mode** `string` *required*

生成模式。可选值为 `text-to-video`、`image-to-video`、`reference-to-video`、`video-edit`。

**prompt** `string`

提示文字。对于 `text-to-video`、`reference-to-video` 和 `video-edit` 是必需的。`image-to-video` 可选。修剪后必填提示不能为空。支持中文、英文；最大长度为 `5000` 个字符，超出的内容将被截断。

**negative\_prompt** `string`

可选的否定提示。支持中文、英文；最大长度为 `500` 个字符，超出的内容将被截断。

**resolution** `string` (default: 1080p)

输出分辨率档位。可选值为 `720p`、`1080p`。

**ratio** `string`

支持的值：`16:9`、`9:16`、`1:1`、`4:3`、`3:4`。`text-to-video` 和 `reference-to-video` 的默认值为 `16:9`，不支持 `image-to-video`，`video-edit` 为可选。

**duration** `integer`

接受整数或数字字符串输入。`text-to-video` 和 `image-to-video`：`2-15`（默认为 `5`）；`reference-to-video`：默认为 `2-15`，但当提供任何参考视频时为 `2-10`（默认为 `5`）；对于 `reference-to-video` 的计费，非空 `video_urls` 数组将为每个请求增加 `5` 秒计费时间；`video-edit`：`0` 或 `2-10`（默认为 `0`）。

**prompt\_extend** `boolean` (default: true)

是否在生成前启用提示重写。`true`（默认）启用重写并可以改善简短的提示，但可能会增加延迟。`false` 禁用重写。

**watermark** `boolean` (default: false)

是否添加水印。`false`（默认）表示不添加水印；`true` 时将在右下角添加固定文本 `AI 生成`（AI 生成）的水印。

**seed** `integer`

可选的随机种子。支持范围为 `0` 至 `2147483647`。固定种子可提高输出的可重现性，但相同种子不能保证输出完全一致。

**image\_urls** `string[]`

可公开访问的图片 URL。使用 `image-to-video` 时，如果没有提供 `video_urls`，请传入 `1-2` 张图片：第一张作为首帧，第二张可选，用作尾帧。如果已提供 `video_urls`，则最多传入 `1` 张图片作为尾帧。`reference-to-video` 可选填 `1-5` 张图片，但 `image_urls + video_urls` 的总数必须在 `1-5` 之间。`video-edit` 可选填 `1-4` 张参考图。支持的格式为 `JPEG/JPG/PNG`（不含 Alpha 通道）、`BMP` 和 `WEBP`。宽和高分别为 `240-8000` 像素，宽高比为 `1:8-8:1`，文件大小为 `<= 20MB`。

**video\_urls** `string[]`

可公开访问的视频 URL。`image-to-video` 可在 `video_urls[0]` 中提供 `1` 段待续写的视频。`reference-to-video` 可选填 `1-5` 个参考视频，但 `image_urls + video_urls` 的总数须在 `1` 至 `5` 之间。只要请求中含有非空视频 URL，就固定加收 `5` 秒的费用，每次请求只加收一次，与参考视频的数量和时长无关。`video-edit` 必须提供正好 `1` 个输入视频 URL。各模式的限制如下：`image-to-video` 的续写视频（`video_urls[0]`）须为 `mp4/mov`，时长 `2-10s`，尺寸 `240-4096` 像素，宽高比 `1:8-8:1`，大小 `<= 100MB`。`reference-to-video` 的参考视频须为 `mp4/mov`，时长 `1-30s`，尺寸 `240-4096` 像素，宽高比 `1:8-8:1`，大小 `<= 100MB`。`video-edit` 的输入视频须为 `mp4/mov`，时长 `2-10s`，尺寸 `240-4096` 像素，宽高比 `1:8-8:1`，大小 `<= 100MB`。

**audio\_urls** `string[]`

可公开访问的音频 URL。`text-to-video` 可提供 `1` 个背景音频 URL。`image-to-video` 可提供 `1` 个驱动音频 URL，但仅限未提供 `video_urls` 时。`reference-to-video` 可选填 `1-5` 个音频，按位置对应参考素材，先对应 `image_urls`，再对应 `video_urls`。音频数组可短于参考素材总数，但不能超过 `image_urls + video_urls`。如需跳过其中一个位置，请在该处传空字符串 `""`，以保留后续素材的对应关系。每个非空值为对应素材提供音频。在 `reference-to-video` 中，如果没有提供 `audio_urls`，参考视频默认可保留原声。支持 `wav/mp3` 格式，时长 `2-30s`，大小 `<= 15MB`。音频长于 `duration` 时，只取前 `duration` 秒；音频较短时，视频剩余部分静音。

**audio\_setting** `string`

仅 `video-edit`。支持的值：`auto`、`origin`。`auto`（默认）根据提示音指示决定是否重新生成音频，否则可能会保留原始音频。`origin` 强制使用原始输入音频并跳过音频再生。

**nsfw\_checker** `boolean` (default: false)

设为 `true` 可在支持的生成路由上启用上游内容审核。API 默认值为 `false`。

## 响应格式

### 提交任务时的响应

任务受理后，`POST /generateTask/wan-2-7-video` 会返回任务 ID：

**code** `integer`

API 状态码。`200` 表示任务已受理。

**message** `string`

状态说明。

**data.taskId** `string`

任务的唯一 ID，用于查询任务状态。

### 状态响应字段

**taskId** `string`

任务的唯一标识符。

**state** `string`

当前任务状态，可能的值为 `pending`、`processing`、`success`、`failed`。

**resultJson** `string`

当 `state` 为 `success` 时返回。解析此 JSON 字符串后，可从 `resultUrls` 读取生成的视频链接。

**failCode** `string`

供程序处理的错误码，仅在 `state` 为 `failed` 时返回。

**failMsg** `string`

失败原因说明，仅在 `state` 为 `failed` 时返回。

**createTime** `integer`

任务创建时的 Unix 时间戳，单位为毫秒。

**completeTime** `integer`

任务完成时的 Unix 时间戳，单位为毫秒。任务完成后返回。

**costTime** `integer`

处理耗时，以毫秒为单位。任务完成且有计时数据时返回。

## Webhook 回调模式

如果希望服务端自动收到最终结果，可以使用回调模式，无需轮询。

```bash theme={null}
curl -X POST "https://api.apixo.ai/api/v1/generateTask/wan-2-7-video" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "request_type": "callback",
    "callback_url": "https://your-server.com/webhooks/apixo",
    "input": {
      "mode": "video-edit",
      "video_urls": [
        "https://example.com/input.mp4"
      ],
      "image_urls": [
        "https://example.com/reference.png"
      ],
      "prompt": "change the scene to watercolor style",
      "resolution": "1080p",
      "duration": 0,
      "audio_setting": "origin"
    }
  }'
```

Webhook 接收要求和重试规则见 [Webhook 文档](https://apixo.ai/docs/zh/api-reference/webhooks.md)。

## 计费

新提交的非 LLM 请求按 **1 积分 = `$0.001`** 计费。先按用量和附加项目计算总额，再应用账号折扣，最后将请求总额向上取整到整数积分。如果约定了固定单价，则按该单价的原始精度计算，不再使用标准价或另行打折；最终积分仍向上取整。详见[积分换算与取整](https://apixo.ai/docs/zh/pricing.md#credit-conversion-and-rounding)。

Wan 2.7 Video 按秒计费。单价根据 `mode` 和 `resolution` 确定。

| 模式 | 分辨率 | APIXO 官方价格 |
| - | - | - |
| `text-to-video` | `720p` | `$0.10 / second` |
| `text-to-video` | `1080p` | `$0.15 / second` |
| `image-to-video` | `720p` | `$0.10 / second` |
| `image-to-video` | `1080p` | `$0.15 / second` |
| `reference-to-video` | `720p` | `$0.15 / second` |
| `reference-to-video` | `1080p` | `$0.24 / second` |
| `video-edit` | `720p` | `$0.10 / second` |
| `video-edit` | `1080p` | `$0.15 / second` |

计费公式：

| 模式 | 公式 |
| - | - |
| `text-to-video` | `duration * unitPrice` |
| `image-to-video` | `duration * unitPrice` |
| `reference-to-video` 且不包含 `video_urls` | `duration * unitPrice` |
| `reference-to-video` 且包含一个或多个非空的 `video_urls` | `(duration + 5) * unitPrice` |
| `video-edit` | `billableSeconds * unitPrice` |

对于 `reference-to-video`，无论参考视频的数量或实际长度如何，每次请求都会添加固定的 `5` 计费秒数 \*\*\*\*。参考图像和音频不会增加计费秒数。

`duration = 5` 的示例：

| 请求 | 计算方式 | 总计 |
| - | - | -: |
| `720p`，仅供图像参考 | `5 * $0.15` | `$0.75` |
| `720p`，与 `video_urls` | `(5 + 5) * $0.15` | `$1.50` |
| `1080p`，与 `video_urls` | `(5 + 5) * $0.24` | `$2.40` |

对于 `video-edit`，计费基于输入和输出持续时间：

* 输入视频时长必须介于 2 和 10 秒（含）之间。
* 计费输入持续时间上限为 `10` 秒。
* 如果 `duration = 0`，则 `billableSeconds = cappedInputDuration * 2`。
* 如果 `duration = 2-10`，则 `billableSeconds = cappedInputDuration + duration`。
* `video-edit` 的最大计费秒数为 `20`。

最新的美元费率见 [API 价目表](https://apixo.ai/pricing/api)。

## 延迟与轮询

Wan 2.7 Video 任务是异步的。后端不提供固定的公共延迟SLA；实际延迟因模式、分辨率、持续时间、提示复杂性、媒体获取速度和队列负载而异。

| 工作流程 | 建议首次查询时间 | 轮询间隔 |
| - | - | - |
| `text-to-video` | 任务创建 60 秒后 | 10s |
| `image-to-video` | 任务创建 60 秒后 | 10s |
| `reference-to-video` | 任务创建 60 至 90 秒后 | 10s-15s |
| `video-edit` | 任务创建 60 至 90 秒后 | 10s-15s |

> [!TIP]
>
> 对于生产工作负载，请使用回调模式以避免对长时间运行的视频作业进行频繁轮询。

请求频率和并发上限因账号、API 密钥和路由而异。收到 `429` 时，请降低请求频率，逐步延长重试间隔。账号级限制见[系统 API](https://apixo.ai/docs/zh/api-reference/system.md)。

## 错误与排查

### HTTP 错误

| 代码 | 含义 | 处理方式 |
| - | - | - |
| `400` | 请求体、模式、参数或媒体 URL 格式无效 | 在重试前修复请求 |
| `401` | 缺少 API 密钥，或密钥无效 | 检查 `Authorization` 请求头 |
| `402` | 余额或配额不足 | 充值或更换账号或API密钥 |
| `403` | 密钥或路由无权访问该模型 | 检查权限和路由策略 |
| `429` | 已达到速率或并发限制 | 按指数退避策略重试 |
| `500` | 服务器错误 | 逐步延长间隔后重试 |
| `502` | 服务错误 | 逐步延长间隔后重试 |
| `504` | 服务超时 | 重试或使用回调模式 |

### 任务失败错误码

`failCode` 表示任务失败的原因，常见值如下。

| 错误码 | 含义 | 处理方式 |
| - | - | - |
| `PromptInvalid` | 提示词无效或被拒绝 | 重写提示并重试 |
| `MissingParameter` / `BadRequest` | 必填字段缺失或格式错误 | 检查特定模式的必填字段 |
| `SensitiveContent` / `SensitiveContentDetected` | 提示或媒体未通过安全检查 | 修改提示或媒体 |
| `RateLimitExceeded` | 请求频率达到上限 | 逐步延长间隔后重试 |
| `Task TimeOut` / `Timeout` | 任务超时 | 重试或使用回调模式 |
| `UnmappedUpstreamError` | 任务因未知原因失败 | 通过退避重试或通过 `taskId` 联系支持人员 |

### 参数排查

* `mode` 必须是 `text-to-video`、`image-to-video`、`reference-to-video` 或 `video-edit` 之一。
* `prompt` 需要用于 `text-to-video`、`reference-to-video` 和 `video-edit` 任务。
* `ratio` 不允许出现在 `image-to-video` 任务中。
* `image-to-video` 任务需要提供 `image_urls` 或 `video_urls`。
* 如果 `image-to-video` 任务包含 `video_urls`，则不允许提供 `audio_urls`。
* `reference-to-video` 需要至少一个参考项，横跨 `image_urls` 和 `video_urls`，总计数量 `<= 5`。
* 如果`reference-to-video`包含`audio_urls`，则按槽位顺序绑定：先`image_urls`，然后`video_urls`。
* 如果 `reference-to-video` 需要跳过参考槽，同时保持后面的音频对齐，请在该槽中传递空字符串 `""`。
* 如果`reference-to-video`包含`audio_urls`，则其长度不能超过`image_urls + video_urls`。
* `video-edit` 恰好需要一个 `video_urls` 项。
* `video-edit` 需要一个非空的 `prompt`。
* `video-edit` 输入剪辑持续时间必须为 `2-10` 秒。

完整列表见[错误码](https://apixo.ai/docs/zh/api-reference/errors.md)。

## MCP 集成

[完整模型 Schema](https://apixo.ai/docs/models/schemas/video/wan-2-7-video.json) 中的 `mcp.result` 指定了结果的解析方式，`mcp.attachments` 列出支持绑定文件的字段。这些元数据供客户端集成使用，无需作为生成参数提交。附件字段为 `image_urls`, `video_urls`, `audio_urls`。请保留用户指定的文件顺序。API 负责校验模型参数。

## 相关链接

* [生成 API 概览](https://apixo.ai/docs/zh/models.md)
* [视频模型](https://apixo.ai/docs/zh/models/video)
* [提交生成任务](https://apixo.ai/docs/zh/api-reference/generate-task.md)
* [查询任务状态](https://apixo.ai/docs/zh/api-reference/status-task.md)
* [Webhook](https://apixo.ai/docs/zh/api-reference/webhooks.md)
* [错误码](https://apixo.ai/docs/zh/api-reference/errors.md)
* [参数规范](https://apixo.ai/docs/zh/api-reference/parameters.md)
* [路由策略](https://apixo.ai/docs/zh/concepts/routing-strategies.md)
* [在 APIXO Playground 中试用 Wan 2.7 Video](https://apixo.ai/models/wan-2-7-video)
* [API定价](https://apixo.ai/pricing/api)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.