Skip to main content

ComfyUI + n8n: Automate AI Image Generation Workflows (2026)

· 7 min read
Yassine El Haddad
Software Developer & Automation Specialist

I build production AI agents, web scrapers, and automation pipelines. Most of what I publish here comes from the actual problems they run into: proxies that get banned, anti-bot stacks that fingerprint your client, RAG that drifts when the underlying data moves. Stack: Python, TypeScript, Go, FastAPI, LangChain, Crawlee, Playwright, deployed on AWS, GCP, and Cloudflare.

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:

EndpointMethodPurpose
/promptPOSTSubmit workflow JSON. Returns { prompt_id, number }.
/history/{prompt_id}GETGet execution status and output file info.
/viewGETFetch generated image by filename and subfolder.
/queueGETList 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:

  1. Webhook — Receives { "prompt": "a red sports car", "style": "cinematic" }.
  2. Code / Set — Build ComfyUI workflow JSON. Inject prompt from webhook body into the appropriate CLIP Text Encode node.
  3. HTTP Request — POST http://comfyui-server:8188/prompt with { "prompt": workflow }.
  4. Extract prompt_id — From response: $json.prompt_id.
  5. Wait — 5–10 seconds (or use a Loop + Wait for smarter polling).
  6. HTTP Request — GET http://comfyui-server:8188/history/{prompt_id}.
  7. IF — Check if outputs exists and status is finished. If not, loop back to Wait.
  8. Extract image path — From outputs → find the Save Image node output → filename, subfolder, type.
  9. HTTP Request — GET http://comfyui-server:8188/view?filename=...&subfolder=...&type=output to fetch image binary.
  10. 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 nodetext = {{ $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

  1. Webhook (POST) — http://your-n8n:5678/webhook/comfyui-gen
  2. Setprompt_text = {{ $json.body.prompt || "a beautiful landscape" }}
  3. Code — Load base workflow JSON (hardcoded or from a previous node). Replace the prompt field. Output { prompt: workflow }.
  4. HTTP Request — POST http://comfyui:8188/prompt, body from Code node. Save prompt_id.
  5. Wait — 8 seconds.
  6. HTTP Request — GET http://comfyui:8188/history/{{ $json.prompt_id }}
  7. IF{{ $json[prompt_id].status?.completed }} is true → continue. Else → back to Wait (or fail after N retries).
  8. Extract — From outputs get filename, subfolder (often empty), type = "output".
  9. HTTP Request — GET http://comfyui:8188/view?filename={{ filename }}&type=output (binary response).
  10. S3 Upload — Or Slack (upload file), or HTTP to your CMS.

Batch Generation

Use n8n's Loop or Split In Batches node:

  1. Webhook receives { "prompts": ["car", "boat", "plane"] }.
  2. Split In Batches — Iterate over $json.prompts.
  3. For each item, run the ComfyUI flow above (build workflow → POST → poll → retrieve).
  4. Merge — Collect all image URLs or binaries.
  5. 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 /prompt returns 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:

  1. Webhooks — Custom webhook trigger.
  2. HTTP — Make a Request: POST to ComfyUI /prompt. Map body from webhook.
  3. HTTP — Poll /history with Repeater until done.
  4. HTTP — GET /view for image.
  5. 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.

Apify Affiliate Banner 728x90Apify Affiliate Banner 728x90Apify Affiliate Banner 300x50Apify Affiliate Banner 300x50
Export from ComfyUI

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.

Frequently Asked Questions

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.

Common mistakes and fixes

ComfyUI API returns 504 or timeout.

GPU may be busy. Increase HTTP timeout in n8n (60–120s). Add retry logic. Ensure ComfyUI is running with --listen.

Image not found in /history response.

Poll /history/{prompt_id} until status is finished. Check outputs in the workflow JSON for correct node IDs. Wait a few seconds between polls.

Dynamic prompt not updating in workflow.

Use n8n expressions {{ $json.prompt }} in the workflow JSON. Ensure the HTTP Request body is built from upstream node data.