Connect your local ComfyUI installation to the AI Power Grid network and run it as a distributed image generation worker.
- Bridge: Receives image-generation jobs from AI Power Grid.
- Worker: Executes jobs via your local ComfyUI instance.
- Return: Uploads generated images back to the network.
This allows you to contribute GPU cycles to a decentralized AI rendering network while leveraging your local ComfyUI setup.
- Auto-detects installed ComfyUI model checkpoints and maps them to AI Power Grid model names.
- Customizable: override advertised models via
GRID_MODEL(supports comma-separated lists). - Workflow templating: use your own ComfyUI
.jsonworkflow files. - Async, multi-threaded job polling and processing.
- Python 3.9+
- ComfyUI running locally (default:
http://127.0.0.1:8000). - AI Power Grid account + API key: https://dashboard.aipowergrid.io
# 1. Clone the repo
git clone https://github.com/youruser/comfy-bridge.git
cd comfy-bridge
# 2. Create & activate a virtual environment
python -m venv venv
# macOS/Linux
source venv/bin/activate
# Windows
venv\Scripts\activate
# 3. Install dependencies
pip install -e .Copy the example .env and adjust values:
# .env
GRID_API_KEY=your_powergrid_api_key # required
GRID_WORKER_NAME=MyComfyWorker.APIG_Wallet # optional
COMFYUI_URL=http://127.0.0.1:8000 # optional
GRID_API_URL=https://api.aipowergrid.io/api # optional
GRID_NSFW=false # allow NSFW? true/false
GRID_THREADS=2 # concurrent jobs
GRID_MAX_PIXELS=1048576 # max output resolution (pixels)
GRID_MODEL=stable_diffusion, Flux.1-Krea-dev Uncensored (fp8+CLIP+VAE) # comma-separated model names
WORKFLOW_FILE=my_workflow.json # ComfyUI JSON export templateGRID_MODELsupports one or more model keys (comma-separated). If unset, the bridge auto-detects from your ComfyUI checkpoints.WORKFLOW_FILEpoints to a JSON workflow in yourworkflows/directory.
Start your ComfyUI web server, then:
# Via CLI module
python -m comfy_bridge.cliOr directly (legacy):
start_bridge.pyThe bridge will:
- Register as a worker with AI Power Grid.
- Poll for jobs every few seconds.
- Render in ComfyUI.
- Submit results back to the network.
-
Build the Docker image:
docker build -t comfy-bridge . -
Run the container:
-
Linux (host networking):
docker run --rm --network host --env-file .env comfy-bridge
-
macOS/Windows (using
host.docker.internal):docker run --rm \ -v "$(pwd)/workflows:/app/workflows" \ --env-file .env \ -e COMFYUI_URL=http://host.docker.internal:8000 \ comfy-bridge
-
Linux
Build & run:
docker-compose -f docker-compose.linux.yml up --buildmacOS/Windows
Build & run:
docker-compose -f docker-compose.win-macos.yml up --buildAll core modules include unit and async tests. To run them:
pytestTests use pytest-asyncio for async routines and respx for HTTP mocking.
- No jobs found? Check
Advertising models:log; ensureGRID_MODELis set or your checkpoints match default mappings. - 400 Bad Request: unrecognized models—verify model key names or adjust
GRID_MODEL. - ComfyUI unreachable: confirm
COMFYUI_URLand that the server is running. - API auth errors: verify
GRID_API_KEYand network access.
Logs are printed at INFO (bridge flow) and DEBUG (detailed payloads) levels. Adjust via:
import logging
logging.basicConfig(level=logging.DEBUG)This project is licensed under the MIT License - see the LICENSE file for details.
- AI Power Grid (https://aipowergrid.io) - For the API
- ComfyUI (https://github.com/comfyanonymous/ComfyUI) - For the local image generation backend
- httpx, aiohttp, pytest, pytest-asyncio ❤️