ComfyICU API Documentation

Take your custom ComfyUI workflows to production. Run ComfyUI workflows using our easy-to-use REST API. Focus on building next-gen AI experiences rather than on maintaining own GPU infrastructure.

1

Create API Key

First, you'll need to create an API key. You can do this from your account settings page. Once you have your key, add it to your environment variable like so:

export COMFYICU_API_KEY=XXX
2

Create a workflow

Next, start by creating a workflow on the ComfyICU website. Run a few experiments to make sure everything is working smoothly. Once you're satisfied with the results, open the specific "run" and click on the "View API code" button. You'll need to copy the workflow_id and prompt for the next steps.

const workflow_id = "XXX"

const prompt = {
  // ComfyUI API JSON
}
3

Run the workflow with API

Now, let's run the workflow using the API.

const fetch = require('node-fetch');

async function runWorkflow(workflow_id, prompt, files){
    const url = "https://comfy.icu/api/v1/workflows/"+workflow_id+"/runs"
    const resp = await fetch(url, {
      "headers": {
        "accept": "application/json",
        "content-type": "application/json",
        "authorization": "Bearer " + process.env.COMFYICU_API_KEY
      },
      "body": JSON.stringify({ prompt, files }),
      "method": "POST"
    });

    return await resp.json()
}

const run = await runWorkflow(workflow_id, prompt)
console.log(run)

files parameter is optional. If you don't have any input files, you can simply omit it. Please note, only files saved to /output/ directory are considered as output of a run. Temporary files produced by PreviewImage nodes will not be saved.

4

Check the run status

To check the status of your run, use the following function:

const fetch = require('node-fetch');

async function getRunStatus(workflow_id, run_id) {
    const url = "https://comfy.icu/api/v1/workflows/"+workflow_id+"/runs/"+run_id
    const resp = await fetch(url, {
    "headers": {
        "accept": "application/json",
        "content-type": "application/json",
        "authorization": "Bearer " + process.env.COMFYICU_API_KEY
    }
    });
    return await resp.json()
}

const status = await getRunStatus(workflow_id, run.id)
console.log(status)
5

Add input images and videos

You can use the files field to specify the ComfyUI destination path as key and provide a direct link to download the file as value. Then update the prompt with the same filename.

For example, if you want to load image1.jpg on a Load Image node:

const files = {
  "/input/image1.jpg": "http://public-url-for-assets.com/image1.jpg", // direct link to download the image
  "/input/image2.jpg": "http://public-url-for-assets.com/image2.jpg",
  "/input/video.mp4": "http://public-url-for-assets.com/video.mp4"
}

const prompt = {
    // ComfyUI API JSON
    // ...
    "45": {
      "_meta": {
          "title": "Load Image"
      },
      "inputs": {
          "image": "image1.jpg", // specify the input filename
          "upload": "image"
      },
      "class_type": "LoadImage"
    },
    // ...
}

const run = await runWorkflow(workflow_id, prompt, files)
console.log(run)

All files provided via files will be downloaded to their respective path before the workflow execution begins. The file downloads do not count against your GPU usage. Plus, we cache these files to speed up subsequent executions.

6

Add custom models, loras and embeddings

Just like input files, you can provide custom models via the files field. For example, if you want to use the Thickline lora from Civitai:

const files = {
  // ...
  "/models/loras/thickline_fp16.safetensors": "https://civitai.com/api/download/models/16368?type=Model&format=SafeTensor&size=full&fp=fp16", // direct link to download the lora
  
  // similarly, you can also provide checkpoints, embeddings, VAEs etc by providing right ComfyUI path
  "/models/checkpoints/custom_model.safetensors": "https://...",
  "/models/embeddings/custom_embedding.pt": "https://..."
}

const prompt = {
    // ComfyUI API JSON
    // ...
    "43": {
        "inputs": {
            "clip": [
                "4",
                1
            ],
            "model": [
                "4",
                0
            ],
            "lora_name": "thickline_fp16.safetensors", // specify the lora filename
            "strength_clip": 1,
            "strength_model": 1
        },
        "class_type": "LoraLoader"
    },
    // ...
}

const run = await runWorkflow(workflow_id, prompt, files)
console.log(run)

Please note, custom models are not currently supported via the web UI. But no worries, you can still use them in your API calls! And there you have it! You're now ready to build and run your custom ComfyUI workflows using our API. Happy coding!

7

Change the GPU accelerator

Add accelerator option in the request body to select from T4, L4, A10, A100_40GB, A100_80GB or H100 GPUs.

async function runWorkflow(workflow_id, prompt, files){
  const url = "https://comfy.icu/api/v1/workflows/"+workflow_id+"/runs"
  const resp = await fetch(url, {
    "headers": {
      "accept": "application/json",
      "content-type": "application/json",
      "authorization": "Bearer " + process.env.COMFYICU_API_KEY
    },
    "body": JSON.stringify({ prompt, files, accelerator: 'A100_40GB' }),
    "method": "POST"
  });

  return await resp.json()
}