🚀 ComfyuiGW: ComfyUI API Gateway

ComfyuiGW is a RESTful API Gateway designed specifically for running ComfyUI version of Stable Diffusion Sketch. It provides a robust interface for executing complex workflows through both API endpoints and a user-friendly web interface.
✨ Key Features
- REST API Gateway - Execute ComfyUI workflows via simple HTTP requests
- Web Interface - User-friendly form-based workflow execution (
/runflow)
- Real-time Progress Tracking - Monitor workflow execution with live updates
- File Management - Automatic handling of images, videos, and audio files
- Workflow Configuration - Simple JSON-based workflow definition
- Preset Management - Create reusable configurations with json files
- Cross-platform Support - Works on Windows and Linux systems
🛠️ Installation
Windows Setup
- Install ComfyUI
- Install required custom nodes for your workflows, e.g.:
cd ComfyUI/custom_nodes
git clone https://github.com/ltdrdata/ComfyUI-Manager
git clone https://github.com/kijai/ComfyUI-Florence2
git clone https://github.com/pythongosssss/ComfyUI-Custom-Scripts
git clone https://github.com/kijai/ComfyUI-KJNodes
git clone https://github.com/WASasquatch/was-node-suite-comfyui
git clone https://github.com/BlenderNeko/ComfyUI_ADV_CLIP_emb
git clone https://github.com/jamesWalker55/comfyui-various
git clone https://github.com/Fannovel16/comfyui_controlnet_aux
- Clone this repository:
git clone https://github.com/your-repo/ComfyuiGW
- Update
COMFYUI_PATH in run.bat (Windows) or run.sh (Linux)
- Start the server:
run.bat # Windows
./run.sh # Linux
📦 Adding a Workflow
- Create or download a ComfyUI workflow JSON file
- Place it in a subdirectory under
workflows/ (e.g., workflows/my_workflow/)
- Create
workflows.config.json:{
"workflow_name_api": {
"prompt_workflow": "your_workflow.json",
"fields": {
"param1": "15.inputs.param1",
"param2": ["16.inputs.input1", "16.inputs.input2"]
},
"inputs": {
"param1": {"type": "text", "default": "value"},
"param2": {"type": "integer", "default": 10}
}
}
}
- Create
mode.config.json for preset configurations (in Stable Diffusion Sketch app):[
{
"name": "ModeName",
"title": "Display Name",
"showT2I": true,
"show": true,
"configurable": true,
"default": {"param1": "value"},
"fields": {
"workflow": "workflow_name",
"param1": "fixed_value"
}
}
]
🌐 Using the Web Interface
Access http://localhost:5000/runflow to execute workflows through a convenient form-based interface:
- Select Workflow - Choose from available workflows
- Fill Parameters - Provide inputs via text fields and file uploads
- Submit & Monitor - Track real-time progress with step-by-step updates
- Retrieve Results - Find output in
ComfyUI/output directory
🤖 Agent / Programmatic Access
The gateway serves its own documentation, so a remote agent on the LAN can learn the API without
access to this repository.
Start at http://<host>:5000/, which indexes every entry point. In particular:
| Path |
Purpose |
/agent_guide |
Agent Integration Guide rendered as HTML |
/agent_guide.md |
The same guide as raw Markdown |
/api/workflows |
JSON map of every workflow → accepted payload keys, input/output flags |
/api/endpoints |
JSON inventory of all routes |
/openapi.json, /docs |
FastAPI-generated schema and Swagger UI |
The guide documents the full lifecycle (submit → poll /comfyui_status until progress == "Done"
→ fetch outputs → download), the JSON and multipart entry points, and the non-obvious behaviours
that commonly break clients: a single global job slot, the exact _api suffix rules, raw (non-data:)
base64 for image fields, and the file_url field that is emitted but not routable.
A ready-to-use Python client is included in the guide (see its §8).
🧩 Project Structure
ComfyuiGW/
├── comfyui_server.py # Main server implementation
├── docs/
│ └── AGENT_API_GUIDE.md # Agent integration guide (served at /agent_guide.md)
├── run.bat # Windows launch script
├── run.sh # Linux launch script
├── requirements.txt # Python dependencies
├── workflows/ # Workflow configurations
│ ├── workflows.config.json # Workflow form template
│ ├── mode.config.json # Workflow list template
│ └── my_ComfyUI_workflow.json # Your custom ComfyUI workfiles API json
├── inputs/ # Uploaded input files
├── templates/ # Web interface templates
│ ├── index.html # Landing page
│ ├── agent_guide.html # Rendered agent guide
│ ├── runflow_form.html # Workflow form template
│ ├── runflow_list.html # Workflow list template
│ └── workflow_progress.html # Progress tracking
└── mode_config.json # Global mode configurations
📚 Configuration Files
workflows.config.json
Defines workflow mappings and API parameters with the following structure:
{
"workflow_name": {
"prompt_workflow": "filename.json",
"fields": {
"param1": "16.inputs.param1",
"param2": ["15.inputs.input1", "15.inputs.input2"]
},
"inputs": {
"param1": {"type": "text", "default": "default value"},
"param2": {"type": "integer", "default": 10}
}
}
}
Parameter Descriptions:
- workflow_name: Unique identifier for the workflow (used in API calls)
- prompt_workflow: Path to the ComfyUI workflow JSON file
- fields: Maps API parameters to workflow node inputs:
- Key: API parameter name
- Value: Target node input(s) in format
"node_id.inputs.param_name" (string for single input, array for multiple inputs)
- descriptions: (Optional) Description to be show in
runflow web interface:
- inputs: (Optional) JSON object which defines
runflow parameters:
- type: Data type (text, string, integer, float, array, image, video, audio)
- default: Default value if not provided
mode.config.json
Defines preset configurations for workflows:
{
"name": "ModeName",
"title": "Display Name",
"showT2I": true,
"show": true,
"configurable": true,
"default": {"param1": "value", "param2": 0.5},
"fields": {
"workflow": "workflow_name",
"param1": "fixed_value",
"param2": "$variable"
}
}
Parameter Descriptions:
- name: Internal mode identifier (alphanumeric, no spaces)
- title: Display name shown in UI
- showT2I: Show in text-to-image section (true/false)
- show: Enable/disable mode visibility (true/false)
- configurable: Allow parameter customization in UI (true/false)
- default: Default values for configurable parameters
- fields: Fixed parameters passed to workflow:
- workflow: Required - references workflow_name from workflows.config.json
- Additional fields: Fixed values or variables (prefixed with $, filled by app) to pass to workflow
⚙️ System Requirements
- Python 3.8+
- ComfyUI installation
- Custom nodes (listed in Installation)
⁉️ Support
For issues and feature requests, please open an issue on GitHub.
ComfyuiGW simplifies ComfyUI workflow execution through a well-designed API gateway and web interface, making complex image and video processing workflows accessible to both developers and end-users.
评论