ComfyUI API Endpoints Guide: Complete Reference for Image Generation Workflows

Introduction

ComfyUI is a powerful, open-source, node-based interface for generative AI workflows, majorly for image and video workflows.

While it’s primarily known for its visual interface, ComfyUI also offers robust API capabilities, enabling developers to integrate and automate workflows programmatically. This guide will walk you through using ComfyUI in API mode.

ComfyUI offers a suite of RESTful and WebSocket API endpoints that enable developers to programmatically interact with its workflow engine. These endpoints facilitate tasks such as queuing prompts, retrieving results, uploading images, and monitoring system status.

🧰 Setting Up ComfyUI for API Access

1. Installation

Begin by cloning the ComfyUI repository and installing the necessary dependencies:

git clone https://github.com/comfyanonymous/ComfyUI.git
cd ComfyUI
pip install -r requirements.txt

2. Running ComfyUI

Start the ComfyUI server

python main.py

Before you start, you will need the workflow_api.json file. You can download it from ComfyUI by following these steps:

  • Enable dev mode options in the ComfyUI settings
  • Export your API JSON using the “Save (API format)” button.

🧩 Core ComfyUI API Endpoints

1. WebSocket Endpoint

  • Endpoint: /ws
  • Method: WebSocket
  • Description: Establishes a WebSocket connection for real-time updates, including status changes, progress, and execution events.

2. Queue Prompt

  • Endpoint: /prompt
  • Method: POST
  • Description: Queues a workflow for execution. The request body should include the prompt (workflow definition) and client_id.

3. Retrieve Prompt History

  • Endpoint: /history/{prompt_id}
  • Method: GET
  • Description: Fetches the execution history and results for a specific prompt ID.

4. View Generated Images

  • Endpoint: /view
  • Method: GET
  • Description: Retrieves images based on filename, subfolder, and type (input, output, or temp).

5. Upload Images or Masks

  • Endpoint: /upload/{image_type}
  • Method: POST
  • Description: Uploads images or masks to ComfyUI. The {image_type} can be image or mask. The request should include the image data and specify the target folder.

📋 Queue and History Management

6. Get Current Queue

  • Endpoint: /queue
  • Method: GET
  • Description: Retrieves the current state of the queue, including running and pending prompts.

7. Interrupt Execution

  • Endpoint: /interrupt
  • Method: POST
  • Description: Interrupts the execution of the currently running prompt.

8. Delete Items from Queue or History

  • Endpoint: /queue or /history
  • Method: POST
  • Description: Deletes specific items from the queue or history. The request body should specify the IDs of the items to delete.

9. Clear Queue or History

  • Endpoint: /queue or /history
  • Method: POST
  • Description: Clears all items from the queue or history. The request body should include a flag indicating the clear action.

⚙️ System and Configuration Endpoints

10. System Statistics

  • Endpoint: /system_stats
  • Method: GET
  • Description: Provides system and device statistics, such as Python version, operating system, and device information.

11. User Configuration

  • Endpoint: /users
  • Method: GET or POST
  • Description: Retrieves or creates user configuration data.

12. Settings Management

  • Endpoints:
    • Get All Settings: /settings (GET)
    • Get Specific Setting: /settings/{id} (GET)
    • Update Settings: /settings (POST)
    • Update Specific Setting: /settings/{id} (POST)
  • Description: Manages user-specific settings, allowing retrieval and updates of configuration parameters.

🧠 Workflow and Node Information

13. Node Definitions

  • Endpoint: /object_info
  • Method: GET
  • Description: Retrieves definitions of available nodes, including their inputs, outputs, and parameters.

14. Extensions

  • Endpoint: /extensions
  • Method: GET
  • Description: Lists available extensions that can be integrated into workflows.

15. Embeddings

  • Endpoint: /embeddings
  • Method: GET
  • Description: Retrieves a list of available embeddings for use in workflows.

📁 User Data Management

16. User Data Files

  • Endpoints:
    • Get User Data: /userdata/{file} (GET)
    • Store User Data: /userdata/{file} (POST)
  • Description: Manages user-specific data files, allowing retrieval and storage of custom data

These endpoints provide a robust interface for integrating ComfyUI into various applications and workflows.

You can install a custom node like ComfyUI-load-image-from-url, to send image URL that is publically available, and you can send base64 image back in the API response.

https://github.com/tsogzark/ComfyUI-load-image-from-url

You can check this code to see, how the comfyui frontend talks to comfyui backend

https://github.com/Comfy-Org/ComfyUI_frontend/blob/3d4ac079572c39434d3f54213f9f4039d73485b5/src/scripts/api.ts#L709

Leave a comment