docs/source/examples/comfyui.rst
ComfyUI <https://github.com/comfyanonymous/ComfyUI>_ is a powerful tool for designing advanced diffusion workflows. It provides an extensive collection of resources, including shared workflows and custom nodes, to help creative workers and developers generate content without dealing with complex code. However, deploying and serving these workflows as scalable API endpoints can be complex and non-intuitive <https://www.bentoml.com/blog/comfy-pack-serving-comfyui-workflows-as-apis>_.
To address the deployment challenges, the BentoML team developed comfy-pack <https://github.com/bentoml/comfy-pack>_, a comprehensive toolkit that transforms ComfyUI workflows into production-grade APIs. Specifically, comfy-pack enables you to:
You can install comfy-pack using either ComfyUI Manager <https://github.com/ltdrdata/ComfyUI-Manager>_ or Git.
.. tab-set::
.. tab-item:: ComfyUI Manager (Recommended)
1. Open **ComfyUI Manager**.
2. Search for ``comfy-pack`` and click **Install**.
.. image:: ../../_static/img/examples/comfyui/install-comfy-pack-via-comfyui-manager.png
:alt: Install comfy-pack via ComfyUI Manager
3. Click **Restart** and refresh your ComfyUI interface to apply changes.
.. tab-item:: Git
Clone the repository into your ComfyUI custom nodes directory:
.. code-block:: bash
cd ComfyUI/custom_nodes
git clone https://github.com/bentoml/comfy-pack.git
When serving ComfyUI workflows as APIs, one key challenge is establishing a standardized schema for workflow inputs and outputs. comfy-pack addresses this by providing dedicated interface nodes that integrate seamlessly with existing workflows without affecting their core functionality.
Right-click a node containing the widget you want to expose.
Select Convert Widget to Input, then choose the widget name.
To add a comfy-pack input node:
a. Right-click anywhere on the blank space.
b. Navigate to Add Node > ComfyPack > input, then select the desired input node type:
LoadImage node.Connect the comfy-pack input node to the widget you converted previously.
.. image:: ../../_static/img/examples/comfyui/add-comfy-pack-input-node.gif :alt: Add comfy-pack input node
To add a comfy-pack output node:
a. Right-click anywhere on the blank space.
b. Navigate to Add Node > ComfyPack > output, then select the desired output node type:
SaveImage node.Connect the workflow's output to the comfy-pack output node.
.. image:: ../../_static/img/examples/comfyui/add-comfy-pack-output-node.gif :alt: Add comfy-pack output node
Run the workflow to ensure it functions as expected.
You can expose ComfyUI workflows as HTTP APIs that can be called from any client.
On the toolbar at the top of the screen, click Serve.
Set the desired port (default: 3000).
Click Start to launch the server. The API will be available at http://127.0.0.1:<port>.
The server exposes a /generate endpoint. Use it to submit requests with parameters configured through comfy-pack nodes (e.g., prompt, width, height, seed). For example:
.. tab-set::
.. tab-item:: CURL
.. code-block:: bash
curl -X 'POST' \
'http://127.0.0.1:3000/generate' \
-H 'accept: application/octet-stream' \
-H 'Content-Type: application/json' \
--output output.png \
-d '{
"prompt": "rocks in a bottle",
"width": 512,
"height": 512,
"seed": 1
}'
.. tab-item:: Python client
comfy-pack uses BentoML as its serving framework, allowing you to use the :doc:`BentoML Python client </build-with-bentoml/clients>` for interaction:
.. code-block:: python
import bentoml
with bentoml.SyncHTTPClient("http://127.0.0.1:3000") as client:
result = client.generate(
prompt="rocks in a bottle",
width=512,
height=512,
seed=1
)
.. important::
Parameter names in API calls must match your comfy-pack node names.
You can deploy your ComfyUI workflow to BentoCloud for better management and scalability.
sign up for free <https://www.bentoml.com/>_ and :doc:create a token </scale-with-bentocloud/manage-api-tokens>.You can package a ComfyUI workspace into a portable artifact, ensuring it can be easily transferred and unpacked elsewhere with consistent behavior.
Create a package ^^^^^^^^^^^^^^^^
.cpack.zip file.Restore a workspace ^^^^^^^^^^^^^^^^^^^
Install comfy-pack CLI:
.. code-block:: bash
pip install comfy-pack
Unpack the .cpack.zip file:
.. code-block:: bash
comfy-pack unpack <workflow_name>.cpack.zip
When unpacking, comfy-pack restores the original ComfyUI workspace by performing the following steps: