> ## 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.2 Animate API：将图片中的角色生成为动画

> 在阿里巴巴的 Wan 2.2 Animate API 中，通过异步轮询和 Webhook 回调，将源图像与动态视频结合，为角色生成动画。

## 概览

Wan 2.2 Animate 采用两个具有不同用途的资源：`image_urls[0]` 提供角色，`video_urls[0]` 提供动作。分别提供一个。保持 `mode` 为 `standard`，并通过 `type` 选择操作：

* [动画](#animate)：将源运动应用到角色。
* [替换](#replace)：替换动态视频中的角色。

| 功能 | 值 |
| - | - |
| 模型 ID | `wan-2-2-animate` |
| 模式 | `standard` |
| 行为 | `animate`, `replace` |
| 源图片 | `image_urls` 中必须恰好包含 1 个 URL |
| 动态视频 | `video_urls` 中必须恰好包含 1 个公开的 HTTP/HTTPS MP4、MOV 或 M4V URL |
| 分辨率 | `480p`, `720p` |
| 计费时长 | 从 `video_urls[0]` 检测到，最短 5 秒和最长 120 计费秒 |
| 种子 | `-1` 或 `0` 至 `2147483647` |

## 接口与身份验证

API 基础地址：

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

| 方法 | 端点 | 用途 |
| - | - | - |
| `POST` | `/generateTask/wan-2-2-animate` | 提交生成任务 |
| `GET` | `/statusTask/wan-2-2-animate?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-2-animate" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "request_type": "async",
    "input": {
      "mode": "standard",
      "type": "animate",
      "image_urls": [
        "https://example.com/character.png"
      ],
      "video_urls": [
        "https://example.com/motion.mp4"
      ],
      "resolution": "480p",
      "seed": -1
    }
  }'
```

成功响应：

```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-2-animate?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": 1767965772317,
    "costTime": 161388
  }
}
```

任务失败时的响应示例：

```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;
```

## 请求体

### 动画

使用 `type: "animate"` 使用参考视频中的运动为源图像中的角色设置动画。

```json theme={null}
{
  "request_type": "async",
  "input": {
    "mode": "standard",
    "type": "animate",
    "image_urls": [
      "https://example.com/character.png"
    ],
    "video_urls": [
      "https://example.com/motion.mp4"
    ],
    "prompt": "keep the face stable and follow the motion naturally",
    "resolution": "480p",
    "seed": -1
  }
}
```

### 代替

将 `type: "replace"` 用于角色替换：用源图片中的角色替换动作视频里的角色。

```json theme={null}
{
  "request_type": "async",
  "input": {
    "mode": "standard",
    "type": "replace",
    "image_urls": [
      "https://example.com/character.png"
    ],
    "video_urls": [
      "https://example.com/motion.mp4"
    ],
    "prompt": "replace the person in the motion video with the provided character",
    "resolution": "720p",
    "seed": 42
  }
}
```

## 参数

**request\_type** `string` (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.2 Animate 的输入参数。

**属性**

**mode** `string` *required*

公共生成模式。支持的值：`standard`。

**type** `string` (default: animate)

动画行为。支持的值：`animate`、`replace`。

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

源图像 URL。准确提供 1 个 URL。

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

动作参考视频 URL。准确提供 1 个公开的 HTTP/HTTPS MP4、MOV 或 M4V URL。APIXO 在提交任务前会探测 `video_urls[0]` 以检测计费持续时间。

**prompt** `string`

可选提示指导。如果提供，必须是非空字符串。最大长度：2500 个字符。

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

输出分辨率。可选值为 `480p`、`720p`。

**seed** `integer` (default: -1)

随机种子。使用 `-1` 作为随机种子，或设置 `0` 到 `2147483647` 之间的整数以获得可重现的运行。

## 响应格式

### 提交任务时的响应

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

**code** `integer`

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

**message** `string`

状态说明。

**data.taskId** `string`

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

### 状态响应字段

**taskId** `string`

任务的唯一标识符。

**state** `string`

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

**resultJson** `string`

包含生成视频 URL 的 JSON 字符串。当 `state` 为 `success` 时返回。

**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-2-animate" \
  -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": "standard",
      "type": "replace",
      "image_urls": [
        "https://example.com/character.png"
      ],
      "video_urls": [
        "https://example.com/motion.mp4"
      ],
      "prompt": "replace the person in the motion video with the provided character",
      "resolution": "720p",
      "seed": 42
    }
  }'
```

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.2 Animate 按生成视频的秒数计费。所选的 `resolution` 决定单价，并从 `video_urls[0]` 检测计费持续时间。

| 分辨率 | 计费输入 | APIXO 价格 |
| - | - | - |
| `480p` | 检测到的参考视频时长，最短为 5 秒，最长为 120 秒（计费时长） | `$0.04 / second` |
| `720p` | 检测到的参考视频时长，最短为 5 秒，最长为 120 秒（计费时长） | `$0.08 / second` |

如果参考视频短于 5 秒，则计费按 5 秒计算；如果超过 120 秒，则计费上限为 120 秒。

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

## 延迟与轮询

实际延迟可能因参考视频时长、分辨率、队列负载及当前路由健康状况而异。

| 请求结构 | 通常生成耗时 | 建议首次查询时间 | 轮询间隔 |
| - | - | - | - |
| 短片 `480p` 动画 | 随参考视频时长和队列负载变化 | 任务创建 60 秒后 | 5s-10s |
| 短片 `720p` 动画 | 随参考视频时长和队列负载变化 | 任务创建 60 秒后 | 5s-10s |
| 较长的参考视频 | 随参考视频时长和队列负载变化 | 任务创建 60 至 120 秒后 | 10s |

> [!TIP]
>
> 视频生成可能需要几分钟。对于生产环境，请使用回调模式以避免频繁轮询。

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

## 错误与排查

### HTTP 错误

| 代码 | 含义 | 处理方式 |
| - | - | - |
| `400` | 请求体、模式、参数、图像URL或视频URL无效 | 在重试前修复请求 |
| `401` | 缺少 API 密钥，或密钥无效 | 检查 `Authorization` 请求头 |
| `402` | 余额或配额不足 | 充值或更换账号或API密钥 |
| `403` | 密钥或路由无法访问模型，或者内容被拒绝 | Check权限并修改输入内容 |
| `429` | 已达到速率或并发限制 | 按指数退避策略重试 |
| `500` | 服务器错误 | 逐步延长间隔后重试 |
| `502` | 服务错误 | 逐步延长间隔后重试 |
| `504` | 服务超时 | 重试；耗时较长的任务可改用回调模式 |

### 任务失败原因

| 原因 | 需要检查什么 |
| - | - |
| 内容政策拒绝 | 修改提示、源图像或动态视频 |
| 模式或类型无效 | 使用`mode: "standard"`和`type: "animate"`或`"replace"` |
| 介质形状无效 | 准确提供 1 `image_urls` 项和 1 `video_urls` 项 |
| 无法探测视频 URL | 使用支持范围读取或完整下载的直接公开 HTTP/HTTPS MP4、MOV 或 M4V URL |
| 分辨率无效 | 使用`480p`或`720p` |
| 无效种子 | 使用 `-1` 或 `0` 到 `2147483647` 之间的整数 |
| 速率限制或任务超时 | 使用退避重试或切换到回调模式 |

### 常见问题解决方法

| 问题表现 | 解决办法 |
| - | - |
| 请求因模式无效而失败 | 将`input.mode`设置为`standard` |
| 任务创建前请求失败 | 检查 `video_urls[0]` 是否可公开访问并且具有受支持的 MP4、MOV 或 M4V 媒体类型 |
| 非常短的视频的帐单费用高于预期 | 短于 5 秒的视频按 5 秒计费 |
| 长参考视频的账单停止增加 | 计费时长上限为 120 秒 |
| 几分钟内无更新 | 通过退避继续轮询，或使用回调模式进行生产 |

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

## MCP 集成

[完整模型 Schema](https://apixo.ai/docs/models/schemas/video/wan-2-2-animate.json) 中的 `mcp.result` 指定了结果的解析方式，`mcp.attachments` 列出支持绑定文件的字段。这些元数据供客户端集成使用，无需作为生成参数提交。附件字段为 `image_urls`, `video_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)
* [尝试 Wan 2.2 Animate 在 APIXO Playground](https://apixo.ai/models/wan-2-2-animate)
* [API定价](https://apixo.ai/pricing/api)


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