跳转到主要内容
POST

概述

POST /flux/v1/\{model\} 使用原生 BFL 格式的请求生成图像。默认情况下,请求为异步。存储顶级响应中的 id,然后轮询 GET /flux/v1/get_result 并使用该任务 ID。 如需在同一请求中等待图像,请在 JSON 正文中发送 "async": false。成功的同步响应包含 status: "Ready",图像 URL 位于 result.sample 中。 API 演练场包含适用于 FLUX.2 Pro、Flex 和 Max 的文生图请求示例。请查看 模型页面 或 /v1/models,了解模型 ID 和账户可用性。

请求字段

首先使用 prompt、width、height 和 output_format。你还可以发送 seed;完成后的结果可以报告所使用的种子,但仅凭该字段无法确保输出可重复。 可选的 async 字段控制请求的返回方式。使用 JSON 布尔值 false 进行同步生成。使用 true 或省略该字段进行异步生成。请勿发送诸如 "false" 的字符串。 对于参考图编辑,请在 input_image 中发送公开的 HTTPS 图像 URL。上述三个 FLUX.2 模型均支持此字段。FLUX.2 Pro 还接受 input_image_2 中的第二个公开 HTTPS URL;发送 input_image 时,务必包含 input_image_2。

同步生成

选择 同步文生图(FLUX.2 Pro) 在请求示例中,以发送 "async": false。生成图像时请保持连接处于打开状态。该示例使用 300 秒的客户端超时;这是客户端设置,而非完成截止时间。 当响应包含 status: "Ready" 时,直接读取 result.sample。无需轮询结果。如果请求失败,请先处理 HTTP 错误,再读取结果。 请勿将 async: false 与 webhook_url 或 webhook_secret 结合使用。同步请求会直接返回结果,并拒绝这些 webhook 字段。

异步提交并轮询

当 async 为 true 或被省略时,创建响应会返回任务 ID,同时生成继续进行。将其顶级 id 与 CometAPI 结果端点配合使用;客户端不应依赖响应提供的 polling_url。 轮询直到结果端点返回 status: "Ready"。将 Error、Failed、Failure、Task not found、Request Moderated 和 Content Moderated 视为失败。对于其他状态,请在应用程序的重试和超时限制内继续轮询。
任务就绪后,result.sample 是临时图像 URL。请及时下载或传输该图像;不要依赖固定的有效期。

授权

Authorization
string
header
必填

Bearer token authentication. Use your CometAPI key.

路径参数

model
string
必填

FLUX.2 model ID in the URL path. Check /v1/models or the Models page for account availability.

请求体

application/json
prompt
string
必填

Text prompt describing the image or reference-image edit.

示例:

"A clean editorial photograph of a red ceramic teapot on a pale blue table, soft window light, no text."

async
boolean
默认值:true

Controls whether generation returns asynchronously. Set false to wait for the finished image and read result.sample from the successful response. Set true or omit this field to receive a task ID for polling. Use a JSON boolean, not a string. Do not combine false with webhook_url or webhook_secret.

input_image
string
必填 if input_image_2 is set

Public HTTPS URL of the first reference image. Replace the example URL with a publicly accessible image. This editing field is available for the FLUX.2 models covered by this reference.

示例:

"https://your-image-host/reference-one.jpg"

input_image_2
string

Public HTTPS URL of a second reference image for flux-2-pro. Replace the example URL and also send input_image.

示例:

"https://your-image-host/reference-two.jpg"

seed
integer

Optional seed value. A completed result can report the used seed; that field alone does not establish repeatable output.

width
integer

Requested output width in pixels. Use a dimension supported by the selected model.

示例:

1280

height
integer

Requested output height in pixels. Use a dimension supported by the selected model.

示例:

768

output_format
string

Requested output image format supported by the selected model. The examples use png.

示例:

"png"

响应

200 - application/json

With async: false, successful generation returns status: "Ready" and the image URL in result.sample. With async: true or no async field, save the top-level id and poll the CometAPI result endpoint.

id
string
必填

Task ID to pass to GET /flux/v1/get_result?id=....

status
string
必填

Task state. A successful synchronous response returns Ready. An asynchronous submission can return Pending while generation continues.

result
object | null

Generation result. A successful synchronous response contains the finished image. An asynchronous submission can return an empty or null result.

polling_url
string | null

Response-supplied convenience URL when returned. Clients should poll the documented CometAPI result route by the top-level id.

cost
number | null

Numeric billing coefficient when returned. This field is not documented as a currency or credit amount.

input_mp
number | null

Input image megapixels when returned.

output_mp
number | null

Output image megapixels when returned.

progress
number | null

Task progress when returned.

details
any

Additional task details when returned.

preview
any

Task preview data when returned.

最后修改于 2026年9月21日