Flux
生成 FLUX 图像
通过 CometAPI 的原生 BFL 兼容端点提交 FLUX.2 文生图和参考图任务。
POST
/
flux
/
v1
/
{model}
curl https://api.cometapi.com/flux/v1/flux-2-pro \
-H "Authorization: Bearer $COMETAPI_KEY" \
-H "Content-Type: application/json" \
-d '{
"prompt": "A clean editorial photograph of a red ceramic teapot on a pale blue table, a small yellow lemon on the right, soft window light, no text.",
"seed": 424242,
"width": 1280,
"height": 768,
"output_format": "png"
}'
{
"id": "<task_id>",
"status": "Pending",
"result": {},
"polling_url": "https://api.cometapi.com/flux/v1/get_result?id=<task_id>"
}
概述
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。请及时下载或传输该图像;不要依赖固定的有效期。路径参数
请求体
application/json
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.
响应
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.
最后修改于 2026年9月21日
⌘I
curl https://api.cometapi.com/flux/v1/flux-2-pro \
-H "Authorization: Bearer $COMETAPI_KEY" \
-H "Content-Type: application/json" \
-d '{
"prompt": "A clean editorial photograph of a red ceramic teapot on a pale blue table, a small yellow lemon on the right, soft window light, no text.",
"seed": 424242,
"width": 1280,
"height": 768,
"output_format": "png"
}'
{
"id": "<task_id>",
"status": "Pending",
"result": {},
"polling_url": "https://api.cometapi.com/flux/v1/get_result?id=<task_id>"
}