# Black Forest Labs FLUX

本站 FLUX 原生兼容入口，只支持 flux-3-image；其他 FLUX 模型使用模型详情列出的协议。

## 接口与鉴权

`POST https://api.tu-zi.com/flux/v1/flux-3-image`

传输方式: json

使用模型调用 API Key。示例凭证为占位符，请从环境变量读取真实密钥。

```http
Authorization: Bearer YOUR_API_KEY
Content-Type: application/json
```

## 请求体参数

| 字段 | 类型 | 必填 | 说明与约束 |
| --- | --- | --- | --- |
| prompt | string | 是 | 图片生成提示词。 |
| width | integer | 否 | 图片宽度，本站接口要求为 32 的倍数。 表单初始值（非上游默认值）: 1024 定义范围: 256 ~ 1440 |
| height | integer | 否 | 图片高度，本站接口要求为 32 的倍数。 表单初始值（非上游默认值）: 1024 定义范围: 256 ~ 1440 |
| prompt_upsampling | boolean | 否 | 是否由上游增强提示词。 表单初始值（非上游默认值）: false |
| seed | integer | 否 | 随机种子。 定义范围: 0 ~ 4294967295 |
| safety_tolerance | integer | 否 | 安全审核等级，0 最严格。 表单初始值（非上游默认值）: 2 定义范围: 0 ~ 6 |
| output_format | string | 否 | 输出图片格式。 表单初始值（非上游默认值）: "jpeg" 可选值: "jpeg", "png", "webp" |

## 最小请求示例

```json
{
  "prompt": "A white ceramic cup"
}
```

## 运行前准备

将 https://api.tu-zi.com 替换为本站地址（不要重复追加 /v1），YOUR_MODEL 替换为模型广场中的完整模型名。Python 示例需要先安装 requests；JavaScript 示例使用 Node.js 20+ 并保存为 .mjs 文件。WebSocket 示例按代码注释安装专用依赖。

先在本站令牌页面创建模型调用密钥，并设置 API_KEY 环境变量；cURL 中的 YOUR_API_KEY 需要替换。上传示例中的 input.png/input.wav 是本地文件，必须提前准备。

首次运行使用最小请求；成功后对照下方响应字段读取结果。异步接口返回任务 ID 后仍需查询，任务提交成功不代表生成已完成。

## 代码示例

### curl

```bash
curl --request POST 'https://api.tu-zi.com/flux/v1/flux-3-image' \
  --header 'Authorization: Bearer YOUR_API_KEY' \
  --header 'Content-Type: application/json' \
  --data '{
  "prompt": "A white ceramic cup"
}'
```

### python

```python
import json
import os
import requests

url = "https://api.tu-zi.com/flux/v1/flux-3-image"
headers = json.loads("{\"Authorization\":\"Bearer YOUR_API_KEY\",\"Content-Type\":\"application/json\"}")
headers["Authorization"] = "Bearer " + os.environ["API_KEY"]
payload = json.loads("{\"prompt\":\"A white ceramic cup\"}")
response = requests.request("POST", url, headers=headers, json=payload, timeout=120)
response.raise_for_status()
result = response.json()
if isinstance(result, dict) and (result.get("success") is False or result.get("error")):
    raise RuntimeError(json.dumps(result, ensure_ascii=False))
print(result)  # Also inspect protocol-specific status/code fields.
```

### javascript

```javascript
// Node.js 20+
const url = "https://api.tu-zi.com/flux/v1/flux-3-image";
const headers = {
  "Authorization": "Bearer YOUR_API_KEY",
  "Content-Type": "application/json"
};
headers.Authorization = 'Bearer ' + process.env.API_KEY;
const response = await fetch(url, { method: "POST", headers, body: JSON.stringify({
  "prompt": "A white ceramic cup"
}) });
if (!response.ok) throw new Error(await response.text());
const result = await response.json();
if (result?.success === false || result?.error) throw new Error(JSON.stringify(result));
console.log(result); // Also inspect protocol-specific status/code fields.
```

## 响应字段

| 字段 | 类型 | 说明与约束 |
| --- | --- | --- |
| id | string | 本站公开任务 ID。 |
| polling_url | string | 如返回查询地址，使用本站任务查询入口校验。 |

以下为示例响应，部分接口仅展示主要字段；可选字段不保证出现。

```json
{
  "id": "task_example"
}
```

## 异步任务

保存创建返回的 id；GET /flux/v1/get_result?id={task_id} 返回 status=Pending、Ready 或 Error。Ready 时读取 result.sample；Error 时读取 error。该结果入口对应本站 flux-3-image 异步任务，其他模型需确认有效端点。

## 错误处理与重试

检查 HTTP 状态与该协议的错误对象；不要将不同协议的错误字段混用。401/403 检查凭证与权限，429 退避等待，5xx 检查网关或上游状态。错误正文可能含 error/message/code 等字段，以实际协议为准。

查询可采用有上限的指数退避；创建任务、生成内容、创建或删除密钥等操作不要盲目重试，以免重复计费或重复执行。

## 适用限制

只接受 prompt、width、height、seed、prompt_upsampling、safety_tolerance、output_format；可选 model 必须是 flux-3-image。未提供宽高时本站使用 1024；宽高须为 256–1440 内的 32 倍数。未知字段会被拒绝。API Key 可用 Bearer 或 x-key；不要同时提供不同密钥。 此异步接口必须交付图片 URL；若上游只返回 Base64，站点需启用 Base64 转 URL 并具备可用的图片存储。未启用或保存失败时任务可能进入 Error，即使提交已返回 200。

## 文档依据

定义版本: 1

审核日期: 2026-11-02

来源: https://api.tu-zi.com/docs/api/reference-relay-bfl-image

关联协议说明: https://api.tu-zi.com/docs/api/images

本文只包含接口文档和示例。真实密钥、账号数据及用户请求内容不包含在复制内容中。
