ComfyUI + n8n: Automate AI Image Generation Workflows (2026)
Trigger ComfyUI from n8n, generate images, and send them to Slack, S3, or your CMS. No manual clicking. This guide covers the ComfyUI API mode, building n8n workflows with HTTP Request nodes, dynamic prompts, batch generation, error handling, and the Make.com alternative. ComfyUI must be running with --listen to accept API requests — see ComfyUI on a cloud GPU for setup.
The use case: Webhook receives a request → n8n builds the ComfyUI workflow JSON → POST to ComfyUI /prompt → poll /history until done → retrieve image → upload to S3 → notify Slack. All without touching the ComfyUI UI. For no-code users, Make.com offers a similar flow with HTTP modules.
Try Make.com for automation → | Apify for data pipelines →
ComfyUI API Mode
ComfyUI exposes a REST API when started with --listen:
python main.py --listen
Key endpoints:
| Endpoint | Method | Purpose |
|---|---|---|
/prompt | POST | Submit workflow JSON. Returns { prompt_id, number }. |
/history/{prompt_id} | GET | Get execution status and output file info. |
/view | GET | Fetch generated image by filename and subfolder. |
/queue | GET | List queued prompts. |
The workflow JSON is the same structure ComfyUI uses internally — a graph of nodes with unique IDs and connections. You can export it from the ComfyUI UI (Save API Format) and use it as a template.
n8n Workflow Overview
Full flow:
- Webhook — Receives
{ "prompt": "a red sports car", "style": "cinematic" }. - Code / Set — Build ComfyUI workflow JSON. Inject
promptfrom webhook body into the appropriate CLIP Text Encode node. - HTTP Request — POST
http://comfyui-server:8188/promptwith{ "prompt": workflow }. - Extract prompt_id — From response:
$json.prompt_id. - Wait — 5–10 seconds (or use a Loop + Wait for smarter polling).
- HTTP Request — GET
http://comfyui-server:8188/history/{prompt_id}. - IF — Check if
outputsexists and status is finished. If not, loop back to Wait. - Extract image path — From
outputs→ find the Save Image node output →filename,subfolder,type. - HTTP Request — GET
http://comfyui-server:8188/view?filename=...&subfolder=...&type=outputto fetch image binary. - S3 / Slack / CMS — Upload or send the image.
Building Dynamic Prompts
The ComfyUI workflow JSON has a structure like:
{
"3": {
"class_type": "CLIPTextEncode",
"inputs": {
"text": "a red sports car, cinematic lighting",
"clip": ["4", 1]
}
}
}
Node "3" is the prompt. In n8n, use an expression to inject the webhook payload:
- Set node —
text={{ $json.body.prompt }} - Code node — Load a template from a variable or file, then
template.3.inputs.text = $input.first().json.body.prompt
Return the modified workflow as the body for the ComfyUI HTTP Request.
Full n8n Workflow Description
- Webhook (POST) —
http://your-n8n:5678/webhook/comfyui-gen - Set —
prompt_text={{ $json.body.prompt || "a beautiful landscape" }} - Code — Load base workflow JSON (hardcoded or from a previous node). Replace the prompt field. Output
{ prompt: workflow }. - HTTP Request — POST
http://comfyui:8188/prompt, body from Code node. Saveprompt_id. - Wait — 8 seconds.
- HTTP Request — GET
http://comfyui:8188/history/{{ $json.prompt_id }} - IF —
{{ $json[prompt_id].status?.completed }}is true → continue. Else → back to Wait (or fail after N retries). - Extract — From
outputsgetfilename,subfolder(often empty),type= "output". - HTTP Request — GET
http://comfyui:8188/view?filename={{ filename }}&type=output(binary response). - S3 Upload — Or Slack (upload file), or HTTP to your CMS.
Batch Generation
Use n8n's Loop or Split In Batches node:
- Webhook receives
{ "prompts": ["car", "boat", "plane"] }. - Split In Batches — Iterate over
$json.prompts. - For each item, run the ComfyUI flow above (build workflow → POST → poll → retrieve).
- Merge — Collect all image URLs or binaries.
- Respond — Return list of generated images.
Error Handling
- Timeout — ComfyUI can take 30–120s per image. Set HTTP timeout to 120s. For polling, use a maximum retry count (e.g. 15 × 8s = 2 min).
- GPU busy — ComfyUI may queue. If
/promptreturns 503 or times out, retry with exponential backoff. - Invalid workflow — ComfyUI returns 400 with error details. Log the response and fail the workflow gracefully.
Add an Error Trigger workflow to catch failures and notify via Slack or email.
Alternative: Make.com
The same pattern works in Make.com:
- Webhooks — Custom webhook trigger.
- HTTP — Make a Request: POST to ComfyUI
/prompt. Map body from webhook. - HTTP — Poll
/historywith Repeater until done. - HTTP — GET
/viewfor image. - Slack / Google Drive / Airtable — Upload or store.
Make.com has a 30-second execution limit per module; use a webhook callback or a dedicated "poll ComfyUI" scenario to avoid timeouts on long runs. Both n8n and Make support Apify for web scraping; you can feed scraped product names or descriptions into your prompt for batch asset generation. For example: scrape product titles from a catalog, loop each through ComfyUI, and output a generated hero image per product.
Extend your automation with n8n advanced workflows for Code nodes, sub-workflows, and Apify integration. Compare n8n vs Make vs Zapier 2026 to choose the right platform for your team. For ComfyUI server setup, see ComfyUI on a cloud GPU.
Use "Save (API Format)" in ComfyUI to get the workflow JSON. Use it as your n8n template. Replace only the prompt text (and optionally size, steps) with dynamic values.
In ComfyUI, use Save (API Format) or the dev tools to export the current graph as JSON. That JSON is the prompt body. Replace the CLIP Text Encode node's text input with your dynamic prompt.
ComfyUI does not have a built-in webhook. You must poll /history/{prompt_id} until the run completes. In n8n, use a Loop node with Wait between polls.
n8n: no execution time limit, Code node for complex JSON building, self-hostable. Make: simpler for non-devs, 30s module limit may require splitting into multiple scenarios. Both work.
Yes. Inject them into the workflow JSON the same way as the prompt. Find the KSampler node and set steps, cfg_scale, width, height from your webhook or Set node.
Ensure ComfyUI is running with --listen. If n8n is in Docker, use the host network or the container name (e.g. comfyui:8188) for internal calls. Check firewall allows port 8188.




