This repository has been archived on 2026-10-21 . You can view files and clone it. You cannot open issues or pull requests or push a commit.
2f64f3c80ccef542750b6211a66d8f78fbd47119
External API Custom Node
REST API endpoints for executing ComfyScript workflows with YAML-based UI schemas.
Full documentation: See DOCUMENTATION.md for complete API reference, WebSocket events, and JavaScript examples.
Quick Start
# List workflows
curl http://localhost:8188/imagelab/workflows
# Get workflow parameters (with resolved options)
curl http://localhost:8188/imagelab/workflow/basic_sdxl/parameters
# Execute workflow
curl -X POST http://localhost:8188/imagelab/workflow/basic_sdxl \
-H "Content-Type: application/json" \
-d '{
"prompt": "a beautiful sunset",
"negativePrompt": "blurry",
"checkpoints": ["model.safetensors"],
"seed": 42,
"steps": 20,
"width": 1024,
"height": 1024,
"cfg": 8.0
}'
Structure
external-api/
├── __init__.py # Entry point, registers routes
├── __main__.py # CLI entry point
├── cli.py # CLI commands (generate, validate, list, watch)
├── schema_generator.py # YAML schema generation
├── workflows.py # Workflow registry and discovery
├── routes.py # API endpoint definitions
├── resources.py # Model discovery and indexing
├── progress.py # WebSocket progress broadcasting
├── parameters.py # Shared Annotated type definitions
├── base.py # BaseWorkflow class
└── workflows/
├── basic_sdxl.py # Workflow code
├── basic_sdxl.yaml # Auto-generated UI schema
└── ...
Adding New Workflows
- Create
workflows/my_workflow.py:
from pydantic import BaseModel, Field
from comfy_script.runtime import *
load('http://127.0.0.1:8188/')
from comfy_script.runtime.nodes import *
import sys, os
sys.path.insert(0, os.path.dirname(os.path.dirname(__file__)))
from base import BaseWorkflow
from parameters import Prompt, Seed, Checkpoint, Width, Height
WORKFLOW_METADATA = {
"name": "My Workflow",
"description": "Description here.",
"model_types": ["SDXL"],
"category": "Image Generation",
}
class WorkflowParams(BaseModel):
prompt: Prompt
seed: Seed
checkpoints: Checkpoint
width: Width = 1024
height: Height = 1024
steps: int = Field(default=20, ge=1, le=150)
class MyWorkflow(BaseWorkflow):
def run(self):
with Workflow(wait=False):
model, clip, vae = self.load_checkpoints()
# ... workflow logic
preview = PreviewImage(image)
return {'prompt_id': preview.task.prompt_id, 'status': 'queued'}
def run_workflow(**kwargs):
return MyWorkflow(WorkflowParams(**kwargs)).run()
- Generate the YAML schema:
python -m external-api generate my_workflow
- Customize the generated
workflows/my_workflow.yamlas needed.
CLI Commands
# Generate schemas
python -m external-api generate --all
python -m external-api generate basic_sdxl
python -m external-api generate basic_sdxl --dry-run
# Validate schemas
python -m external-api validate --all
# List workflows
python -m external-api list
# Watch mode (auto-regenerate on changes)
pip install watchdog
python -m external-api watch
API Endpoints
| Endpoint | Method | Description |
|---|---|---|
/imagelab/workflows |
GET | List all workflows |
/imagelab/workflow/{name}/metadata |
GET | Get workflow metadata |
/imagelab/workflow/{name}/parameters |
GET | Get UI parameter schema |
/imagelab/workflow/{name} |
POST | Execute workflow |
/imagelab/resources |
GET | Get all resources |
/imagelab/resources/{type} |
GET | Get resources by type |
/imagelab/resources/{type}/index/{file} |
POST | Index a model file |
/imagelab/hello |
GET | Test endpoint |
WebSocket Events
Connect to ws://127.0.0.1:8188/ws for real-time updates:
| Event | Code | Description |
|---|---|---|
| Progress | 100 | Sampler step progress |
| Preview | 101 | Preview images |
| Workflow | 102 | Lifecycle events |
Dependencies
pydantic- Parameter validationpyyaml- YAML schema fileswatchdog(optional) - Watch mode
Languages
Python
100%