> For the complete documentation index, see [llms.txt](https://xalora-ai.gitbook.io/xalora-ai-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://xalora-ai.gitbook.io/xalora-ai-docs/comfyui-workflow.md).

# ComfyUI Workflow

Execute ComfyUI workflows such as image upscaling and video generation.

## [​](https://docs.heurist.ai/dev-guide/heurist-sdk/comfyui-workflow#introduction)Introduction <a href="#introduction" id="introduction"></a>

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. Xalora 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](https://github.com/XaloraAI/Xalora-sdk/tree/main/packages/workflow)

## [​](https://docs.heurist.ai/dev-guide/heurist-sdk/comfyui-workflow#available-workflows)Available Workflows <a href="#available-workflows" id="available-workflows"></a>

The SDK currently supports the following ComfyUI workflows:

* Text to Video Generation - Generate videos from text descriptions
* Image Upscaling - Upscale images while maintaining quality

## [​](https://docs.heurist.ai/dev-guide/heurist-sdk/comfyui-workflow#core-concepts)Core Concepts <a href="#core-concepts" id="core-concepts"></a>

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.

## [​](https://docs.heurist.ai/dev-guide/heurist-sdk/comfyui-workflow#before-you-start)Before you start <a href="#before-you-start" id="before-you-start"></a>

1. Get an API key
2. Define environment variables in `.env` file:

Copy

```
XALORA_API_KEY=your_api_key
XALORA_WORKFLOW_URL=https://sequencer-v2.xalora.xyz
```

## [​](https://docs.heurist.ai/dev-guide/heurist-sdk/comfyui-workflow#data-structures)Data Structures <a href="#data-structures" id="data-structures"></a>

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.

### [​](https://docs.heurist.ai/dev-guide/heurist-sdk/comfyui-workflow#base-class)Base Class <a href="#base-class" id="base-class"></a>

Copy

```
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>;
}
```

### [​](https://docs.heurist.ai/dev-guide/heurist-sdk/comfyui-workflow#task-option-type)Task Option Type <a href="#task-option-type" id="task-option-type"></a>

Copy

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

### [​](https://docs.heurist.ai/dev-guide/heurist-sdk/comfyui-workflow#task-result-type)Task Result Type <a href="#task-result-type" id="task-result-type"></a>

Copy

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

## [​](https://docs.heurist.ai/dev-guide/heurist-sdk/comfyui-workflow#functions)Functions <a href="#functions" id="functions"></a>

### [​](https://docs.heurist.ai/dev-guide/heurist-sdk/comfyui-workflow#execute-a-workflow)Execute a workflow <a href="#execute-a-workflow" id="execute-a-workflow"></a>

Executes a workflow task without waiting for the result.

Copy

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

Returns a Promise that resolves to the task ID.

### [​](https://docs.heurist.ai/dev-guide/heurist-sdk/comfyui-workflow#query-the-task-result)Query the task result <a href="#query-the-task-result" id="query-the-task-result"></a>

Queries the result of a previously executed task.

Copy

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

Returns a Promise that resolves to the task result.

### [​](https://docs.heurist.ai/dev-guide/heurist-sdk/comfyui-workflow#execute-a-workflow-and-wait-for-the-result)Execute a workflow and wait for the result <a href="#execute-a-workflow-and-wait-for-the-result" id="execute-a-workflow-and-wait-for-the-result"></a>

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.

Copy

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

### [​](https://docs.heurist.ai/dev-guide/heurist-sdk/comfyui-workflow#cancel-a-task)Cancel a task <a href="#cancel-a-task" id="cancel-a-task"></a>

Cancels a previously submitted task.

Copy

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

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