> ## 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` |
| 特定模式的比率規則 | 預設 `16:9` 為 `text-to-video` 和 `reference-to-video`；不支援 `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-hant/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`。預設為 `16:9`，適用於 `text-to-video` 與 `reference-to-video`；不支援 `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-hant/api-reference/webhooks.md)。

## 計費

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

## 錯誤與排查

### HTTP 錯誤

| 代碼 | 含義 | 處理方式 |
| - | - | - |
| `400` | 請求主體、模式、參數或媒體 URL 形狀無效 | 修正請求後再試 |
| `401` | 缺少 API 金鑰，或金鑰無效 | 檢查 `Authorization` 請求標頭 |
| `402` | 餘額或配額不足 | 充值或更換帳號或金鑰 |
| `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-hant/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-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)
* [在 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.