π Lazy API Switch (Bypass)
The node that stops your API node from running at all
- cached_data
- api_data
- final_output
Everything else in the ComfyUI-API-Optimizer pack saves you money indirectly. This is the node that actually stops the bleeding. On a cache hit it physically prevents your upstream API node from executing - not "fast-forwards past it," not "reuses a copy" - the API node never runs, so you're never charged and you never wait on its latency. That's the whole point of the Hash Vault suite, and this is the switch that makes it pay off.
The lazy trick
ComfyUI normally evaluates a node as soon as its inputs are ready. This node opts out. Its two data sockets are declared with {"lazy": True}, and it implements check_lazy_status, a hook that tells ComfyUI which inputs to actually bother evaluating. On a cache hit it demands only cached_data; on a miss it demands only api_data. ComfyUI respects that, so the branch you didn't demand simply never executes.
That's why the wiring makes or breaks the pack. Your API node sits upstream of the api_data socket. When the switch doesn't demand it, the entire branch stays idle - the API node doesn't run, the Save node doesn't run, nothing upstream of that socket moves. The result you already paid for comes back from disk instead.
Inputs and outputs
is_cached(required, INT) - the verdict from Hash Vault (Check Cache). 1 routes the cached copy, 0 routes the fresh API result.cached_data- the stored result, wired from Check Cache'scached_dataoutput.api_data- the live result, wired from your API node's output.final_output(output) - whichever branch won, continuing downstream to your Save Image / Preview / next step.
The sandwich, one more time
- Fan your prompt/image to both Check Cache and the API node.
- Check Cache's
is_cachedβ the switch'sis_cached. - API node's output β Hash Vault (Save Result), with the
hash_keyfrom Check Cache. - Both Check Cache's
cached_dataand Save Result'sapi_outputβ the switch's two data sockets. final_outputβ wherever you were going.
First run: miss, the switch demands api_data, the API executes, Save Result banks it. Second run: hit, cached_data is routed, and the API branch never wakes up. Two runs, one API charge.
Gotchas
Don't reroute the save around the switch. Hash Vault (Save Result) deliberately is not an output node, so it only runs when the switch demands its branch. If you connect the API output straight to a preview node, the whole lazy mechanism is moot - ComfyUI will run the API node every time because something downstream actually needs it. The switch has to sit in the path.
Cache hit but the API still runs? Then is_cached wasn't 1. A changed input means a miss by design - that's the hash being strict, not the switch being broken. Also make sure cached_data is really wired: the switch is defensive about a hit with no cached data, but you don't want to rely on that path.
Install
Part of the ComfyUI-API-Optimizer pack. ComfyUI Manager: search "ComfyUI API Optimizer". Or:
cd ComfyUI/custom_nodes/
git clone https://github.com/jeremieLouvaert/ComfyUI-API-Optimizer.git
pip install -r ComfyUI-API-Optimizer/requirements.txt
Restart ComfyUI. Just filelock on top of your existing PyTorch - nothing else, no models.
Inputs (3)
| Name | Type | Default | Description |
|---|---|---|---|
| is_cached | INT | β | |
| cached_dataopt | * | β | |
| api_dataopt | * | β |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| final_output | * | β |