FLUX 画像を生成する
CometAPI のネイティブ BFL 互換エンドポイントを通じて、FLUX.2 のテキストから画像および参照画像タスクを送信します。
概要
POST /flux/v1/\{model\} ネイティブ BFL 形式のリクエストで画像を生成します。リクエストはデフォルトで非同期です。トップレベルのレスポンス id を保存し、次に GET /flux/v1/get_result をそのタスク ID でポーリングします。
同じリクエスト内で画像を待機するには、JSON 本文で "async": false を送信します。同期レスポンスが成功すると、status: "Ready" と result.sample の画像 URL が含まれます。
API プレイグラウンドには、FLUX.2 Pro、Flex、Max 向けのテキストから画像へのリクエスト例が含まれています。モデル ID とアカウントの利用可否については、 モデルページ または /v1/models を確認してください。
リクエストフィールド
まずprompt、width、height、output_format を指定します。seed も送信できます。完了した結果では使用されたシードを報告できますが、このフィールドだけでは再現可能な出力は保証されません。
省略可能な async フィールドは、リクエストの返却方法を制御します。同期生成には JSON のブール値 false を使用します。非同期生成には true を使用するか、このフィールドを省略します。"false" のような文字列は送信しないでください。
参照画像の編集では、input_image に公開 HTTPS 画像 URL を送信します。このフィールドは、上記の 3 つの FLUX.2 モデルでサポートされています。FLUX.2 Pro では input_image_2 に 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 を返します。CometAPI の結果エンドポイントでは、そのトップレベルの id を使用します。クライアントはレスポンスで提供される polling_url に依存しないでください。
結果エンドポイントが status: "Ready" を返すまでポーリングします。Error、Failed、Failure、Task not found、Request Moderated、Content Moderated は失敗として扱います。その他の状態では、アプリケーションの再試行およびタイムアウトの制限内でポーリングを続行してください。
承認
Bearer token authentication. Use your CometAPI key.
パスパラメータ
FLUX.2 model ID in the URL path. Check /v1/models or the Models page for account availability.
ボディ
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."
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.
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"
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"
Optional seed value. A completed result can report the used seed; that field alone does not establish repeatable output.
Requested output width in pixels. Use a dimension supported by the selected model.
1280
Requested output height in pixels. Use a dimension supported by the selected model.
768
Requested output image format supported by the selected model. The examples use png.
"png"
レスポンス
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.
Task ID to pass to GET /flux/v1/get_result?id=....
Task state. A successful synchronous response returns Ready. An asynchronous submission can return Pending while generation continues.
Generation result. A successful synchronous response contains the finished image. An asynchronous submission can return an empty or null result.
Response-supplied convenience URL when returned. Clients should poll the documented CometAPI result route by the top-level id.
Numeric billing coefficient when returned. This field is not documented as a currency or credit amount.
Input image megapixels when returned.
Output image megapixels when returned.
Task progress when returned.
Additional task details when returned.
Task preview data when returned.