> ## 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 2 Image API：Standard 和 Pro 文生图模式

> Qwen 2 文生图 API，支持标准和专业生成模式、灵活的尺寸设置以及根据提示生成的文本渲染。

## 概览

Qwen 2 Image 是异步文生图 API。它支持标准和专业生成模式、多种宽高比、提示扩展、可选的负面提示以及每个任务最多 6 个图像。

| 功能 | 值 |
| - | - |
| 模型 ID | `qwen-2-image` |
| 模式 | `text-to-image`, `text-to-image-pro` |
| 默认模式 | `text-to-image` |
| 提示词长度 | 1 至 800 个字符 |
| 负面提示 | 可选，最多 500 个字符 |
| 每个任务的图像数量 | `num_images`默认为`1`；范围 `1-6` |
| 纵横比 | `1:1`, `3:4`, `4:3`, `9:16`, `16:9` |
| 提示扩展 | `prompt_extend`，默认`true` |
| 水印 | `watermark`，默认`false` |

## 接口与身份验证

API 基础地址：

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

| 方法 | 端点 | 用途 |
| - | - | - |
| `POST` | `/generateTask/qwen-2-image` | 提交文本转图像任务 |
| `GET` | `/statusTask/qwen-2-image?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-2-image" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "request_type": "async",
    "input": {
      "mode": "text-to-image-pro",
      "prompt": "a premium poster for a bookstore event, crisp typography, elegant layout",
      "negative_prompt": "blurry text, distorted letters, low resolution",
      "aspect_ratio": "16:9",
      "num_images": 2,
      "prompt_extend": true,
      "watermark": false
    }
  }'
```

成功响应：

```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-2-image?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.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",
  "input": {
    "mode": "text-to-image",
    "prompt": "a minimalist product poster for wireless earbuds, clean layout",
    "aspect_ratio": "4:3",
    "num_images": 1,
    "prompt_extend": true,
    "watermark": false
  }
}
```

### 专业文本转图像

```json theme={null}
{
  "request_type": "callback",
  "callback_url": "https://your-server.com/webhooks/apixo",
  "input": {
    "mode": "text-to-image-pro",
    "prompt": "a high-end brand key visual with readable headline text and premium lighting",
    "negative_prompt": "blurred typography, misspelled words, jagged edges",
    "aspect_ratio": "9:16",
    "num_images": 2,
    "seed": 123456
  }
}
```

## 参数

**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 2 Image 的输入参数。

**属性**

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

生成模式。支持的值：`text-to-image`、`text-to-image-pro`。如果省略，后端默认为 `text-to-image`。

**prompt** `string` *required*

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

**negative\_prompt** `string`

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

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

输出画面的宽高比。可选值为 `1:1`、`3:4`、`4:3`、`9:16`、`16:9`。

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

输出图像的数量。接受整数或数字字符串输入。支持范围：`1-6`。

**prompt\_extend** `boolean` (default: true)

是否启用提示扩展。

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

是否为生成的图像添加水印。

**seed** `integer`

可选的随机种子。支持范围：`0-2147483647`。

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

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

## 响应格式

### 提交任务时的响应

任务受理后，`POST /generateTask/qwen-2-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`

处理耗时，以毫秒为单位。有计时数据时返回。

## Webhook 回调模式

如果希望服务端自动收到最终结果，可以使用回调模式，无需轮询。

```bash theme={null}
curl -X POST "https://api.apixo.ai/api/v1/generateTask/qwen-2-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": "text-to-image-pro",
      "prompt": "a premium campaign poster with readable headline text",
      "aspect_ratio": "16:9",
      "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 2 Image 按生成的图像计费。

| 模式 | APIXO 价格 |
| - | - |
| `text-to-image` | `$0.03 / image` |
| `text-to-image-pro` | `$0.07 / 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)。

## 延迟与轮询

Qwen 2 Image 任务是异步的。实际延迟因提示复杂性、请求的图像计数和队列负载而异。

| 使用案例 | 建议首次查询时间 | 轮询间隔 |
| - | - | - |
| 标准生成 | 任务创建 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` | 模型服务超时 | 重试；耗时较长的任务可改用回调模式 |

### 请求验证

| 条件 | 后端行为 |
| - | - |
| `mode` 无效 | 返回`Invalid mode type. Supported: text-to-image, text-to-image-pro` |
| 缺失或为空 `prompt` | 返回缺少参数或验证错误 |
| 提示超过 `800` 个字符 | 返回长度错误 |
| `num_images` 无效 | 返回`The parameter {{num_images}} must be between 1 and 6.` |
| `aspect_ratio` 无效 | 返回支持的宽高比列表 |
| `prompt_extend` 或 `watermark` 无效 | 返回布尔类型错误 |
| `seed` 无效 | 返回支持的种子范围 |

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

## MCP 集成

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