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

## 計費

新提交的非 LLM 請求按 **1 點 = `$0.001`** 計費。先依用量和加購項目計算總額，再套用帳戶折扣，最後將請求總額無條件進位至整數點數。若已約定固定單價，則保留該單價的精度，不再使用標準價或另行打折；最終點數仍須進位。詳見[積分換算與進位](https://apixo.ai/docs/zh-hant/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-hant/api-reference/system.md)。

## 錯誤與排查

### HTTP 錯誤

| 代碼 | 含義 | 處理方式 |
| - | - | - |
| `400` | 請求主體、參數類型或值無效 | 修正請求後再試 |
| `401` | 缺少 API 金鑰，或金鑰無效 | 檢查 `Authorization` 請求標頭 |
| `402` | 餘額或配額不足 | 充值或更換帳號或金鑰 |
| `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-hant/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-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)
* [API定價](https://apixo.ai/pricing/api)


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