> ## 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：將圖片中的角色生成為動畫

> 在 APIXO Playground 試用後，可依本頁範例呼叫 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` |
| 來源圖片 | 確切地 1 個 URL 在 `image_urls` |
| 動態影片 | 確切地 1 個公開的 HTTP/HTTPS MP4、MOV 或 M4V URL 在 `video_urls` |
| 解析度 | `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-hant/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-hant/api-reference/webhooks.md)。

## 計費

新提交的非 LLM 請求按 **1 點 = `$0.001`** 計費。先依用量和加購項目計算總額，再套用帳戶折扣，最後將請求總額無條件進位至整數點數。若已約定固定單價，則保留該單價的精度，不再使用標準價或另行打折；最終點數仍須進位。詳見[積分換算與進位](https://apixo.ai/docs/zh-hant/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-hant/api-reference/system.md)。

## 錯誤與排查

### HTTP 錯誤

| 代碼 | 含義 | 處理方式 |
| - | - | - |
| `400` | 請求主體、模式、參數、影像 URL 或影片 URL 無效 | 修正請求後再試 |
| `401` | 缺少 API 金鑰，或金鑰無效 | 檢查 `Authorization` 請求標頭 |
| `402` | 餘額或配額不足 | 充值或更換帳號或金鑰 |
| `403` | 鍵或路由無法存取模型，或內容被拒絕 | 檢查權限並修正輸入內容 |
| `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-hant/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-hant/models.md)
* [影片模型](https://apixo.ai/docs/zh-hant/models/video)
* [送出生成任務](https://apixo.ai/docs/zh-hant/api-reference/generate-task.md)
* [查詢任務狀態](https://apixo.ai/docs/zh-hant/api-reference/status-task.md)
* [Webhook](https://apixo.ai/docs/zh-hant/api-reference/webhooks.md)
* [錯誤碼](https://apixo.ai/docs/zh-hant/api-reference/errors.md)
* [參數規範](https://apixo.ai/docs/zh-hant/api-reference/parameters.md)
* [路由策略](https://apixo.ai/docs/zh-hant/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.