In Development: This feature is in development. Not ready for use.

Introduction

ComfyUI is an open-source program that allows users to use generative AI such as text-to-image, image-to-image, text-to-video and more through a flexible node-based interface. Heurist SDK abstracts away the complexity of ComfyUI, and provides simple functions in Node.js SDK to execute ComfyUI workflows on distributed GPU miners.

SDK source code

Available Workflows

The SDK currently supports the following ComfyUI workflows:

Core Concepts

Each workflow in ComfyUI is represented by a WorkflowTask. The SDK provides a base class that handles common functionality, which specific workflow implementations extend with their unique requirements.

Data Structures

Each WorkflowTask represents a task of a specific ComfyUI workflow (identified by a JSON workflow file describing the node structures in ComfyUI). A derived class of WorkflowTask is defined for each individual workflow, including necessary input parameters.

Base Class

abstract class WorkflowTask {
  public consumer_id?: string;
  public job_id_prefix?: string;
  public timeout_seconds?: number;
  public workflow_id?: string;
  public api_key?: string;

  constructor(options: WorkflowTaskOptions) {
    this.consumer_id = options.consumer_id;
    this.job_id_prefix = options.job_id_prefix;
    this.timeout_seconds = options.timeout_seconds;
    this.workflow_id = options.workflow_id;
    this.api_key = options.api_key;
  }

  abstract get task_type(): WorkflowTaskType;
  abstract get task_details(): Record<string, any>;
}

Task Option Type

interface WorkflowTaskOptions {
  consumer_id?: string;
  job_id_prefix?: string;
  timeout_seconds?: number;
  workflow_id?: string;
  api_key?: string;
}

Task Result Type

interface WorkflowTaskResult {
  task_id: string
  status: 'waiting' | 'running' | 'finished' | 'failed' | 'canceled'
  result?: any
}

Functions

Execute a workflow

Executes a workflow task without waiting for the result.

async executeWorkflow(task: WorkflowTask): Promise<string>

Returns a Promise that resolves to the task ID.

Query the task result

Queries the result of a previously executed task.

async queryTaskResult(task_id: string): Promise<WorkflowTaskResult>

Returns a Promise that resolves to the task result.

Execute a workflow and wait for the result

Executes a workflow and waits until a result is returned. Internally, this function calls queryTaskResult at a fixed interval, and throws if the task times out.

async executeWorkflowAndWaitForResult(
    task: WorkflowTask,
    timeout: number = 300000,
    interval: number = 10000
  ): Promise<WorkflowTaskResult>

Cancel a task

Cancels a previously submitted task.

async cancelTask(task_id: string): Promise<{ task_id: string; msg: string }>

Returns a Promise that resolves to the task ID and message.