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

# Z-Image LoRA API：按自訂尺寸生成影像

> 使用 Z-Image LoRA API 產生風格化影像，並具有細粒度的寬高比控制、快速非同步處理和有競爭力的價格。

## 概覽

Z-Image LoRA 是一個異步文生圖模型，用於根據提示產生單一影像。它支援顯式 `size` 輸入、通用 `aspect_ratio` 預設、可選種子控制和提示擴展。

| 功能 | 值 |
| - | - |
| 模型 ID | `z-image-LoRA` |
| 模式 | `text-to-image` |
| 預設模式 | `text-to-image` |
| 預設尺寸 | `1024*1536` |
| 尺寸格式 | `WIDTH*HEIGHT`, `WIDTHxHEIGHT`, `WIDTHXHEIGHT` |
| 尺寸範圍 | 每條邊必須在 `256` 到 `1536` 像素之間。 |
| 縱橫比 | `1:1`, `2:3`, `3:2`, `3:4`, `4:3`, `9:16`, `16:9` |
| 提示擴展 | `prompt_extend`，預設為 `true` |

## 端點與身分驗證

API 基底網址：

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

| 方法 | 端點 | 用途 |
| - | - | - |
| `POST` | `/generateTask/z-image-LoRA` | 提交文字轉影像任務 |
| `GET` | `/statusTask/z-image-LoRA?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/z-image-LoRA" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "request_type": "async",
    "input": {
      "mode": "text-to-image",
      "prompt": "a cinematic portrait of a warrior standing in falling snow",
      "aspect_ratio": "16:9",
      "prompt_extend": true
    }
  }'
```

成功回應：

```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/z-image-LoRA?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
  }
}
```

等 `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 portrait of a warrior standing in falling snow",
    "aspect_ratio": "16:9",
    "prompt_extend": true
  }
}
```

### 產生明確的大小

```json theme={null}
{
  "request_type": "async",
  "input": {
    "mode": "text-to-image",
    "prompt": "a watercolor mountain lake at sunrise",
    "size": "1024*1536",
    "seed": 42,
    "prompt_extend": false
  }
}
```

## 參數

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

結果交付方式。使用 `async` 並使用 `statusTask` 進行輪詢。

**input** `object` *required*

Z-Image LoRA 的輸入參數。

**屬性**

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

生成模式。此模型僅支援`text-to-image`。如果 SDK 助手省略，則 APIXO 使用 `text-to-image`。

**prompt** `string` *required*

提示文字描述要產生的影像。必須是非空字串。最大長度：4000 個字元。

**size** `string` (default: 1024\*1536)

可選的顯式輸出大小。支援 `WIDTH*HEIGHT`、`WIDTHxHEIGHT` 和 `WIDTHXHEIGHT`，例如 `1024*1536`、`1024x1536` 或 `1024X1536`。寬度和高度必須分別在 `256` 到 `1536` 之間。當提供 `size` 時，它優先於 `aspect_ratio`。

**aspect\_ratio** `string` (default: 2:3)

未提供 `size` 時所使用的輸出縱橫比。支援的值：`1:1`、`2:3`、`3:2`、`3:4`、`4:3`、`9:16`、`16:9`。

**seed** `integer`

選填的隨機種子。若要讓實驗結果更容易重現，請指定固定的非負整數。

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

是否啟用提示擴充。提示擴充不會增加額外的公共費用。

## 回應格式

### 送出任務時的回應

任務受理後，`POST /generateTask/z-image-LoRA` 會傳回任務 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`

處理時間，以毫秒為單位。有計時資料時才會傳回。

## 計費

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

Z-Image LoRA 依產生的影像計費。

| 單位 | APIXO 價格 |
| - | - |
| 生成的一張影像 | `$0.016 / image` |

提示詞擴寫不另收費。

最新的美元費率請見 [API 價目表](https://apixo.ai/pricing/api)。

## 耗時與輪詢

Z-Image LoRA 任務是異步的。實際延遲因提示複雜性和目前佇列負載而異。

| 使用案例 | 建議首次查詢時間 | 輪詢間隔 |
| - | - | - |
| 標準世代 | 任務建立 10 秒後 | 5s-10s |

請求頻率與並行數上限會依帳戶、API 金鑰和路由而異。收到 `429` 時，請降低請求頻率，並逐步拉長重試間隔。帳戶層級的限制請見[系統 API](https://apixo.ai/docs/zh-hant/api-reference/system.md)。

## 尺寸規則

* 如果既未提供 `size` 也未提供 `aspect_ratio`，則預設輸出尺寸為 `1024*1536`。
* `size` 支援 `*`、`x` 和 `X` 分隔符號。
* `size` 優先於 `aspect_ratio`。
* 顯式 `size` 要求寬度和高度必須皆在 `256-1536` 範圍內。
* `aspect_ratio` 僅在 `size` 未提供時使用。
* 支援的 `aspect_ratio` 值會對應到允許範圍內的平台管理的輸出大小。

| 縱橫比 | 輸出尺寸 |
| - | - |
| `1:1` | `1536*1536` |
| `2:3` | `1024*1536` |
| `3:2` | `1536*1024` |
| `3:4` | `1152*1536` |
| `4:3` | `1536*1152` |
| `9:16` | `864*1536` |
| `16:9` | `1536*864` |

## 錯誤與排查

### HTTP 錯誤

| 代碼 | 含義 | 處理方式 |
| - | - | - |
| `400` | 請求主體、模式、參數類型或值無效 | 修正請求後再試 |
| `401` | 缺少 API 金鑰，或金鑰無效 | 檢查 `Authorization` 請求標頭 |
| `402` | 餘額或配額不足 | 充值或更換帳號或金鑰 |
| `403` | 金鑰或路由無權訪問該模型 | 檢查權限和路由策略 |
| `404` | 未找到任務 | 驗證 `taskId` 和模型 ID |
| `429` | 已達到速率或並行限制 | 以指數退避方式重試 |
| `500` | 伺服器錯誤或未知任務失敗 | 逐步拉長間隔後重試 |
| `502` | 模型服務錯誤 | 逐步拉長間隔後重試 |
| `504` | 模型服務逾時 | 稍後重試或再次輪詢 |

### 請求驗證

| 條件 | 後端行為 |
| - | - |
| `mode` 無效 | 傳回模式驗證錯誤；請使用 `text-to-image` |
| 缺失或為空 `prompt` | 傳回缺少參數或驗證錯誤 |
| `size` 格式無效 | 傳回尺寸格式驗證錯誤 |
| 每側 `size` 超出 `256-1536` 範圍 | 傳回尺寸範圍驗證錯誤 |
| 不支援的 `aspect_ratio` 值 | 傳回支援的寬高比列表 |
| 負 `seed` | 傳回種子驗證錯誤 |

完整列表見[錯誤碼](https://apixo.ai/docs/zh-hant/api-reference/errors.md)。

## MCP 整合

[完整模型 Schema](https://apixo.ai/docs/models/schemas/image/z-image-lora.json) 中的 `mcp.result` 指定結果的解析方式，`mcp.attachments` 列出可繫結檔案的欄位。這些中繼資料供用戶端整合使用，無須當作生成參數提交。模型參數由 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)
* [錯誤碼](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.