> ## 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.5 Image API：文字生成圖片與以圖生圖

> Wan 2.5 Image API 用於文生圖和圖生圖的生成，每項任務最多可產生四個輸出。

## 概覽

Wan 2.5 Image 是阿里巴巴的影像模型，支援文字生成圖片和以圖生圖。在 APIXO Playground 試用後，可依本頁範例呼叫 API。

| 功能 | 值 |
| - | - |
| 模型 ID | `wan-2-5-image` |
| 模式 | `text-to-image`, `image-to-image` |
| 提示詞 | 必填，非空；支援中文或英文；最多 `2000` 個字元（模型端截斷） |
| 負面提示 | 選項；支援中文或英文；最多 `500` 個字元（模型端截斷） |
| 每個任務的影像數量 | `num_images` 支援 `1-4`，預設值為 `4` |
| 參考圖片 | `image-to-image` 需提供 `1-3` 個圖片 URL |
| 輸入圖片限制（`image_urls`） | `JPEG/JPG/PNG(no alpha)/BMP/WEBP`、寬度/高度 `384-5000` px、檔案大小 `<=10MB` |
| 縱橫比（`text-to-image`） | `1:1`, `3:4`, `4:3`, `9:16`, `16:9` |
| 縱橫比（`image-to-image`） | `1:1`, `2:3`, `3:2`, `3:4`, `4:3`, `9:16`, `16:9`, `21:9` |

## 端點與身分驗證

API 基底網址：

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

| 方法 | 端點 | 用途 |
| - | - | - |
| `POST` | `/generateTask/wan-2-5-image` | 送出生成任務 |
| `GET` | `/statusTask/wan-2-5-image?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-5-image" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "request_type": "async",
    "input": {
      "mode": "text-to-image",
      "prompt": "a cinematic panda in snow",
      "aspect_ratio": "1:1",
      "num_images": 4
    }
  }'
```

成功回應：

```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-5-image?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/img1.png\",\"https://file.apixo.ai/img2.png\"]}",
    "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 by the model service",
    "createTime": 1767965610929,
    "completeTime": 1767965620132
  }
}
```

等 `state` 變為 `success` 後，再解析 `resultJson`：

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

## 請求體

### 文生圖

```json theme={null}
{
  "request_type": "async",
  "input": {
    "mode": "text-to-image",
    "prompt": "a cinematic panda in snow",
    "negative_prompt": "blurry, low quality",
    "aspect_ratio": "16:9",
    "num_images": 4
  }
}
```

### 圖生圖

```json theme={null}
{
  "request_type": "async",
  "input": {
    "mode": "image-to-image",
    "prompt": "merge style of image 2 into image 1 and keep image 3 color mood",
    "negative_prompt": "low quality",
    "aspect_ratio": "3:4",
    "num_images": 3,
    "image_urls": [
      "https://example.com/base.png",
      "https://example.com/style.png",
      "https://example.com/color.png"
    ]
  }
}
```

## 參數

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

取得結果的方式。選擇 `async` 時，透過 `statusTask` 輪詢結果；選擇 `callback` 時，透過 Webhook 接收結果。

**callback\_url** `string`

當`request_type`為`callback`時需要。必須是可以接收最終任務負載的回呼URL。請參閱 [Webhooks](https://apixo.ai/docs/zh-hant/api-reference/webhooks.md)。

**input** `object` *required*

Wan 2.5 Image 的輸入參數。

**屬性**

**mode** `string` *required*

生成模式。可用值為 `text-to-image`、`image-to-image`。

**prompt** `string` *required*

提示文字。兩種模式皆需提供，修剪後不得為空。支援中文與英文，最大長度為`2000`個字元，超出內容將由模型服務截斷。

**negative\_prompt** `string`

選填的否定提示。支援中文與英文，最大長度為`500`個字元，超出內容將由模型服務截斷。

**aspect\_ratio** `string` (default: 1:1)

輸出縱橫比。`text-to-image`：`1:1`、`3:4`、`4:3`、`9:16`、`16:9`。`image-to-image`：`1:1`、`2:3`、`3:2`、`3:4`、`4:3`、`9:16`、`16:9`、`21:9`。

**num\_images** `integer` (default: 4)

請求的圖像數量。支援`1-4`。接受整數輸入（亦可接受數字字串）。

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

`image-to-image` 所需。必須包含 `1-3` 個圖像 URL。圖像限制：格式為 `JPEG/JPG/PNG`（無 alpha）、`BMP`、`WEBP`；寬度與高度為 `384-5000` px；檔案大小 `<=10MB`。在 `text-to-image` 中將被忽略。

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

設為 `true` 可在支援的生成路由上啟用上游內容審核。API 預設值為 `false`。

## 回應格式

### 送出任務時的回應

任務受理後，`POST /generateTask/wan-2-5-image` 會傳回任務 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`

處理時間，以毫秒為單位。任務完成且有計時資料時才會傳回。

若至少一張圖像成功，該任務仍可回傳 `success`，且 `resultJson.resultUrls` 中僅包含成功的圖像。

## Webhook 回呼模式

若希望後端自動收到最終結果，可使用回呼模式，無須輪詢。

```bash theme={null}
curl -X POST "https://api.apixo.ai/api/v1/generateTask/wan-2-5-image" \
  -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": "image-to-image",
      "prompt": "turn this into a cinematic movie still",
      "aspect_ratio": "16:9",
      "num_images": 2,
      "image_urls": [
        "https://example.com/source-1.png"
      ]
    }
  }'
