added new documentation

This commit is contained in:
donny committed 2026-01-05 15:28:08 -07:00
1 parent 971e180775
commit 2f4bca6e78
2 files changed
+817 -1236

No files matched your search

+695 -1131
View File
File diff suppressed because it is too large. Load diff
+122 -105
View File
@@ -1,130 +1,147 @@
# External API Custom Node
REST API endpoints for executing ComfyScript workflows.
REST API endpoints for executing ComfyScript workflows with YAML-based UI schemas.
> **Full documentation:** See [DOCUMENTATION.md](DOCUMENTATION.md) for complete API reference, WebSocket events, and JavaScript examples.
## Quick Start
```bash
# 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 # Main entry point, registers routes
├── progress.py # Progress hook utilities
├── __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
├── workflows.py # Workflow registry
└── workflows/ # Individual workflow scripts
├── test.py
└── example_image_gen.py
├── 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
1. Create a new file in `workflows/` folder (e.g., `my_workflow.py`)
2. Define a `run_workflow(**kwargs)` function
3. Import and register it in `workflows.py`:
1. Create `workflows/my_workflow.py`:
```python
# In workflows.py
my_workflow = load_workflow_module("my_workflow")
from pydantic import BaseModel, Field
from comfy_script.runtime import *
load('http://127.0.0.1:8188/')
from comfy_script.runtime.nodes import *
WORKFLOWS = {
"my_workflow": my_workflow.run_workflow,
# ... other workflows
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()
```
2. Generate the YAML schema:
```bash
python -m external-api generate my_workflow
```
3. Customize the generated `workflows/my_workflow.yaml` as needed.
## CLI Commands
```bash
# 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
### List Available Workflows
| 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 |
```
GET /external-api/workflows
```
## WebSocket Events
### Execute Workflow
Connect to `ws://127.0.0.1:8188/ws` for real-time updates:
```
POST /external-api/workflow/{workflow_name}
Content-Type: application/json
| Event | Code | Description |
| -------- | ---- | --------------------- |
| Progress | 100 | Sampler step progress |
| Preview | 101 | Preview images |
| Workflow | 102 | Lifecycle events |
{
"prompt": "a beautiful landscape",
"steps": 20,
"seed": 12345
}
```
## Dependencies
### Test Endpoint
```
GET /external-api/hello
```
## Example Usage
```bash
# List workflows
curl http://localhost:8188/external-api/workflows
# Execute test workflow
curl -X POST http://localhost:8188/external-api/workflow/test_workflow \
-H "Content-Type: application/json" \
-d '{"prompt": "test", "steps": 10}'
```
## Workflow Template
Each workflow file should follow this pattern:
```python
def run_workflow(**kwargs):
"""
Your workflow description.
Args:
**kwargs: Workflow parameters
Returns:
dict: Result with status and output
"""
from comfy_script.runtime import *
load('http://127.0.0.1:8188/')
from comfy_script.runtime.nodes import *
# Your workflow logic here
with Workflow(wait=True) as wf:
# ... nodes ...
pass
return {
'status': 'completed',
'output': result
}
```
## Javascript Examples
Cancel a specific job by prompt_id
```Javascript
const axios = require('axios');
let data = JSON.stringify({
"prompt_id": "f244551d-3dff-4390-a7b5-1491bbe42409"
});
let config = {
method: 'post',
maxBodyLength: Infinity,
url: 'http://localhost:8188/interrupt',
headers: {
'Content-Type': 'application/json'
},
data : data
};
axios.request(config)
.then((response) => {
console.log(JSON.stringify(response.data));
})
.catch((error) => {
console.log(error);
});
```
- `pydantic` - Parameter validation
- `pyyaml` - YAML schema files
- `watchdog` (optional) - Watch mode