Skip to main content
Comfy Router lets you call partner models through https://api.comfy.org with one Comfy API key. Send the model’s input to POST /v2/models/{provider}/{model} and wait for the finished result. This example generates an image with bfl/flux-2-pro.
1

Create an API key

Create a key in your Comfy workspace. In a Bash-compatible terminal, set:
Keep API keys on your server or in your local environment. These examples are for a terminal or server, not browser JavaScript.
2

Save a key for this request

Generate this value once for this image. If you retry the same request, reuse it.
If uuidgen is unavailable, use another UUID generator. Use a new key when you start a new image.
3

Generate an image

Choose your language and run the example. Image generation can take a few minutes.
Both SDKs read COMFY_API_KEY from the environment.
4

Read and save the result

For this model, the image URL is at result.sample in the response body. An abbreviated response looks like this; the URL below is illustrative:
Open the returned URL or download it:
Download promptly. Router can rehost BFL assets on Comfy storage, but URLs expire and a replay does not renew them. A failed rehost can leave a shorter-lived provider URL. See result assets.

Queue instead of waiting

run holds the connection until the image is ready. To get a request_id back at once and collect the result later, from this process or another one, call submit instead (the SDK versions step 3 installs have it), or send the same body to POST /v2/models/{provider}/{model}/requests over HTTP. Send an Idempotency-Key with it as you did in step 2: a submit retried after a dropped connection then returns the original request instead of queueing and billing a second one. The SDKs mint one per submit call. Every model page has a Queue and collect later tab beside the synchronous snippet, and Queued delivery walks through status, cancellation and collection. Queued delivery is scoped to the workspace behind your key, which a key created in your Comfy workspace carries.

Choose a model

Browse the models available through Comfy Router, inspect their inputs, then replace the model ID in this example.