```

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.5 Image 依產生的影像計費。

| 模式 | APIXO 價格 |
| - | - |
| `text-to-image` | `$0.03 / image` |
| `image-to-image` | `$0.03 / image` |

計費行為：

```text theme={null}
precharge = requested_num_images * unit_price_for_mode
final_charge = successful_images * unit_price_for_mode
refund = precharge - final_charge (if partial failure)
```

有關當前公開定價的信息，請參閱 [API 定價](https://apixo.ai/pricing/api)。如果未列出價格，請在送出任務之前聯絡 APIXO 支援人員進行確認。

## 耗時與輪詢

Wan 2.5 Image 任務是異步的。後端不提供固定的公共延遲SLA；實際延遲因提示複雜性、請求的影像計數、媒體取得速度和佇列負載而異。

| 工作流程 | 建議首次查詢時間 | 輪詢間隔 |
| - | - | - |
| `text-to-image` | 任務建立 10 秒後 | 5s-10s |
| `image-to-image` | 任務建立 10 至 15 秒後 | 5s-10s |

> [!TIP]
>
> 正式環境中請使用回呼模式，避免頻繁輪詢。

請求頻率與並行數上限會依帳戶、API 金鑰和路由而異。收到 `429` 時，請降低請求頻率，並逐步拉長重試間隔。帳戶層級的限制請見[系統 API](https://apixo.ai/docs/zh-hant/api-reference/system.md)。

## 錯誤與排查

### HTTP 錯誤

| 代碼 | 含義 | 處理方式 |
| - | - | - |
| `400` | 請求主體、參數類型或值無效 | 修正請求後再試 |
| `401` | 缺少 API 金鑰，或金鑰無效 | 檢查 `Authorization` 請求標頭 |
| `402` | 餘額或配額不足 | 充值或更換帳號或金鑰 |
| `403` | 金鑰或路由無權訪問該模型 | 檢查權限和路由策略 |
| `429` | 已達到速率或並行限制 | 以指數退避方式重試 |
| `500` | 伺服器錯誤 | 逐步拉長間隔後重試 |
| `502` | 第三方模型服務錯誤 | 逐步拉長間隔後重試 |
| `504` | 第三方模型逾時 | 重試或使用回呼模式 |

### 任務失敗代碼

`failCode` 表示任務失敗的原因，常見值如下。

| 錯誤碼 | 含義 | 處理方式 |
| - | - | - |
| `PromptInvalid` | 提示無效或被模型服務拒絕 | 修改提示詞後再試一次 |
| `MissingParameter` / `BadRequest` | 必填欄位缺失或格式錯誤 | 檢查所選模式的必填欄位 |
| `SensitiveContentDetected` / `ProhibitedContentDetected` | 提示或媒體未通過安全檢查 | 重寫提示或變更輸入影像 |
| `RateLimitExceeded` | 已達到模型服務或路線速率限制 | 逐步拉長間隔後重試 |
| `Task TimeOut` / `Timeout` | 生成任務逾時 | 重試或使用回呼模式 |

### 參數排查

* 兩種模式都需要 `prompt`，且不能為空。
* `image_urls` 僅對於 `image-to-image` 是必需的，並且必須包含 `1-3` 項。
* `num_images`支持`1-4`；如果省略，則預設為 `4`。
* `aspect_ratio` 必須與所選模式的支援集相符。
* 省略時，`aspect_ratio` 預設為 `1:1`。
* 在 `text-to-image` 中，任何提供的 `image_urls` 輸入都將被忽略。

完整列表見[錯誤碼](https://apixo.ai/docs/zh-hant/api-reference/errors.md)。

## MCP 整合

[完整模型 Schema](https://apixo.ai/docs/models/schemas/image/wan-2-5-image.json) 中的 `mcp.result` 指定結果的解析方式，`mcp.attachments` 列出可繫結檔案的欄位。這些中繼資料供用戶端整合使用，無須當作生成參數提交。附件欄位為 `image_urls`。請保留使用者指定的檔案順序。模型參數由 API 驗證。

## 相關連結

* [生成 API 總覽](https://apixo.ai/docs/zh-hant/models.md)
* [影像模型](https://apixo.ai/docs/zh-hant/models/image)
* [送出生成任務](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)
* [嘗試 Wan 2.5 Image 在 APIXO Playground](https://apixo.ai/models/wan-2-5-image)
* [API定價](https://apixo.ai/pricing/api)


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