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",並在 result.sample 中提供圖片 URL。
API playground 包含 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>"
}