What you’ll learn
In this tutorial you’ll learn:- How to deploy a ComfyUI Serverless endpoint using the Runpod Hub.
- How to structure ComfyUI workflow JSON for API requests.
- How to submit jobs, monitor their progress, and retrieve results.
- How to generate images using the FLUX.1-dev-fp8 model.
- How to decode the base64 output to retrieve the generated image.
Requirements
Before starting this tutorial you’ll need:- A Runpod account with available credits.
- A Runpod API key (available in your user settings).
- Basic familiarity with command-line tools like
curl
. - Python installed on your system (for the image decoding step).
- The
jq
command-line JSON processor (optional but recommended). - Basic understanding of JSON structure for workflow configuration.
Step 1: Deploy a ComfyUI Serverless endpoint using the Runpod Hub
Using a different model
Using a different model
The ComfyUI Hub listing comes with the FLUX.1-dev-fp8 model pre-installed and works only with this model when deployed from the Hub.If you want to use a different model, you can also deploy the endpoint using one of these pre-defined Docker images:
runpod/worker-comfyui:<version>-base
- Clean ComfyUI install with no models.runpod/worker-comfyui:<version>-flux1-schnell
- FLUX.1 schnell model.runpod/worker-comfyui:<version>-flux1-dev
- FLUX.1 dev model.runpod/worker-comfyui:<version>-sdxl
- Stable Diffusion XL model.runpod/worker-comfyui:<version>-sd3
- Stable Diffusion 3 medium model.
<version>
with the latest release version from GitHub Releases.If you need a model that’s not listed here, or have your own LoRA, or need custom nodes, you can use this customization guide to create your own custom worker.- Navigate to the ComfyUI Hub listing in the Runpod web interface.
- Click Deploy [VERSION_NUMBER], then click Next and then Create Endpoint to confirm. This creates a fully configured endpoint with the FLUX.1-dev-fp8 model pre-installed and appropriate GPU settings for running ComfyUI workflows.
- On the endpoint page, make a note of the Endpoint ID. You’ll need this value to submit jobs and retrieve results.
32vgrms732dkwi
). Your endpoint URL will follow this pattern: https://api.runpod.ai/v2/ENDPOINT_ID/run
for asynchronous requests.
Step 2: Prepare your ComfyUI workflow
ComfyUI uses workflow JSON to define the image generation process. The workflow contains nodes that represent different steps in the generation pipeline, such as loading models, encoding prompts, and saving images. On your local machine, create a file calledcomfyui_workflow.json
with the following FLUX.1-dev-fp8 workflow:
- Node 6: Encodes the positive text prompt using CLIP.
- Node 30: Loads the FLUX.1-dev-fp8 checkpoint.
- Node 31: Performs the sampling process with specified parameters.
- Node 8: Decodes the latent image to a viewable format.
- Node 9/40: Saves the generated image.
text
field in node 6, or adjust generation parameters like steps
, cfg
, width
, and height
in their respective nodes.
Step 3: Submit your first job
Use the/run
endpoint to submit an asynchronous job that will generate an image based on your ComfyUI workflow.
Replace ENDPOINT_ID
with your actual endpoint ID and YOUR_API_KEY
with your Runpod API key in the following command:
Step 4: Monitor job progress
Check your job’s status using the/status
endpoint with the job ID you received in the previous step.
Use the following command to check your job’s progress, replacing the placeholders (ENDPOINT_ID
, JOB_ID
, and YOUR_API_KEY
) with your actual values:
delayTime
field shows how long the job waited in the queue before processing began, measured in milliseconds.
Step 5: Retrieve completed results
Continue polling the status endpoint until the status changes toCOMPLETED
. Once your job completes, the status endpoint will return the generated image data encoded in base64 format.
When your job finishes successfully, you’ll receive a response containing the output:
executionTime
field shows how long the actual image generation took, while delayTime
indicates the initial queue wait time. Both values are in milliseconds.
To save the complete response for processing, use this command:
You have up to 30 minutes to retrieve your results via the status endpoint, after which results will be automatically deleted for security.
Step 6: Decode and save your image
Now we’ll convert the base64-encoded image data into a viewable image file using Python. Create a Python script calleddecode_comfyui_image.py
to decode the base64 image data from your JSON response:
Understanding ComfyUI workflows
ComfyUI workflows are JSON structures that define the image generation pipeline through interconnected nodes. Each node has:- Inputs: Parameters and connections to other nodes.
- Class type: The operation this node performs.
- Meta information: Human-readable titles and descriptions.