Open the example workflow
Make a copy of this workflow in your account to follow along.
How it works
Code nodes run on Runchat’s servers, not in your browser. So Runchat has to reach ComfyUI over the public internet.localhost:8188 on your PC is not reachable from there.
The example workflow has three inputs and two code nodes:
Images come back as data URLs, which Runchat uploads automatically. They render on the node and can connect to any image input downstream.
1. Give ComfyUI a public hostname
Pick the option that matches where ComfyUI runs.- Local PC (tunnel)
- Vast.ai / RunPod
- Port forwarding
The easiest and safest option is a Cloudflare quick tunnel. You don’t need an account or router changes, and you don’t have to open a port.
- Install
cloudflared(downloads) - With ComfyUI running, start a tunnel to it:
- Copy the
https://….trycloudflare.comURL it prints. That’s your server URL.
2. Export your workflow in API format
ComfyUI has two JSON formats. Runchat needs the API one.- In ComfyUI, open the workflow you want to run and check that it works there
- Choose Workflow → Export (API) to save the
.jsonfile - Paste its contents into the Workflow (API format) input node
- Replace the positive prompt text with
$prompt. It can sit inside a longer string, e.g."$prompt, golden hour, 35mm" - Replace the seed value with
"$seed"(as a string, including the quotes) to get a new random seed on every run
v1-5-pruned-emaonly-fp16.safetensors checkpoint. Change ckpt_name to a model you have installed.
3. Run it
Select Get images and click Run. Runchat runs Queue prompt first, then waits for the result. Get images waits up to about 50 seconds, because code nodes time out after 60. If your workflow takes longer, the node stops with Still generating. ComfyUI keeps working, so run Get images on its own again to collect the images. That doesn’t queue a new job.The GPU time is yours, so ComfyUI runs cost no model credits. Each
fetch() a code node makes costs 1 credit: one to queue, one per status check (the node backs off from 2 to 8 seconds between checks), and one per image downloaded. A typical 20-second generation uses about 5 credits plus the node run cost.Adding authentication
ComfyUI has no login, so anyone who has your URL can queue jobs and see your outputs. A quick-tunnel URL is hard to guess and only lives while the tunnel runs. That’s fine for a working session, but don’t post it anywhere. For a server that stays up, put ComfyUI behind a proxy that checks a token. Your provider may already do this, or you can set up Cloudflare Access, Caddy or nginx. Then store the token as a credential, with its allowed origin set to your server URL, and send it from both code nodes:Authorization header to the /history and /view requests in Get images. Or select the code nodes and ask the agent to do it.
Troubleshooting
Going further
Select either code node and ask the agent to extend it. For example:- Image-to-image: upload an input image to ComfyUI’s
/upload/imageendpoint and set its filename on aLoadImagenode - More parameters: add inputs for steps, CFG or resolution and substitute them the same way as
$prompt - Publish as a tool: publish the workflow so the agent can call your ComfyUI setup directly from chat
Next steps
- Code node: the sandbox, inputs and outputs
- Credentials: store tokens for your server securely
- Text-to-image ideation: compare your local models against hosted ones