Deploy ComfyUI as a serverless API endpoint with auto-scaling and scale-to-zero cost savings.
2.2K
Run ComfyUI locally with a RunPod-compatible API handler, then deploy to RunPod serverless or GPU pods.
Open Source: This project is open source and welcomes contributions! See CONTRIBUTING.md for guidelines.
docker compose up
First run: Initial startup downloads ComfyUI, installs dependencies with uv (10-100x faster than pip!), and configures models/nodes from config.yml. First run ~2-3 minutes, subsequent runs ~10-30 seconds thanks to volume-first architecture and SHA-based caching.
Open your browser:
Press Ctrl+C to stop.
✅ Lightning-fast package installation - uv package manager (10-100x faster than pip) ✅ Volume-first architecture - Minimal 8.7GB container, everything persists on volume ✅ Universal GPU support - PyTorch 2.9.0 + CUDA 12.8 (RTX 4090, RTX 5090, future GPUs) ✅ Blazing downloads - hf_transfer for HuggingFace (100-200+ MB/s), parallel chunks for others ✅ ComfyUI auto-installs on first run (updateable, persistent) ✅ Full web interface for workflow design ✅ Jupyter Lab for config editing and file management ✅ RunPod-compatible API handler ✅ SHA-based config caching - Skip reinstalls when config unchanged ✅ Works everywhere - Mac, Linux, Windows
🚀 Serverless Endpoints - Auto-scaling production APIs with scale-to-zero 🔧 GPU Pods - Interactive development with Jupyter and SSH access
Deploy ComfyUI as a serverless API endpoint with auto-scaling and scale-to-zero cost savings.
Name: ComfyUI Handler
Container Image: artokun/comfyui-runpod:latest
Container Disk: 20 GB
Environment Variables (Optional - all have defaults):
RUN_MODE=endpoint # Skips Jupyter for fast cold starts
# AUTO_UPDATE=false # (default)
# COMFY_API_URL=http://127.0.0.1:8188 # (default)
Expose HTTP Ports:
Leave blank (API-only)
Or: 8188 (for debugging ComfyUI UI)
comfyui-volumeWhy volume is required:
/runpod-volume/ComfyUI (persistent)Name: comfyui-production
Select Template: ComfyUI Handler
Select Network Volume: comfyui-volume
GPUs:
☑ RTX 4090 (or RTX 5090)
Min Workers: 0
Max Workers: 3
Advanced:
Idle Timeout: 5 seconds
Execution Timeout: 600 seconds
Max Concurrent Requests: 1
export RUNPOD_ENDPOINT_ID="your-endpoint-id"
export RUNPOD_API_KEY="your-api-key"
curl -X POST "https://api.runpod.ai/v2/${RUNPOD_ENDPOINT_ID}/runsync" \
-H "Authorization: Bearer ${RUNPOD_API_KEY}" \
-H "Content-Type: application/json" \
-d @examples/example_request.json
RTX 4090:
RTX 5090:
Tips to reduce costs:
Deploy ComfyUI to RunPod GPU Pods for interactive development with Jupyter notebook access.
Pods are traditional GPU instances with:
Use Pods for: Development, testing, interactive ComfyUI design, experimenting Use Serverless for: Production APIs, auto-scaling, scale-to-zero cost savings
comfyui-volumeContainer Image: artokun/comfyui-runpod:latest
Container Disk: 50 GB
Volume Mount: comfyui-volume → /runpod-volume
Expose HTTP Ports: 8188, 8000, 8888
Environment Variables:
RUN_MODE=production # Enables Jupyter Lab
Once deployed:
Access points:
Pods bill per second while running:
Tip: Stop pods when not in use! Your volume data persists.
The config.yml file controls which models and custom nodes are installed. It's mounted as a volume, so you can edit anytime without rebuilding the Docker image!
Default config: Minimal setup with SD 1.5 + ComfyUI Manager (~4GB) for fast builds.
Advanced example:
See config.example.yml for complete WAN Animate 2.2 setup with 11 models and 20+ nodes (~30GB).
Step 1: Access Jupyter Lab
Step 2: Navigate to config.yml
/runpod-volume/config.yml or /workspace/config.yml/workspace/config.ymlStep 3: Edit and save (Ctrl+S or Cmd+S)
models:
- url: https://huggingface.co/stabilityai/sdxl-vae/resolve/main/sdxl_vae.safetensors
destination: vae
optional: false
nodes:
- url: https://github.com/Kosinkadink/ComfyUI-VideoHelperSuite.git
version: latest
Step 4: Apply changes (see Applying Changes below)
nano config.yml
# or
code config.yml # VS Code
Then restart container:
docker compose restart
For RunPod Endpoints (serverless), set as environment variable:
config.yml fileCONFIG_YML=<base64-encoded-string>
The container automatically decodes and applies on startup!
Configuration Priority:
CONFIG_YML env var → Writes to volume (persistent)config.yml on volume → Can be edited directlyAfter editing config.yml, run the apply script to install new models/nodes without restarting:
Via Jupyter Terminal:
cd /app
chmod +x apply_config.sh
./apply_config.sh
Via Docker:
docker compose exec comfyui /app/apply_config.sh
What it does:
Then restart ComfyUI (custom nodes require restart):
docker compose restartmodels:
- url: https://huggingface.co/model.safetensors
destination: checkpoints # Where to place the model
optional: false # Skip if download fails?
- url: https://civitai.com/api/download/models/123456
destination: loras
optional: true
Supported destinations:
checkpoints - Main model checkpointsvae - VAE modelsloras - LoRA modelscontrolnet - ControlNet modelsclip_vision - CLIP vision modelsembeddings - Text embeddingsupscale_models - Upscaler modelsdiffusion_models - Diffusion modelstext_encoders - Text encoder modelsnodes:
- url: https://github.com/user/repo.git
version: latest # Latest stable release (tag)
- url: https://github.com/user/repo.git
version: nightly # Latest commit (bleeding edge)
- url: https://github.com/user/repo.git
version: v1.2.3 # Specific tag
- url: https://github.com/user/repo.git
version: abc1234 # Specific commit hash
- url: https://github.com/user/repo.git
version: main # Specific branch
Version options:
latest - Latest stable release tag (recommended)nightly - Latest commit on default branchv1.2.3 - Specific version tagabc1234 - Specific commit hashmain - Track a specific branchThe container uses SHA256 hashing to detect config changes:
config.yml, installs everything, stores SHASHA file locations:
/runpod-volume/.config-sha256/workspace/.config-sha256Force reinstall:
rm /runpod-volume/.config-sha256 # RunPod
rm /workspace/.config-sha256 # Local
This dramatically improves RunPod Endpoint cold start performance!
Optional: Enable auto-updates or mount existing models.
cp .env.example .env
# Edit .env file
Auto-Update:
AUTO_UPDATE=true # Update ComfyUI on startup
Models Directory:
MODELS_PATH=/path/to/existing/models # Mount existing models
Jupyter Password:
JUPYTER_PASSWORD=your_secure_password # Enable password protection
If not set, Jupyter Lab is accessible without authentication (default for local development).
Open http://localhost:8188 and create your workflow visually.
workflows/my_workflow.jsoncurl -X POST http://localhost:8000/runsync \
-H "Content-Type: application/json" \
-d @examples/example_request.json
Or with Python:
import requests
import json
with open('examples/example_request.json') as f:
response = requests.post('http://localhost:8000/runsync', json=json.load(f))
print(response.json())
./deploy.sh
Same workflows work immediately in production!
# Start services (with logs)
docker compose up
# Start in background
docker compose up -d
docker compose logs -f # View logs
# Stop services
docker compose down
# Rebuild after changes
docker compose up --build
# Test locally without Docker
python examples/test_local.py
# Build for RunPod
./build.sh
# Deploy to production
./deploy.sh
Container: Minimal shell (~8.7GB) with CUDA runtime + system dependencies only Volume: All Python packages, PyTorch, ComfyUI, models, custom nodes (persistent)
Why?
How it works:
PIP_TARGET=/workspace/python-packages (volume)This project uses uv (https://github.com/astral-sh/uv), a Rust-based pip replacement that's 10-100x faster:
Your downloads will fly at 100-200+ MB/s instead of the old 15 MB/s with pip!
Configure via RUN_MODE environment variable:
development (default local) - ComfyUI + Handler + Jupyter Labproduction (RunPod Pods) - ComfyUI + Handler + Jupyter Labendpoint (RunPod Serverless) - ComfyUI + Handler only (skips Jupyter for fast cold starts)Universal Image - One image for all modern NVIDIA GPUs:
No architecture-specific builds needed!
Expected generation times on RTX 4090:
RTX 5090 is 40-60% faster when available.
Download speeds:
{
"input": {
"workflow": { /* ComfyUI workflow in API format */ },
"overrides": [
{
"node_id": "6",
"field": "inputs.text",
"value": "a beautiful sunset"
},
{
"node_id": "3",
"field": "inputs.seed",
"value": 42
}
]
}
}
{
"status": "success",
"prompt_id": "abc-123",
"execution_time": 8.32,
"images": [
{
"url": "http://127.0.0.1:8188/view?filename=ComfyUI_00001.png",
"filename": "ComfyUI_00001.png"
}
]
}
comfy-template/
├── README.md # This file
├── CLAUDE.md # Project instructions for Claude Code
├── docker-compose.yml # Run with: docker compose up
├── Dockerfile # Universal GPU support (all in one!)
├── .env.example # Configuration template
│
├── handler.py # RunPod worker logic
├── s3_upload.py # S3 upload module
├── requirements.txt # Python dependencies
├── start.sh # Container startup script
├── entrypoint.sh # Entrypoint script
├── test_input.json # Local test input for RunPod SDK
│
├── build.sh # Build production image
├── deploy.sh # Deploy to Docker Hub
├── download_models.py # Model downloader
├── install_nodes.py # Custom nodes installer
├── apply_config.sh # Apply config changes without restart
├── config.yml # Unified configuration (models + nodes)
│
├── workspace/ # Persistent workspace (local dev)
│ └── ComfyUI/ # Auto-created on first run
│ ├── main.py # ComfyUI application
│ ├── models/ # Model files
│ ├── custom_nodes/ # Custom nodes
│ └── output/ # Generated images
│
├── docs/ # Documentation
└── examples/ # Examples and testing
├── example_workflow.json
├── example_request.json
└── test_local.py
Local Development:
Production:
# Test GPU access
nvidia-smi
docker run --rm --gpus all nvidia/cuda:12.0.0-base-ubuntu22.04 nvidia-smi
# Find what's using port 8188
lsof -i :8188 # Mac/Linux
netstat -ano | findstr "8188" # Windows
# Clean build
docker compose build --no-cache
Check pod logs:
The scripts use:
If still slow, check your network connection.
Common causes:
Check error messages for details.
See examples/ directory for:
We welcome contributions! Please see CONTRIBUTING.md for details on:
# Fork and clone the repo
git clone https://github.com/YOUR-USERNAME/comfyui-runpod-handler.git
cd comfyui-runpod-handler
# Install development dependencies
pip install -r requirements-dev.txt
# Install pre-commit hooks
pre-commit install
# Run tests
pytest
# Start development environment
docker compose up
See CONTRIBUTING.md for detailed instructions.
This project is licensed under the MIT License - see the LICENSE file for details.
Special thanks to all contributors who have helped improve this project!
Content type
Image
Digest
sha256:a7224f855…
Size
3 GB
Last updated
11 months ago
docker pull artokun/comfyui-runpod