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

# FLUX 3.1 Image

> 在 APIXO 上使用 FLUX 3.1 Image 從文字生成影像，編輯最多 10 張參考影像，或使用遮罩局部編輯。

## 概覽

可以從文字生成影像、組合參考影像，或透過遮罩編輯指定區域。每個任務傳回一張影像。選擇解析度、品質等級和輸出格式，然後輪詢結果或透過 Webhook 接收回呼。

| 功能 | 取值或限制 |
| - | - |
| 模型 ID | `flux-3-1-image` |
| 模式 | `text-to-image`, `image-to-image` |
| 參考影像 | 圖生圖使用 1–10 個 URL |
| 遮罩編輯 | 遮罩只會套用至第一張參考圖。使用遮罩時，最多可提交 9 張參考圖。 |
| 參考影像尺寸 | 每張影像的寬和高都至少為 256 畫素，總畫素數最多為 4,000,000 |
| 解析度級距 | `1k`, `2k`, `4k` |
| 品質等級 | `quality`（預設）、`fast` |
| 輸出格式 | `jpeg`, `png` |
| 輸出 | 解析後的 `resultJson.resultUrls` 陣列中恰好有一個影像 URL |

## 端點與身分驗證

API 基底網址：

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

| 方法 | 端點 | 用途 |
| - | - | - |
| `POST` | `/generateTask/flux-3-1-image` | 送出影像生成或編輯任務 |
| `GET` | `/statusTask/flux-3-1-image?taskId={taskId}` | 查詢任務狀態並取得結果 |

每次請求都要附上 APIXO API 金鑰。

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

送出任務的請求還必須帶上 `Content-Type: application/json`。

## 非同步請求範例

送出文生圖任務。

```bash theme={null}
curl -X POST "https://api.apixo.ai/api/v1/generateTask/flux-3-1-image" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "request_type": "async",
    "input": {
      "mode": "text-to-image",
      "prompt": "A white ceramic coffee cup on a wooden table, soft natural daylight",
      "aspect_ratio": "1:1",
      "resolution": "1k",
      "output_format": "png"
    }
  }'
```

送出成功時的回應

```json theme={null}
{
  "code": 200,
  "message": "success",
  "data": {
    "taskId": "task_12345678"
  }
}
```

儲存 `data.taskId`，然後查詢狀態端點。送出成功表示任務已被受理，最終結果以 `data.state` 為準。

## 輪詢結果

```bash theme={null}
curl "https://api.apixo.ai/api/v1/statusTask/flux-3-1-image?taskId=task_12345678" \
  -H "Authorization: Bearer YOUR_API_KEY"
```

任務執行期間，`data.state` 為 `processing`。繼續輪詢，直到狀態變為 `success` 或 `failed`。

成功回應

```json theme={null}
{
  "code": 200,
  "message": "success",
  "data": {
    "taskId": "task_12345678",
    "state": "success",
    "resultJson": "{\"resultUrls\":[\"https://example.com/result.png\"]}",
    "createTime": 1791479211790,
    "completeTime": 1791479234710,
    "costTime": 22920
  }
}
```

`resultJson` 是 JSON **字串**。請先解析它，再讀取圖片 URL。

```javascript theme={null}
const imageUrl = JSON.parse(response.data.resultJson).resultUrls[0];
```

失敗回應

```json theme={null}
{
  "code": 200,
  "message": "success",
  "data": {
    "taskId": "task_12345678",
    "state": "failed",
    "failCode": "UnmappedUpstreamError",
    "failMsg": "The request was rejected. Please check your inputs and try again.",
    "createTime": 1791478394190,
    "completeTime": 1791478396181,
    "costTime": 1991
  }
}
```

狀態回應即使傳回 `code: 200`，任務也可能已失敗。請用 `data.state`、`failCode` 和 `failMsg` 處理任務失敗。

## 圖生圖請求

在 `image_urls` 中提供 1–10 張參考影像。影像順序會保留，因此提示詞可以按順序引用影像 1、影像 2 等。

```bash theme={null}
curl -X POST "https://api.apixo.ai/api/v1/generateTask/flux-3-1-image" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "request_type": "async",
    "input": {
      "mode": "image-to-image",
      "prompt": "Place the product from image 1 into the scene in image 2",
      "image_urls": [
        "https://example.com/product.png",
        "https://example.com/scene.png"
      ],
      "resolution": "1k",
      "output_format": "png"
    }
  }'
```

將示例連結替換為可公開存取且可直接取得影像的 URL。每張參考影像的寬和高都至少為 256 畫素，總畫素數（`width * height`）不得超過 4,000,000。

在圖生圖模式中，如果省略 `aspect_ratio` 或留空，輸出將沿用第一張參考影像的長寬比。

### 使用遮罩編輯影像

此示例使用 `fast` 檔位編輯第一張參考影像的遮罩區域。

```json theme={null}
{
  "input": {
    "mode": "image-to-image",
    "prompt": "Change the cup inside the mask to dark blue",
    "image_urls": ["https://example.com/cup.jpg"],
    "mask_urls": ["https://example.com/cup-mask.png"],
    "quality": "fast"
  }
}
```

## 參數

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

結果交付方式，支援 `async` 和 `callback`。使用 `async` 輪詢狀態，或用 `callback` 透過 Webhook 取得結果。

**callback\_url** `string`

