> ## 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.

# Qwen Image 3.0 API：文生图与图像编辑

> Qwen Image 3.0 图像生成和编辑 API 用于文生图和图生图工作流程

## 概览

Qwen Image 3.0是异步图像生成和编辑API。使用 `text-to-image` 仅提示生成，或 `image-to-image` 当您想用一到三个参考图像指导输出时。

| 功能 | 值 |
| - | - |
| 模型 ID | `qwen-image-3-0` |
| 模式 | `text-to-image`, `image-to-image` |
| 输出数量 | `num_images`支持`1-6`；默认 `1` |
| 提示词 | 必填，且必须为非空字符串 |
| 图生图提示长度限制 | 最大 `800` 个字符 |
| 参考图片 | `image-to-image` 模式下必需提供；支持 `1-3` 个可公开访问的图像 URL |
| 纵横比 | `WIDTH:HEIGHT` 的比例范围为 `1:8` 至 `8:1`；常用值包括 `1:1`、`4:3`、`3:4`、`16:9`、`9:16` |
| 默认宽高比 | `1:1` 为 `text-to-image`；省略 `image-to-image` 比例时将遵循第一张输入图像的尺寸 |
| 分辨率档位 | `1k`, `2k` |
| 定制尺寸 | 可选的 `size` 以 `WIDTHxHEIGHT` 或 `WIDTH*HEIGHT` 的形式提供，优先于 `resolution` 和 `aspect_ratio` |
| 提示词扩写 | `enable_prompt_expansion`，默认为 `true` |
| 种子 | `-1` 表示随机，或 `0-2147483647` |

## 接口与身份验证

API 基础地址：

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

| 方法 | 端点 | 用途 |
| - | - | - |
| `POST` | `/generateTask/qwen-image-3-0` | 提交图像生成或编辑任务 |
| `GET` | `/statusTask/qwen-image-3-0?taskId={taskId}` | 查询任务状态并获取结果 |

每个请求都必须携带 APIXO API 密钥：

```http theme={null}
Authorization: Bearer YOUR_API_KEY
```

提交任务时，还需要设置以下请求头：

```http theme={null}
Content-Type: application/json
```

## 异步请求示例

```bash theme={null}
curl -X POST "https://api.apixo.ai/api/v1/generateTask/qwen-image-3-0" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "request_type": "async",
    "input": {
      "mode": "text-to-image",
      "prompt": "a clean editorial poster for a bookstore opening, crisp readable typography, warm daylight",
      "aspect_ratio": "4:3",
      "resolution": "1k",
      "num_images": 1,
      "enable_prompt_expansion": true,
      "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/qwen-image-3-0?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/image.png\"]}",
    "createTime": 1767965610929,
    "completeTime": 1767965652317,
    "costTime": 41388
  }
}
```

任务失败时的响应示例：

```json theme={null}
{
  "code": 200,
  "message": "success",
  "data": {
    "taskId": "task_12345678",
    "state": "failed",
    "failCode": "InvalidParameter",
    "failMsg": "The parameter is invalid",
    "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 minimalist product poster for wireless earbuds, clean layout, sharp text",
    "aspect_ratio": "16:9",
    "resolution": "1k",
    "num_images": 2,
    "negative_prompt": "blur, low quality",
    "watermark": false,
    "enable_prompt_expansion": true,
    "prompt_extend_mode": "direct",
    "seed": -1
  }
}
```

### 图生图

```json theme={null}
{
  "request_type": "callback",
  "callback_url": "https://your-server.com/webhooks/apixo",
  "input": {
    "mode": "image-to-image",
    "prompt": "turn this product photo into a polished e-commerce hero image with soft studio lighting",
    "image_urls": [
      "https://example.com/product.png"
    ],
    "size": "2048x2048",
    "num_images": 3,
    "negative_prompt": "blur, low quality",
    "watermark": false,
    "enable_prompt_expansion": true,
    "prompt_extend_mode": "direct",
    "seed": 123456
  }
}
```

