Three HTTP calls on your own ComfyUI server
ComfyUI is a server as well as an editor. The same process that serves the node UI accepts HTTP requests, so any workflow you can run by clicking Queue you can also run from code. It needs a running ComfyUI instance with the models and custom nodes the workflow uses.
- Export the workflow in API format: in current ComfyUI choose Export (API) from the workflow menu (older versions: enable dev mode and use Save (API Format)). The file maps node ids to class_type and inputs, which is the format the server accepts.
- Queue it: POST {"prompt": <the API-format JSON>, "client_id": "<any id>"} to http://127.0.0.1:8188/prompt. The response carries a prompt_id.
- Change inputs in code first: edit the node values in the JSON (for example the text of a CLIPTextEncode node or the seed of a KSampler node) before you send it.
- Wait for the run: poll GET /history/{prompt_id} until it has outputs, or listen on the /ws WebSocket for the executing message with node null.
- Download the images: each output lists a filename, subfolder and type; GET /view with those three values returns the file.