`request_type` 為 `callback` 時必填。請提供可接收 POST 請求的公開 HTTPS 端點。詳見 [Webhook](https://apixo.ai/docs/zh-hant/api-reference/webhooks.md)。

**input** `object` *required*

FLUX 3.1 Image 的輸入參數。

**屬性**

**mode** `string` *required*

生成模式，支援 `text-to-image` 和 `image-to-image`。此欄位必填，沒有預設模式。

**prompt** `string` *required*

描述預期影像或編輯方式的非空文字。僅包含空白字元的提示詞無效。使用多張參考影像時，請描述影像 1、影像 2 等各自的用途。沒有規定固定的字元數上限。

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

`image-to-image` 必填。按參考順序提供 1–10 個可公開存取、可直接取得且非空的影像 URL。使用遮罩時最多提供 9 個。每張影像的寬和高都至少為 256 畫素，總畫素數最多為 4,000,000。僅在圖生圖請求中使用此欄位。

**mask\_urls** `string[]`

`image-to-image` 的可選欄位。只提供一個可公開存取、可直接取得的遮罩 URL。遮罩用於第一張參考影像，兩者的長寬比必須相同。白色區域可修改，黑色區域會保留。使用遮罩時，最多提供 9 張參考影像，並省略 `aspect_ratio`。

**aspect\_ratio** `string`

輸出的長寬比，支援 `21:9`、`2:1`、`16:9`、`3:2`、`7:5`、`4:3`、`5:4`、`1:1`、`4:5`、`3:4`、`5:7`、`2:3`、`9:16`、`1:2`。省略或留空時，文生圖預設 `1:1`，圖生圖沿用第一張參考影像的長寬比。送出遮罩時請省略此欄位。

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

輸出解析度，支援 `1k`、`2k` 和 `4k`。取值不區分大小寫。解析度和質量共同決定每張影像的價格。

**quality** `string` (default: quality)

使用 `quality` 可獲得更精細的細節和文字渲染，使用 `fast` 可加快生成並降低費用。取值不區分大小寫。兩種生成模式均支援這兩個檔位。

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

輸出圖片的格式。可用值為 `jpeg`、`png`。值不區分大小寫。

## 狀態回應欄位

下列欄位均位於 `data` 中。

| 欄位 | 型別 | 說明 |
| - | - | - |
| `taskId` | string | 建立任務時傳回的任務 ID |
| `state` | string | `processing`、`success` 或 `failed` |
| `resultJson` | string | 任務成功時傳回。解析後讀取 `resultUrls`，它是恰好包含一個影像 URL 的陣列 |
| `createTime` | integer | 任務建立時間戳，以 Unix 毫秒錶示 |
| `completeTime` | integer | 任務完成時間戳，以 Unix 毫秒錶示，任務進入終態後傳回 |
| `costTime` | integer | 任務耗時，單位為毫秒，任務進入終態後傳回 |
| `failCode` | string | `state` 為 `failed` 時的失敗碼 |
| `failMsg` | string | `state` 為 `failed` 時的失敗說明 |

## Webhook 回呼模式

將 `request_type` 設為 `callback`，並提供 `callback_url`。

```json theme={null}
{
  "request_type": "callback",
  "callback_url": "https://your-server.com/webhooks/apixo",
  "input": {
    "mode": "text-to-image",
    "prompt": "A minimal coffee shop poster with the title Morning Coffee",
    "resolution": "1k"
  }
}
```

接收端設定和傳送機制詳見 [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)。

兩種模式均為每個任務生成一張影像，且採用相同的解析度和品質等級價格。預設按 `1k` 和 `quality` 計費。價格包含參考影像和遮罩。每個設定的市場參考價與 APIXO 價格相同。

| 解析度 | `quality` 的 APIXO 價格 | `fast` 的 APIXO 價格 |
| - | - | - |
| `1k` | `$0.030 / image` | `$0.015 / image` |
| `2k` | `$0.060 / image` | `$0.040 / image` |
| `4k` | `$0.280 / image` | `$0.110 / image` |

當前價格請檢視 [API 定價](https://apixo.ai/pricing/api)。

## 延遲與輪詢

生成時間因解析度、提示詞複雜度、參考影像和佇列負載而異。4K 任務可能需要幾分鐘。

| 階段 | 使用指引 |
| - | - |
| 第一次輪詢 | 建立任務後等待 10–20 秒 |
| 輪詢間隔 | 任務處理中每隔 3–5 秒輪詢一次 |
| 任務結束 | 達成 success 或 failed 時停止輪詢，僅在 success 時解析 resultJson |
| 正式環境交付 | 高並行度或長時間執行的任務建議使用回呼模式 |

請求觸發速率限制時，降低併發量，並在延長等待間隔後重試。查詢已受理的任務時，請保留原來的 `taskId`。

## 錯誤與排查

* 確認已傳入 `mode` 和非空的 `prompt`。
* 圖生圖請求應提供 1–10 個有效的參考影像 URL，並遵守單張影像的尺寸與總畫素數限制。
* 使用文件列出的長寬比、解析度、品質等級和輸出格式。
* 狀態端點傳回 `code: 200` 時，仍應檢查 `data.state`。
* 任務失敗時，根據 `failCode` 和 `failMsg` 判斷是否應先修改輸入，再重新送出任務。

身分驗證、餘額、速率限制和任務失敗的處理方式見[錯誤碼](https://apixo.ai/docs/zh-hant/api-reference/errors.md)。

## MCP 整合

[完整模型 schema](https://apixo.ai/docs/models/schemas/image/flux-3-1-image.json) 在 `mcp.result` 中宣告結果解析方式，在 `mcp.attachments` 中宣告支援的檔案繫結。兩項都是用戶端整合後設資料，不屬於生成輸入參數。附件路徑為 `image_urls`、`mask_urls`。請保留參考影像的順序，模型參數仍由 API 校驗。

## 相關連結

* [影像模型](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)
* [Flux 2](https://apixo.ai/docs/zh-hant/models/image/flux-2.md)
* [Flux Kontext](https://apixo.ai/docs/zh-hant/models/image/flux-kontext.md)
* [API 定價](https://apixo.ai/pricing/api)


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