RepoReplicateReplicatepublished Jan 12, 2024seen 5d

replicate/cog-comfyui

Python

Open original ↗

Captured source

source ↗
published Jan 12, 2024seen 5dcaptured 13hhttp 200method plain

replicate/cog-comfyui

Description: Run ComfyUI with an API

Language: Python

License: MIT

Stars: 768

Forks: 197

Open issues: 61

Created: 2024-01-12T10:47:54Z

Pushed: 2025-11-03T18:54:57Z

Default branch: main

Fork: no

Archived: no

README:

cog-comfyui

Run ComfyUI workflows on Replicate:

  • https://replicate.com/comfyui/any-comfyui-workflow
  • https://replicate.com/comfyui/any-comfyui-workflow-a100

We recommend:

  • trying it on the website with your favorite workflow and making sure it works
  • using your own instance to run your workflow quickly and efficiently on Replicate (see the guide below)
  • using the production ready Replicate API to integrate your workflow into your own app or website

What’s included

We've tried to include many of the most popular model weights and custom nodes:

Raise an issue to request more custom nodes or models, or use the train tab on Replicate to use your own weights (see below).

How to use

1. Get your API JSON

You’ll need the API version of your ComfyUI workflow. This is different to the commonly shared JSON version, it does not included visual information about nodes, etc.

To get your API JSON:

1. Turn on the "Enable Dev mode Options" from the ComfyUI settings (via the settings icon) 2. Load your workflow into ComfyUI 3. Export your API JSON using the "Save (API format)" button

https://private-user-images.githubusercontent.com/319055/298630636-e3af1b59-ddd8-426c-a833-808e7f199fac.mp4

2. Gather your input files

If your model takes inputs, like images for img2img or controlnet, you have 3 options:

Use a URL

Modify your API JSON file to point at a URL:

- "image": "/your-path-to/image.jpg",
+ "image": "https://example.com/image.jpg",

Upload a single input

You can also upload a single input file when running the model.

This file will be saved as input.[extension] – for example input.jpg. It'll be placed in the ComfyUI input directory, so you can reference in your workflow with:

- "image": "/your-path-to/image.jpg",
+ "image": "image.jpg",

Upload a zip file or tar file of your inputs

These will be downloaded and extracted to the input directory. You can then reference them in your workflow based on their relative paths.

So a zip file containing:

- my_img.png
- references/my_reference_01.jpg
- references/my_reference_02.jpg

Might be used in the workflow like:

"image": "my_img.png",
...
"directory": "references",

3. Using custom LoRAs from CivitAI or HuggingFace

You can use LoRAs directly from CivitAI, HuggingFace, or any other URL in two ways:

Option 1: Use the LoraLoader node with a URL

Use the direct download URL as the lora_name:

{
"inputs": {
"lora_name": "https://huggingface.co/username/model/resolve/main/lora.safetensors",
...
},
"class_type": "LoraLoader"
}

Option 2: Use the LoraLoaderFromURL node

Alternatively, use the dedicated LoraLoaderFromURL node from ComfyUI-GlifNodes:

{
"inputs": {
"url": "https://civitai.com/api/download/models/1163532",
// ...
},
"class_type": "LoraLoaderFromURL"
}

Both methods work the same way - the standard LoraLoader will automatically switch to use LoraLoaderFromURL when it detects a URL in the lora_name field.

Run your workflow

With all your inputs updated, you can now run your workflow.

Example:

# Pass in the workflow JSON as a string
cog predict -i workflow_json="{ ... }"

# Pass in the workflow JSON as a URL
cog predict -i workflow_json="https://example.com/your_workflow.json"

# Pass in the workflow JSON as a file
cog predict -i workflow_json=@your_workflow.json

Some workflows save temporary files, for example pre-processed controlnet images. You can also return these by enabling the return_temp_files option.

How to use your own dedicated instance

The any-comfyui-workflow model on Replicate is a shared public model. This means many users will be sending workflows to it that might be quite different to yours. The effect of this will be that the internal ComfyUI server may need to swap models in and out of memory, this can slow down your prediction time.

ComfyUI and it's custom nodes are also continually being updated. While this means the newest versions are usually running, if there are breaking changes to custom nodes then your workflow may stop working.

If you have your own dedicated instance you will:

  • fix the code and custom nodes to a known working version
  • have a faster prediction time by keeping just your models in memory
  • benefit from ComfyUI’s own internal optimisations when running the same workflow repeatedly

Options for using your own instance

To get the best performance from the model you should run a dedicated instance. You have 3 choices:

1. Create a private deployment (simplest, but you'll need to pay for setup and idle time) 2. Create and deploy a fork using Cog (most powerful but most complex) 3. Create a new model from the train tab (simple, your model can be public or private and you can bring your own weights)

1. Create a private deployment

Go to:

https://replicate.com/deployments/create

Select comfyui/any-comfyui-workflow as the model you'd like to deploy. Pick your hardware and min and max instances, and you're ready to go. You'll be pinned to the version you deploy from. When any-comfyui-workflow is updated, you can test your workflow with it, and then deploy again using the new version.

You can read more about deployments in the Replicate docs:

https://replicate.com/docs/deployments

2. Create and deploy a fork using Cog

You can use this repository as a template to create your own model. This gives you complete control over the ComfyUI version, custom nodes, and the API you'll use to run the model.

You'll need to be familiar with Python, and you'll also need a GPU to push your model using Cog. Replicate has a good getting started guide: https://replicate.com/docs/guides/push-a-model

Example

The kolors model on Replicate is a good example to follow:

  • https://replicate.com/fofr/kolors (The model with it’s customised API)
  • https://github.com/replicate/cog-comfyui-kolors (The new…

Excerpt shown — open the source for the full document.