> [!NOTE]
>
> `size` 优先于 `resolution` 和 `aspect_ratio`。在 `image-to-image` 模式中若未指定 `size`，则若希望输出遵循第一张输入图像的比例，应省略 `aspect_ratio`

## 参数

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

结果交付方式。支持的值：`async`、`callback`。使用 `async` 进行轮询，使用 `statusTask` 进行轮询，或使用 `callback` 进行 Webhook 传递。

**callback\_url** `string`

当 `request_type` 为 `callback` 时必填。请提供公网可访问的 HTTPS 地址，用于接收任务的最终结果。详见 [Webhook](https://apixo.ai/docs/zh/api-reference/webhooks.md)。

**input** `object` *required*

Qwen Image 3.0 的输入参数。

**属性**

**mode** `string` *required*

生成模式。可选值为 `text-to-image`、`image-to-image`。

**prompt** `string` *required*

描述所需图像或编辑的文本提示。验证时将忽略前导和尾随空格。对于 `image-to-image`，提示不能超过 `800` 个字符。最大长度：文本生成图像为 1800 个字符；图生图最多 800 个字符。

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

参考图像 URL。`image-to-image` 所需；提供 `1-3` 可公开访问且可直接获取的图像 URL。忽略 `text-to-image`。

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

输出宽高比，格式为 `WIDTH:HEIGHT`。该比例必须在 `1:8` 到 `8:1` 之间，常见值包括 `1:1`、`4:3`、`3:4`、`16:9` 和 `9:16`。对于 `text-to-image`，若为空或省略，默认为 `1:1`；对于 `image-to-image`，若为空或省略，则沿用第一个输入图像的宽高比。

**resolution** `string` (default: 1k)

Output分辨率层级。支持的值：`1k`、`2k`。API 接受小写或大写值，并对它们进行标准化以用于计费和处理。

**size** `string`

可选的显式输出大小，采用 `WIDTHxHEIGHT` 或 `WIDTH*HEIGHT` 格式，例如 `1024x1024` 或 `2048*1152`。如果提供，`size` 优先于 `resolution` 和 `aspect_ratio`。自定义尺寸标准化为支持的 16 像素网格、比率范围 `1:8` 到 `8:1` 以及从 `512x512` 到 `2048x2048` 的总像素面积。

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

请求的输出图像数量。支持从 `1` 到 `6` 的整数。

**negative\_prompt** `string`

可选的负面提示，用于描述需避免的视觉元素。最大长度为 500 个字符。

**watermark** `boolean` (default: false)

是否添加水印。

**enable\_prompt\_expansion** `boolean` (default: true)

是否在生成前启用提示扩展。支持值：`true`、`false`。

**prompt\_extend\_mode** `string` (default: direct)

提示扩展模式。支持值：`direct`、`agent`。`agent` 模式适用于 `text-to-image`；在 `image-to-image` 模式下，视为 `direct` 处理。

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

随机种子。使用 `-1` 生成随机输出，或输入 `0` 至 `2147483647` 之间的整数以获得更可重复的实验结果。

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

设为 `true` 可在支持的生成路由上启用上游内容审核。API 默认值为 `false`。

## 响应格式

### 提交任务时的响应

任务受理后，`POST /generateTask/qwen-image-3-0` 会返回任务 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/qwen-image-3-0" \
  -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": "keep the product identity, improve the lighting, and replace the background with a clean studio set",
      "image_urls": [
        "https://example.com/product.png"
      ],
      "resolution": "2k"
    }
  }'
