Skip to main content

What you will build

You will submit a 1280x768 PNG task to FLUX.2 Pro, store the returned task id, poll GET /flux/v1/get_result, and download result.sample when the task becomes Ready. For a synchronous request, send "async": false and read result.sample from the create response. See Generate synchronously for complete examples.

Prerequisites

  • A CometAPI API key stored in COMETAPI_KEY
  • curl and jq, Python 3.10+ with requests, or Node.js 18+
  • Access to flux-2-pro on your CometAPI account

Endpoints and authentication

Submit the task:
Poll with the top-level id returned by the create response:
Authenticate both CometAPI requests with:

Code examples

Generate synchronously

To receive the finished image in the create response, send the JSON boolean false in async. A successful response has status: "Ready" and an image URL in result.sample. Use true or omit async to use the asynchronous workflow above. Do not send "false" as a string, or combine async: false with webhook_url or webhook_secret. These examples wait up to 300 seconds for the create response, then download the image. The timeout is a client setting, not a completion deadline:

How the flow works

With async: true or no async field, the create endpoint returns a top-level task id while generation continues. Poll the CometAPI result endpoint with that id. Ready is the successful terminal state. Treat known error and moderation states as failures, and keep polling other states only until your client timeout. With async: false, the successful create response contains status: "Ready" and result.sample. Read the image URL directly without polling. Use result.sample only to download the finished image. It is a temporary URL and should not be used as durable application storage.

Common parameters

Troubleshooting

Continue polling within a bounded retry loop. If the client timeout is reached, keep the task ID for later inspection and report the request as timed out rather than successful.
Download result.sample promptly after the task becomes Ready, then place the image in storage that your application controls.
Use the Generate a FLUX image API reference to choose the request fields for your model. Check field names and JSON types against the request example.

Next steps

Last modified on September 21, 2026