> ## 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 API：根据提示词进行图生图

> Qwen 图生图 API，用于提示引导的图像转换：使用文本指令重新设计、编辑和优化源图像。

## 概览

Qwen Image 是异步图生图 API。提供一张源图像和提示，然后轮询任务，直到生成的变体准备就绪。

| 功能 | 值 |
| - | - |
| 模型 ID | `qwen` |
| 模式 | `image-to-image` |
| 提示词长度 | 1 至 2000 个字符 |
| 源图片 | 正好 1 个公开 `image_url` |
| 每个任务的图像数量 | `num_images` 必须是 `1`、`2`、`3` 或 `4` |
| 纵横比 | `1:1`, `4:3`, `3:4`, `9:16`, `16:9` |
| 速度选项 | `none`, `regular`, `high` |
| 输出格式 | `png`, `jpeg` |

## 接口与身份验证

API 基础地址：

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

| 方法 | 端点 | 用途 |
| - | - | - |
| `POST` | `/generateTask/qwen` | 提交图生图任务 |
| `GET` | `/statusTask/qwen?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" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "request_type": "async",
    "input": {
      "mode": "image-to-image",
      "prompt": "turn this product photo into a clean studio hero image with soft reflections",
      "image_url": "https://example.com/source.png",
      "num_images": 2,
      "aspect_ratio": "16:9",
      "speed": "regular",
      "output_format": "png"
    }
  }'
```

成功响应：

```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?taskId=task_12345678" \
  -H "Authorization: Bearer YOUR_API_KEY"
```

成功响应：

```json theme={null}
{
  "code": 200,
  "message": "success",
  "data": {
    "taskId": "task_12345678",
    "state": "success",
    "resultJson": "{\"resultUrls\":[\"https://file.apixo.ai/image-1.png\",\"https://file.apixo.ai/image-2.png\"]}",
    "createTime": 1767965610929,
    "completeTime": 1767965652317,
    "costTime": 41388
  }
}
```

等 `state` 变为 `success` 后，再解析 `resultJson`：

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

## 请求体

```json theme={null}
{
  "request_type": "async",
  "callback_url": "https://your-server.com/webhooks/apixo",
  "input": {
    "mode": "image-to-image",
    "prompt": "transform into a warm sunrise scene with cinematic lighting",
    "image_url": "https://example.com/source.jpg",
    "num_images": 4,
    "aspect_ratio": "16:9",
    "speed": "regular",
    "num_inference_steps": 30,
    "guidance_scale": 8,
    "output_format": "jpeg",
    "negative_prompt": "low quality, blurry, distorted",
    "seed": 42
  }
}
```

## 参数

**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*

Qwen Image 的输入参数。

**属性**

**mode** `string` (default: image-to-image)

生成模式。唯一支持的值为 `image-to-image`。如果省略，后端将自动识别此单一支持模式。

**prompt** `string` *required*

提示文字。必须是非空字符串且不能超过 `2000` 个字符。

**image\_url** `string` *required*

源图像 URL。必须是可直接访问的公共图像 URL。

**num\_images** `integer` *required*

请求的输出图像的数量。支持的值：`1`、`2`、`3`、`4`。

**aspect\_ratio** `string`

可选的输出纵横比。支持的值：`1:1`、`4:3`、`3:4`、`9:16`、`16:9`。

**speed** `string` (default: none)

可选的生成速度。支持的值：`none`、`regular`、`high`。

**num\_inference\_steps** `integer` (default: 25)

可选的推理步数。支持范围：`2-49`。

**guidance\_scale** `integer` (default: 4)

可选的指导尺度。支持范围：`0-20`。

**output\_format** `string` (default: png)

输出图片的格式。可选值为 `png`、`jpeg`。

**negative\_prompt** `string`

可选的否定提示。最大长度为 `500` 个字符。

**seed** `integer`

可选的随机种子。

**sync\_mode** `boolean`

可选的同步标志以实现兼容性。对于正常的 APIXO 任务使用，请保留默认的异步工作流程。

## 响应格式

### 提交任务时的响应

任务受理后，`POST /generateTask/qwen` 会返回任务 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" \
  -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": "make this image look like a premium editorial campaign",
      "image_url": "https://example.com/source.jpg",
      "num_images": 1
    }
  }'
```

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 按请求的 `num_images` 值计费。

| 请求的图像 | APIXO 价格 |
| - | - |
| `1` | `$0.025 / generation` |
| `2` | `$0.050 / generation` |
| `3` | `$0.075 / generation` |
| `4` | `$0.100 / generation` |

最新的美元费率见 [API 价目表](https://apixo.ai/pricing/api)。

## 延迟与轮询

Qwen Image 任务是异步的。实际延迟因源图像获取速度、请求的图像数量、提示复杂性和队列负载而异。

| 使用案例 | 建议首次查询时间 | 轮询间隔 |
| - | - | - |
| 正常的图生图任务 | 任务创建 10 至 15 秒后 | 5s-10s |
| 多个输出或高并发工作负载 | 优先使用回调模式 | 如果轮询，请使用 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` | 返回`The required parameter {{input}} is missing.` |
| 缺少 `prompt` | 返回`The required parameter {{prompt}} is missing.` |
| 提示为空或过长 | 返回验证或长度错误 |
| 缺少 `image_url` | 返回`The required parameter {{image_url}} is missing.` |
| `num_images` 无效 | 返回`The parameter {{num_images}} must be 1, 2, 3 or 4.` |
| `aspect_ratio` 无效 | 返回支持的宽高比列表 |
| `speed` 无效 | 返回`The parameter {{speed}} must be either 'none', 'regular' or 'high'.` |
| `output_format` 无效 | 返回`The parameter {{output_format}} must be either 'jpeg' or 'png'.` |

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

## MCP 集成

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


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