|
| 1 | +# ComfyUI Integration |
| 2 | + |
| 3 | +The Stability Matrix Inference UI is built on top of ComfyUI's API and WebSocket protocol. Understanding this integration is useful if you want to use ComfyUI's own web interface, use the API directly, or troubleshoot connection issues. |
| 4 | + |
| 5 | +[`Section Overview`](overview.md) | [`Home`](../README.md) |
| 6 | + |
| 7 | +## Table of Contents |
| 8 | + |
| 9 | +- [How Stability Matrix Uses ComfyUI](#how-stability-matrix-uses-comfyui) |
| 10 | +- [ComfyUI as a Standalone Package](#comfyui-as-a-standalone-package) |
| 11 | +- [The ComfyUI Web Interface](#the-comfyui-web-interface) |
| 12 | +- [Custom Nodes](#custom-nodes) |
| 13 | +- [The ComfyUI API and WebSocket](#the-comfyui-api-and-websocket) |
| 14 | + |
| 15 | +--- |
| 16 | + |
| 17 | +## How Stability Matrix Uses ComfyUI |
| 18 | + |
| 19 | +The Inference UI does not replace ComfyUI. It uses ComfyUI as its execution backend. |
| 20 | + |
| 21 | +When you configure a generation tab in Stability Matrix, the app builds a real ComfyUI prompt graph behind the scenes. The inference view models and modules assemble that graph with a node builder, adding the same kinds of nodes you would use manually in ComfyUI: model loaders, text encoders, samplers, VAE encode/decode steps, ControlNet preprocessors, image loaders, tiled VAE nodes, video nodes, and output preview nodes. |
| 22 | + |
| 23 | +In practical terms, that means: |
| 24 | + |
| 25 | +- every generation from the Inference UI is sent to ComfyUI as workflow-style node JSON |
| 26 | +- local input images are uploaded into ComfyUI's input area before execution when needed |
| 27 | +- some auxiliary files are copied into the local ComfyUI package directory when the workflow requires them |
| 28 | +- progress, active-node changes, and preview images are streamed back while the workflow is running |
| 29 | +- final outputs are fetched from ComfyUI after execution finishes, then saved by Stability Matrix with its own project and parameter metadata layered on top |
| 30 | + |
| 31 | +So the relationship is best understood as: Stability Matrix provides a curated native UI, while ComfyUI is the engine actually running the graph. |
| 32 | + |
| 33 | +The reverse is not fully symmetrical. Everything the Inference UI does is representable as a ComfyUI workflow, but not every arbitrary ComfyUI workflow is exposed through the Inference UI's built-in cards and panels. |
| 34 | + |
| 35 | +## ComfyUI as a Standalone Package |
| 36 | + |
| 37 | +ComfyUI is available as an installable package in Stability Matrix's Package Manager. When you launch that package through Stability Matrix, the Inference UI connects to it as its local backend. |
| 38 | + |
| 39 | +By default, the ComfyUI package uses host `127.0.0.1` and port `8188`, and the Inference client connects to `http://127.0.0.1:8188`. If you change the ComfyUI launch arguments inside Stability Matrix, the Inference UI reads those host and port values and connects to the configured address instead. |
| 40 | + |
| 41 | +This matters because the Inference UI is not tied to a hardcoded browser tab or embedded widget. It is a client talking to a running ComfyUI server. If the package is stopped, the Inference UI loses its backend. If the package is restarted, the Inference UI reconnects to that backend. |
| 42 | + |
| 43 | +Stability Matrix also knows when it is talking to a locally managed ComfyUI install. In that case it can: |
| 44 | + |
| 45 | +- upload inputs directly to the local package's `input` folder when needed |
| 46 | +- read outputs from the local `output` directory |
| 47 | +- manage custom-node installs through the package extension system |
| 48 | +- restart the package after extension changes when necessary |
| 49 | + |
| 50 | +## The ComfyUI Web Interface |
| 51 | + |
| 52 | +The Inference UI and the ComfyUI web interface are meant to coexist. |
| 53 | + |
| 54 | +Once the ComfyUI package is running, you can open ComfyUI's own browser-based node graph from the Launch page. That graph editor gives you direct access to the raw workflow layer, which is useful when you want to: |
| 55 | + |
| 56 | +- inspect or modify workflows beyond what the Inference UI currently exposes |
| 57 | +- use custom nodes or advanced graph structures that do not have native Inference UI cards |
| 58 | +- import or build community workflows directly in ComfyUI |
| 59 | +- debug a workflow at the node level |
| 60 | + |
| 61 | +This is one of the main strengths of the integration: you can start with Stability Matrix's simpler native controls, then move into ComfyUI's graph editor when you need lower-level control. |
| 62 | + |
| 63 | +Community and exported ComfyUI workflows are also commonly shared as JSON files. Those can be opened in ComfyUI directly, and they are often the easiest way to exchange complex graphs with other users. |
| 64 | + |
| 65 | +## Custom Nodes |
| 66 | + |
| 67 | +ComfyUI's functionality can be extended with custom nodes, and Stability Matrix is aware of that extension model. |
| 68 | + |
| 69 | +For ComfyUI packages installed through Stability Matrix, custom nodes live in the `custom_nodes` directory. You can install them in two common ways: |
| 70 | + |
| 71 | +- use the Extensions browser in Stability Matrix for the ComfyUI package |
| 72 | +- manually clone a node repository into `custom_nodes` |
| 73 | + |
| 74 | +Stability Matrix's ComfyUI package uses extension manifests for custom-node discovery. On new ComfyUI installs, ComfyUI Manager is also installed automatically through the package setup process, and the accompanying `--enable-manager` launch argument is enabled by default. That gives the ComfyUI side an in-browser extension manager out of the box. |
| 75 | + |
| 76 | +There is also a deeper integration point in the Inference UI itself: when a built workflow declares required Comfy extensions, Stability Matrix checks whether those extensions are already installed before the first batch runs. If required extensions are missing or version-constrained extensions are out of date, Stability Matrix can prompt you to install or update them and then restart the ComfyUI package so the changes take effect. |
| 77 | + |
| 78 | +This does not eliminate the need to understand custom nodes, but it does reduce some of the manual work when a workflow depends on specific ComfyUI extensions. |
| 79 | + |
| 80 | +## The ComfyUI API and WebSocket |
| 81 | + |
| 82 | +For advanced users, the integration is straightforward: Stability Matrix talks to ComfyUI over its normal local API and websocket endpoints. |
| 83 | + |
| 84 | +The main pieces used by Stability Matrix are: |
| 85 | + |
| 86 | +- REST base address: `http://127.0.0.1:8188/` by default |
| 87 | +- `POST /prompt` to submit the generated node graph for execution |
| 88 | +- `POST /interrupt` to cancel a running generation |
| 89 | +- `POST /upload/image` to send input images into ComfyUI |
| 90 | +- `GET /history/{promptId}` to retrieve executed outputs after the prompt finishes |
| 91 | +- `GET /view` to download output images returned by ComfyUI history |
| 92 | +- WebSocket at `ws://127.0.0.1:8188/ws?clientId=...` for live status, running-node changes, progress data, execution errors, and preview-image bytes |
| 93 | + |
| 94 | +In practice, the websocket is what makes the Inference UI feel live. It is how Stability Matrix receives step progress, node execution state, and preview frames while ComfyUI is still working. |
| 95 | + |
| 96 | +The REST side is used for the request-response parts of the workflow: |
| 97 | + |
| 98 | +- upload inputs |
| 99 | +- queue the prompt |
| 100 | +- interrupt if cancelled |
| 101 | +- fetch history and outputs when execution completes |
| 102 | + |
| 103 | +If you are troubleshooting connection issues, those are the paths to keep in mind. If you are building your own automation around a local ComfyUI instance, Stability Matrix is effectively using the same public backend surface that advanced users can script against themselves. |
0 commit comments