> ## 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 Image API：文字生成圖片與影像編輯

> 從文字產生一張影像或編輯最多 10 張具有 1K、2K 或 4K 輸出的參考影像

## 概覽

FLUX 3 Image 從文字產生影像並編輯或組合參考影像。每個任務傳回一張影像。選擇解析度和輸出格式，送出任務，然後輪詢結果或接收 Webhook 回呼。

| 功能 | 值 |
| - | - |
| 模型 ID | `flux-3-image` |
| 模式 | `text-to-image`, `image-to-image` |
| 參考圖片 | 1-10 圖生圖的 URL |
| 參考尺寸 | 每張影像的寬度和高度必須至少為 256 像素，總像素最多為 4,000,000 像素 |
| 解析度級距 | `1k`, `2k`, `4k` |
| 輸出格式 | `jpeg`, `png` |
| 輸出 | 確切地 1 影像 URL 在解析的 `resultJson.resultUrls` 陣列中 |

## 端點與身分驗證

API 基底網址：

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

| 方法 | 端點 | 用途 |
| - | - | - |
| `POST` | `/generateTask/flux-3-image` | 提交影像生成或編輯任務 |
| `GET` | `/statusTask/flux-3-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-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-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` 來處理任務失敗。

## 圖生圖的請求

提供 1-10 個參考影像於 `image_urls`。其順序會被保留，因此在提示中應稱為影像 1、影像 2，以此類推。

```bash theme={null}
curl -X POST "https://api.apixo.ai/api/v1/generateTask/flux-3-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 替換為公開且可直接取得的影像 URL。每個參考影像的兩邊必須至少有 256 個像素，且總像素數（`width * height`）不超過 4,000,000。

當在圖生圖模式下 `aspect_ratio` 省略或為空白時，輸出將遵循第一個參考影像的縱橫比。

## 參數

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

結果交付方式。支援的值：`async`、`callback`。使用 `async` 進行狀態輪詢，或使用 `callback` 進行回應傳遞。

**callback\_url** `string`

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

**input** `object` *required*

FLUX 3 Image 的輸入參數。

**屬性**

**mode** `string` *required*

生成模式。支援的值：`text-to-image`、`image-to-image`。此欄位為必填項目；無預設模式。

**prompt** `string` *required*

描述所需影像或編輯的非空白文字。僅包含空格的提示無效。對於多個參考影像，描述影像 1、影像 2 等的作用。未指定固定的最大字元數。

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

`image-to-image` 所需。依參考順序提供 1-10 公用、可直接取得、非空白影像 URL。每個影像的寬度和高度必須至少為 256 像素，且最多包含 4,000,000 像素。僅將此欄位用於圖生圖的請求。

**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`。值不區分大小寫。所選等級決定了每張影像的價格。

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

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

**enable\_prompt\_expansion** `boolean` (default: false)

擴展提示，同時保留其意圖。提供時必須是 JSON 布林值。

## 狀態回應欄位

下面的所有欄位都在 `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"
  }
}
```

請參閱 [Webhooks](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)。

兩種模式皆每項任務生成一張影像，並採用相同的基於解析度的計費方式。參考影像的數量不另計費用。

| 解析度 | APIXO 價格 |
| - | - |
| `1k` | `$0.05 / image` |
| `2k` | `$0.12 / image` |
| `4k` | `$0.65 / image` |

請參閱 [API 定價](https://apixo.ai/pricing/api) 以了解當前價格。

## 耗時與輪詢

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

| 階段 | 使用指引 |
| - | - |
| 第一次輪詢 | 任務創建後等待 10-20 秒 |
| 輪詢間隔 | 任務處理期間每 3-5 秒輪詢一次 |
| 完成 | 成功或失敗時停止輪詢；僅在成功時解析 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-image.json) 中的 `mcp.result` 指定結果的解析方式，`mcp.attachments` 列出可繫結檔案的欄位。這些中繼資料供用戶端整合使用，無須當作生成參數提交。附件欄位為 `image_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.