When you want to stop the worker after each finished job to have a clean state, see official documentation.
false
COMFY_POLLING_INTERVAL_MS
Time to wait between poll attempts in milliseconds.
250
COMFY_POLLING_MAX_RETRIES
Maximum number of poll attempts. This should be increased the longer your workflow is running.
500
SERVE_API_LOCALLY
Enable local API server for development and testing. See Local Testing for more details.
disabled
Upload image to AWS S3
This is only needed if you want to upload the generated picture to AWS S3. If you don't configure this, your image will be exported as base64-encoded string.
Create a bucket in region of your choice in AWS S3 (BUCKET_ENDPOINT_URL)
Create an IAM that has access rights to AWS S3
Create an Access-Key (BUCKET_ACCESS_KEY_ID & BUCKET_SECRET_ACCESS_KEY) for that IAM
Configure these environment variables for your RunPod worker:
Environment Variable
Description
Example
BUCKET_ENDPOINT_URL
The endpoint URL of your S3 bucket.
https://<bucket>.s3.<region>.amazonaws.com
BUCKET_ACCESS_KEY_ID
Your AWS access key ID for accessing the S3 bucket.
AKIAIOSFODNN7EXAMPLE
BUCKET_SECRET_ACCESS_KEY
Your AWS secret access key for accessing the S3 bucket.
Template Name: runpod-worker-comfy (it can be anything you want)
Template Type: serverless (change template type to "serverless")
Container Image: <dockerhub_username>/<repository_name>:tag, in this case: timpietruskyblibla/runpod-worker-comfy:3.1.0-sd3 (or -base for a clean image or -sdxl for Stable Diffusion XL or -flex1-schnell for FLUX.1 schnell)
Container Registry Credentials: You can leave everything as it is, as this repo is public
Note: You can also not configure it, the images will then stay in the worker. In order to have them stored permanently, we have to add the network volume
Worker configuration: Select a GPU that can run the model you have chosen (see GPU recommendations)
Active Workers: 0 (whatever makes sense for you)
Max Workers: 3 (whatever makes sense for you)
GPUs/Worker: 1
Idle Timeout: 5 (you can leave the default)
Flash Boot: enabled (doesn't cost more, but provides faster boot of our worker, which is good)
Select Template: runpod-worker-comfy (or whatever name you gave your template)
(optional) Advanced: If you are using a Network Volume, select it under Select Network Volume. Otherwise leave the defaults.
Click deploy
Your endpoint will be created, you can click on it to see the dashboard
GPU recommendations
Model
Image
Minimum VRAM Required
Container Size
Stable Diffusion XL
sdxl
8 GB
15 GB
Stable Diffusion 3 Medium
sd3
5 GB
20 GB
FLUX.1 Schnell
flux1-schnell
24 GB
30 GB
FLUX.1 dev
flux1-dev
24 GB
30 GB
API specification
The following describes which fields exist when doing requests to the API. We only describe the fields that are sent via input as those are needed by the worker itself. For a full list of fields, please take a look at the official documentation.
An array of images. Each image will be added into the "input"-folder of ComfyUI and can then be used in the workflow by using it's name
"input.images"
An array of images, where each image should have a different name.
🚨 The request body for a RunPod endpoint is 10 MB for /run and 20 MB for /runsync, so make sure that your input images are not super huge as this will be blocked by RunPod otherwise, see the official documentation
Field Name
Type
Required
Description
name
String
Yes
The name of the image. Please use the same name in your workflow to reference the image.
image
String
Yes
A base64 encoded string of the image.
Interact with your RunPod API
Generate an API Key:
In the User Settings, click on API Keys and then on the API Key button.
Save the generated key somewhere safe, as you will not be able to see it again when you navigate away from the page.
Use the API Key:
Use cURL or any other tool to access the API using the API key and your Endpoint ID:
Replace <api_key> with your key.
Use your Endpoint:
Replace <endpoint_id> with the ID of the endpoint. (You can find the endpoint ID by clicking on your endpoint; it is written underneath the name of the endpoint at the top and also part of the URLs shown at the bottom of the first box.)
You can either create a new job async by using /run or a sync by using /runsync. The example here is using a sync job and waits until the response is delivered.
Use the Network Volume in your endpoint configuration:
Either create a new endpoint or update an existing one.
In the endpoint configuration, under Advanced > Select Network Volume, select your Network Volume.
Note: The folders in the Network Volume are automatically available to ComfyUI when the network volume is configured and attached.
Custom Docker Image
If you prefer to include your models directly in the Docker image, follow these steps:
Fork the Repository:
Fork this repository to your own GitHub account.
Add Your Models in the Dockerfile:
Edit the Dockerfile to include your models:
RUN wget -O models/checkpoints/sd_xl_base_1.0.safetensors https://huggingface.co/stabilityai/stable-diffusion-xl-base-1.0/resolve/main/sd_xl_base_1.0.safetensors
You can also add custom nodes:
RUN git clone https://github.com/<username>/<custom-node-repo>.git custom_nodes/<custom-node-repo>
Build Your Docker Image:
Build the base image locally:
docker build -t <your_dockerhub_username>/runpod-worker-comfy:dev-base --target base --platform linux/amd64 .
Install the NVIDIA Toolkit in Ubuntu:
Follow this guide and create the nvidia runtime.
Enable GPU acceleration on Ubuntu on WSL2:
Follow this guide.
If you already have your GPU driver installed on Windows, you can skip the "Install the appropriate Windows vGPU driver for WSL" step.
Add your user to the docker group to use Docker without sudo:
sudo usermod -aG docker $USER
Once these steps are completed, switch to Ubuntu in the terminal and run the Docker image locally on your Windows computer via WSL:
wsl -d Ubuntu
Testing the RunPod handler
Run all tests: python -m unittest discover
If you want to run a specific test: python -m unittest tests.test_rp_handler.TestRunpodWorkerComfy.test_bucket_endpoint_not_configured
You can also start the handler itself to have the local server running: python src/rp_handler.py
To get this to work you will also need to start "ComfyUI", otherwise the handler will not work.
Local API
For enhanced local development, you can start an API server that simulates the RunPod worker environment. This feature is particularly useful for debugging and testing your integrations locally.
Set the SERVE_API_LOCALLY environment variable to true to activate the local API server when running your Docker container. This is already the default value in the docker-compose.yml, so you can get it running by executing:
docker-compose up
Access the local Worker API
With the local API server running, it's accessible at: localhost:8000
When you open this in your browser, you can also see the API documentation and can interact with the API directly
Access local ComfyUI
With the local API server running, you can access ComfyUI at: localhost:8188
Automatically deploy to Docker hub with GitHub Actions
The repo contains two workflows that publish the image to Docker hub using GitHub Actions:
dev.yml: Creates the image and pushes it to Docker hub with the dev tag on every push to the main branch
release.yml: Creates the image and pushes it to Docker hub with the latest and the release tag. It will only be triggered when you create a release on GitHub
If you want to use this, you should add these secrets to your repository:
Configuration Variable
Description
Example Value
DOCKERHUB_USERNAME
Your Docker Hub username.
your-username
DOCKERHUB_TOKEN
Your Docker Hub token for authentication.
your-token
HUGGINGFACE_ACCESS_TOKEN
Your READ access token from Hugging Face
your-access-token
And also make sure to add these variables to your repository:
Variable Name
Description
Example Value
DOCKERHUB_REPO
The repository on Docker Hub where the image will be pushed.