> ## 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/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)

Output分辨率，支持 `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/api-reference/webhooks.md)。

## 计费

新提交的非 LLM 请求按 **1 积分 = `$0.001`** 计费。先按用量和附加项目计算总额，再应用账号折扣，最后将请求总额向上取整到整数积分。如果约定了固定单价，则按该单价的原始精度计算，不再使用标准价或另行打折；最终积分仍向上取整。详见[积分换算与取整](https://apixo.ai/docs/zh/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/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/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)
* [Flux 2](https://apixo.ai/docs/zh/models/image/flux-2.md)
* [Flux Kontext](https://apixo.ai/docs/zh/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.