```

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)。

Qwen Image 3.0 按生成的图像计费。 `num_images` 控制请求的图像数量，`image-to-image` 定价还取决于输入图像 URL 的数量。

| 模式 | 分辨率 | 输入图像 | APIXO 价格 |
| - | - | -: | -: |
| `text-to-image` | `1k` | `0` | `$0.030 / image` |
| `text-to-image` | `2k` | `0` | `$0.030 / image` |
| `image-to-image` | `1k` | `1` | `$0.033 / image` |
| `image-to-image` | `1k` | `2` | `$0.036 / image` |
| `image-to-image` | `1k` | `3` | `$0.039 / image` |
| `image-to-image` | `2k` | `1` | `$0.033 / image` |
| `image-to-image` | `2k` | `2` | `$0.036 / image` |
| `image-to-image` | `2k` | `3` | `$0.039 / image` |

计费行为：

```text theme={null}
precharge = requested_num_images * unit_price_for_mode_resolution_and_input_image_count
final_charge = successful_images * unit_price_for_mode_resolution_and_input_image_count
refund = precharge - final_charge
```

如果提供 `size`，则计费将使用标准化输出大小层。归一化尺寸超过 `2,250,000` 像素的按 `2k` 计费；其他支持的尺寸按 `1k` 计费。

有关当前折扣和市场比较定价，请参阅[API定价](https://apixo.ai/pricing/api)。

## 延迟与轮询

Qwen Image 3.0 任务是异步的。实际延迟因提示复杂性、参考图像可访问性、所选分辨率和当前队列负载而异。

| 工作流程 | 建议首次查询时间 | 轮询间隔 |
| - | - | - |
| 文生图 | 任务创建 10 秒后 | 5s-10s |
| 图生图 | 任务创建 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` | 密钥或账户无法访问模型 | 检查权限和账户状态 |
| `404` | 未找到任务 | 验证 `taskId` 和模型 ID |
| `429` | 已达到速率或并发限制 | 按指数退避策略重试 |
| `500` | 服务器错误或未知任务失败 | 逐步延长间隔后重试 |
| `502` | 模型服务错误 | 逐步延长间隔后重试 |
| `504` | 模型服务超时 | 重试；耗时较长的任务可改用回调模式 |

### 请求验证

| 条件 | 后端行为 |
| - | - |
| 缺少 `input` | 返回缺少参数的错误 |
| 缺失或无效 `mode` | 返回`Invalid mode type. Supported: text-to-image, image-to-image` |
| 缺失、非字符串或空 `prompt` | 返回提示验证错误 |
| `image-to-image`提示超过`800`个字符 | 返回提示长度错误 |
| `image-to-image`模式下缺失 `image_urls` | 返回缺少参数的错误 |
| `image_urls` 不是数组、包含空值或包含多于 `3` 个项目 | 返回图像 URL 验证错误 |
| `aspect_ratio` 无效 | 返回纵横比验证错误 |
| `resolution` 无效 | 返回`The parameter {{resolution}} is invalid. Supported: 1k, 2k.` |
| `size` 无效 | 返回尺寸验证错误 |
| `num_images` 无效 | 返回`The parameter {{num_images}} must be between 1 and 6.` |
| `negative_prompt` 无效 | 返回字符串类型错误 |
| `watermark` 无效 | 返回布尔类型错误 |
| `enable_prompt_expansion` 无效 | 返回布尔类型错误 |
| `prompt_extend_mode` 无效 | 返回`The parameter {{prompt_extend_mode}} must be direct or agent.` |
| `seed` 无效 | 返回支持的种子范围 |

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

## MCP 集成

[完整模型 Schema](https://apixo.ai/docs/models/schemas/image/qwen-image-3-0.json) 中的 `mcp.result` 指定了结果的解析方式，`mcp.attachments` 列出支持绑定文件的字段。这些元数据供客户端集成使用，无需作为生成参数提交。附件字段为 `image_urls`。请保留用户指定的文件顺序。API 负责校验模型参数。

## 相关链接

* [Qwen Image 3.0 Pro](https://apixo.ai/docs/zh/models/image/qwen-image-3-0-pro.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)
* [API定价](https://apixo.ai/pricing/api)


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