diff --git a/README.md b/README.md index dc2389266..c0f058017 100644 --- a/README.md +++ b/README.md @@ -65,6 +65,14 @@ Supports all operating systems and GPU types (NVIDIA, AMD, Intel, Apple Silicon, ## Examples See what ComfyUI can do with the [newer template workflows](https://comfy.org/workflows) or old [example workflows](https://comfyanonymous.github.io/ComfyUI_examples/). +## API + +If you want to automate local ComfyUI runs or integrate it into another tool: + +- `openapi.yaml` documents the newer `/api/*` endpoints, including `POST /api/prompt`, `GET /api/queue`, and `GET /api/jobs/{job_id}`. +- [`script_examples/`](script_examples/README.md) contains small Python examples for the local scripting endpoints and websocket flow. +- In the UI, use `File -> Export (API)` to export the current workflow in API format before sending it to the backend. + ## Features - Nodes/graph/flowchart interface to experiment and create complex Stable Diffusion workflows without needing to code anything. - NOTE: There are many more models supported than the list below, if you want to see what is supported see our templates list inside ComfyUI. diff --git a/script_examples/README.md b/script_examples/README.md new file mode 100644 index 000000000..9985c4f61 --- /dev/null +++ b/script_examples/README.md @@ -0,0 +1,44 @@ +# API Script Examples + +This folder contains small Python examples for driving a local ComfyUI server from code. + +## Files + +- `basic_api_example.py`: submits a workflow exported from `File -> Export (API)`. +- `websockets_api_example.py`: submits a workflow, waits for completion over websocket, and then fetches generated images from history. +- `websockets_api_example_ws_images.py`: streams image bytes directly through the websocket with `SaveImageWebsocket` instead of saving files to disk first. + +## What These Examples Use + +These scripts target the local scripting routes exposed by `server.py`: + +- `POST /prompt` +- `GET /history/{prompt_id}` +- `GET /queue` +- `GET /view` +- `GET /ws` + +For the newer documented REST API, see [`openapi.yaml`](../openapi.yaml). In particular: + +- `POST /api/prompt` +- `GET /api/queue` +- `GET /api/jobs/{job_id}` + +## Usage Notes + +1. Start ComfyUI locally, which defaults to `127.0.0.1:8188`. +2. Load or create a workflow in the UI. +3. Export the workflow with `File -> Export (API)`. +4. Replace the sample `prompt_text` in one of these scripts with the exported JSON if needed. +5. Make sure the referenced models and nodes are available in your local ComfyUI install. + +## Dependencies + +- `basic_api_example.py` uses only the Python standard library. +- The websocket examples also require `websocket-client`. + +Install it with: + +```bash +pip install websocket-client +```