> ## 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` |
| 输出 | 解析后的 `resultJson.resultUrls` 数组中必须恰好包含 1 个图像 URL |

## 接口与身份验证

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`来处理任务失败。

## Image-to-image 请求

在 `image_urls` 中提供 1-10 个参考图像。其顺序保持不变，因此在提示中应将其分别称为图像 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` 进行 Webhook 交付。

**callback\_url** `string`

`request_type` 为 `callback` 时必填。请提供能接收 POST 请求的公开 HTTPS 端点。详见 [Webhook](https://apixo.ai/docs/zh/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/api-reference/webhooks.md) 了解接收器设置和传递处理。

## 计费

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