Switch Node

This tutorial workflow demonstrates how to use ComfyUI's ComfySwitchNode to route between two inputs with a simple boolean toggle. It includes two focused examples: Example 1 - String Selection shows how to switch between two prompt strings using PrimitiveString and PrimitiveStringMultiline, previewing the active choice with PreviewAny. Example 2 - LoRA Switch shows how to toggle a LoRA on and off around a base model: UNETLoader loads Z-Image-Turbo, LoraLoaderModelOnly applies a selected LoRA, and a ComfySwitchNode chooses either the plain UNet (on_false) or the LoRA-modified UNet (on_true) to feed the generation node.

Under the hood, ComfySwitchNode exposes four pins: on_false, on_true, switch (boolean), and output. When the switch is OFF (false), the output forwards whatever is connected to on_false; when ON (true), it forwards on_true. The workflow wires these switches to real tasks. The text switch selects a single prompt string used downstream, and the LoRA switch controls whether a LoRA weight is applied to the Z-Image-Turbo UNet before image generation. A SaveImage node captures results for easy A/B comparison, and MarkdownNote blocks explain the routing inline. The generation path uses Z-Image-Turbo via UNETLoader and a generation node (ID 0f79b7f9-d214-4587-b475-bc429519b976) that consumes the chosen model and prompt to render images.

API

Use this workflow from code

Every Comfy workflow is a JSON graph. The payload below is this workflow, exactly as ComfyUI runs it — fetch it from the URL, keep it in version control, or load it in ComfyUI and run it node by node.

basic_switch_node.json
Fetching workflow JSON…

Run it from TypeScript or Python with the Comfy SDK. The same code targets Comfy Cloud or a ComfyUI you host yourself — only the base URL changes.

// Install (beta)
npm i @comfyorg/sdk

// Run "Switch Node" (TypeScript)
import { Comfy } from "@comfyorg/sdk";

const client = new Comfy({ apiKey: "comfyui-..." });

// This workflow, exported in API format (see note below)
const wf = await client.workflows.fromFile("basic_switch_node_api.json");

const job = await client.run(wf);
await job.getOutputs("63")[0].toFile("output.png"); // SaveImage

The SDK takes a workflow in API format: open this workflow in ComfyUI and use File → Export Workflow (API).

Comfy Cloud API access requires a plan with an API key.

FAQ

Frequently Asked Questions

View all workflows
Showing 30 of 30 templates