What you will build
You will submit a1280x768 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 curlandjq, Python 3.10+ withrequests, or Node.js 18+- Access to
flux-2-proon your CometAPI account
Endpoints and authentication
Submit the task:id returned by the create response:
Code examples
Generate synchronously
To receive the finished image in the create response, send the JSON booleanfalse 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
Withasync: 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
The task stays in a processing state
The task stays in a processing state
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.
The image URL no longer works
The image URL no longer works
Download
result.sample promptly after the task becomes Ready, then place the image in storage that your application controls.A request field has no effect
A request field has no effect
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
- Read the Generate a FLUX image API reference.
- Poll results with Get a FLUX image result.
- Find available FLUX models in Models.