Comfy UI Workflow

Use Cinna's SDK to execute ComfyUI workflows such as text-to-video generation and image upscaling, all coordinated through decentralized GPUs and verified on Solana.


Introduction

ComfyUI is an open-source visual interface that supports advanced generative tasks like text-to-image, image-to-image, and text-to-video. Cinna’s SDK simplifies interaction with ComfyUI by abstracting away node graph logic and exposing clean functions in a Node.js environment. This lets developers run visual workflows on distributed GPU infrastructure with minimal setup.


Supported Workflows

The following ComfyUI workflows are currently supported through the Cinna SDK:

  • Text to Video Generation Convert descriptive prompts into short video clips using diffusion-based models

  • Image Upscaling Enhance low-resolution images while preserving detail and visual clarity


Core Concepts

Each ComfyUI process is represented as a WorkflowTask. The SDK includes a base class that handles all shared functionality. Individual workflows extend this base and define specific input requirements.


Before You Begin

  1. Obtain your Cinna API key

  2. Add the following to your .env file:

envCopy codeCINNA_API_KEY=your_api_key
CINNA_WORKFLOW_URL=https://sequencer-v2.cinna.ai

WorkflowTask Structure

Each task uses a JSON definition of the ComfyUI node graph. You can define unique workflows by subclassing the base class.

Base Class

tsCopy codeabstract 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

tsCopy codeinterface WorkflowTaskOptions {
  consumer_id?: string
  job_id_prefix?: string
  timeout_seconds?: number
  workflow_id?: string
  api_key?: string
}

Task Result Type

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

Available Functions

Execute a workflow Submits the workflow task for execution.

tsCopy codeasync executeWorkflow(task: WorkflowTask): Promise<string>

Returns the task ID.


Query a task result Checks the status or output of a submitted task.

tsCopy codeasync queryTaskResult(task_id: string): Promise<WorkflowTaskResult>

Returns the current state and result.


Execute and wait for result Runs the task and polls until the result is ready.

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

Cancel a task Stops a running task before completion.

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

Last updated