ComfyUI: Deploy workflows as APIs¶
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.
To address the deployment challenges, the BentoML team developed comfy-pack, a comprehensive toolkit that transforms ComfyUI workflows into production-grade APIs. Specifically, comfy-pack enables you to:
Define standardized API schemas for workflow inputs and outputs
Serve workflows as HTTP endpoints accessible via standard API clients
Deploy workflows to BentoCloud with enterprise-grade features such as fast autoscaling and built-in observability
Package the complete workspace as portable artifacts for consistent reproduction
Installation¶
You can install comfy-pack using either ComfyUI Manager or Git.
Open ComfyUI Manager.
Search for
comfy-pack
and click Install.Click Restart and refresh your ComfyUI interface to apply changes.
Clone the repository into your ComfyUI custom nodes directory:
cd ComfyUI/custom_nodes
git clone https://github.com/bentoml/comfy-pack.git
Specify input and output nodes¶
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:
Right-click anywhere on the blank space.
Navigate to Add Node > ComfyPack > input, then select the desired input node type:
Image Input: Accepts image type input, similar to the official
LoadImage
node.String Input: Accepts string type input (e.g., prompts).
Int Input: Accepts integer type input (e.g., dimensions, seeds).
File Input: Accepts file type input.
Any Input: Accepts combo type and other input (e.g., custom nodes).
Connect the comfy-pack input node to the widget you converted previously.
To add a comfy-pack output node:
Right-click anywhere on the blank space.
Navigate to Add Node > ComfyPack > output, then select the desired output node type:
File Output: Outputs a file path as a string and saves the file to the specified location.
Image Output: Outputs an image, similar to the official
SaveImage
node.
Connect the workflow’s output to the comfy-pack output node.
Run the workflow to ensure it functions as expected.
Serve workflows as APIs¶
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: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 }'
comfy-pack uses BentoML as its serving framework, allowing you to use the BentoML Python client for interaction:
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.
Deploy to BentoCloud¶
You can deploy your ComfyUI workflow to BentoCloud for better management and scalability.
On the toolbar at the top of the screen, click Deploy.
In the dialog that appears, set a name and select required models and system packages.
Enter your BentoCloud access token. If you don’t have a BentoCloud account, sign up for free and create a token.
Click Push to Cloud and wait for your Bento to be built.
Once it’s ready, click Deploy Now to open the Bento details page on BentoCloud.
Deploy the Bento from the BentoCloud console.
Package and restore a workspace¶
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¶
On the toolbar at the top of the screen, click Package.
Set a name for the package.
(Optional) Choose which models to include. Note that only model hashes are stored, not the actual files. This keeps package size minimal while ensuring version accuracy.
Click Pack. Your browser will automatically download a
.cpack.zip
file.
Restore a workspace¶
Install comfy-pack CLI:
pip install comfy-pack
Unpack the
.cpack.zip
file:comfy-pack unpack <workflow_name>.cpack.zip
When unpacking, comfy-pack restores the original ComfyUI workspace by performing the following steps:
Prepares a Python virtual environment with the exact packages used in the workflow.
Clones the specific ComfyUI version and custom nodes, pinned to the exact versions required by the workflow.
Searches for and downloads models from common registries like Hugging Face and Civitai. It uses symbolic links for efficient model sharing (i.e., models are downloaded only once and reused across workflows) and verifies model integrity via hash checking.