> ## 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/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/api-reference/webhooks.md)。

## 计费

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

## 错误与排查

### HTTP 错误

| 代码 | 含义 | 处理方式 |
| - | - | - |
| `400` | 请求体、参数类型或值无效 | 在重试前修复请求 |
| `401` | 缺少 API 密钥，或密钥无效 | 检查 `Authorization` 请求头 |
| `402` | 余额或配额不足 | 充值或更换账号或API密钥 |
| `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/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/models.md)
* [图像模型](https://apixo.ai/docs/zh/models/image)
* [提交生成任务](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)
* [尝试 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.