跳轉到主要內容
POST

概覽

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。請立即下載或轉移該圖片;請勿依賴固定的有效期限。

授權

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日