mirror of
https://github.com/comfyanonymous/ComfyUI.git
synced 2026-06-26 17:59:54 +08:00
| .. | ||
| basic_api_example.py | ||
| README.md | ||
| websockets_api_example_ws_images.py | ||
| websockets_api_example.py | ||
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 fromFile -> 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 withSaveImageWebsocketinstead of saving files to disk first.
What These Examples Use
These scripts target the local scripting routes exposed by server.py:
POST /promptGET /history/{prompt_id}GET /queueGET /viewGET /ws
For the newer documented REST API, see openapi.yaml. In particular:
POST /api/promptGET /api/queueGET /api/jobs/{job_id}
Usage Notes
- Start ComfyUI locally, which defaults to
127.0.0.1:8188. - Load or create a workflow in the UI.
- Export the workflow with
File -> Export (API). - Replace the sample
prompt_textin one of these scripts with the exported JSON if needed. - Make sure the referenced models and nodes are available in your local ComfyUI install.
Dependencies
basic_api_example.pyuses only the Python standard library.- The websocket examples also require
websocket-client.
Install it with:
pip install websocket-client