Nodes/ComfyUI-Easy-Media/API Workflow Gate
ComfyUI Node

API Workflow Gate

One Workflow for Both the UI and the API, Without the Double Graph

By yolain·Created 3 months ago·Updated about 16 hours ago· 158
API Workflow Gate
  • value
  • VALUE
  • VALUES

The node that answers "is this run coming from the API?"

ComfyUI runs the same workflow two very different ways. When you hit Queue in the UI, ComfyUI executes a graph that includes workflow metadata - your layout, your node positions, the whole serialized document. When an external app or agent calls the /prompt API endpoint with a bare API-format workflow, that metadata is absent. Most of the time you don't care. But if you're shipping one workflow that must behave differently depending on who's calling it - a value that should be injectable via the API but fixed in the UI, a heavy input that should only be evaluated on API runs - you need a way to tell which world you're in.

That's this node. The README frames it as the APIWorkflowGate for APP Mode: use it to make sure only workflows intended for API calls pass through the preceding input items, while normal UI queues start executing from the subsequent nodes and skip the API-only front section.

How it works

The mechanism is two clever tricks working together:

  1. Lazy evaluation. The value input is lazy - ComfyUI doesn't compute it unless the node actually requests it. The node's check_lazy_status looks at the hidden extra_pnginfo: if the execution includes workflow metadata (i.e. it's a UI queue), it returns [], meaning "don't evaluate value at all." The whole upstream subgraph behind value never runs. That's the speed win - a skipped heavy render isn't just gated, it's never queued.
  2. The pass-through. When the run is an API-format workflow (no metadata), it evaluates value and passes it out. Scalars go to the VALUE output; if you hand it a list, the items fan out on the VALUES list output.

The practical shape: the API-only front end of your graph feeds value; everything after the gate is shared. UI runs start at the shared part, API runs start earlier and flow through.

Inputs and outputs

  • value - optional, any type, lazy. The thing only evaluated on API-format executions. It's AnyType, so the README suggests wiring it from a regular string node (there's a known ComfyUI quirk where forced AnyType inputs can fight custom widgets).
  • VALUE - the value, when the run is API-format; None on UI runs.
  • VALUES - a list output; if value is a list, its items come out here.

Setup and where it shines

It ships with the pack (Manager → ComfyUI-Easy-Media, or git clone + restart). No dependencies beyond a normal ComfyUI.

Where people actually use it:

  • Same graph, two front ends. A workflow with an optional API parameter section that must be silent and fast when you hit Queue in the UI.
  • App integrations. You're building an app that posts API workflows; this gate keeps the "app-only" preprocessing out of interactive use.
  • Avoiding wasted work. Because the input is lazy, UI runs skip the upstream nodes entirely - not just "ignore their output" but "never execute them," which is the difference between a snappy UI and a queued-up slug.

The main trap is conceptual rather than mechanical: if you expect the gate to filter values in the UI, it won't - on UI runs both outputs are None/empty, on purpose. It's a routing switch keyed to the run's origin, not a data filter. Wire it with that in mind and it's the cleanest way to make one workflow serve two masters.

CategoryEasyUse/Logic

Inputs (1)

NameTypeDefaultDescription
valueopt*Any input to evaluate only when the execution prompt is API workflow format.

Outputs (2)

NameTypeDescription
VALUE*
VALUES*