ComfyUI Workflow Runner via Replicate API - n8n Workflow

Automate complex ComfyUI generation tasks using this asynchronous n8n workflow. Integrate Replicate API for AI generation, status polling, and robust error handling using various n8n node types.

Workflow Preview

Ready to automate?

Download this n8n workflow template and start using it instantly.

Who is this best for?


  • AI developers or MLOps engineers needing to integrate advanced image generation models (ComfyUI) into applications.

  • Users looking for a ready-to-use n8n templates to handle long-running API jobs with polling logic.

  • Automation specialists seeking to deploy a scalable n8n workflow for custom AI service orchestration.

  • Anyone who needs a robust n8n node setup for interacting with the Replicate platform.

Overview

Executing long-running AI generation jobs can be complex due to the requirement for continuous status polling. This comprehensive n8n workflow template solves this challenge by providing a production-ready automation pipeline for running custom ComfyUI workflows via the Replicate API (fofr/any-comfyui-workflow).

Starting with a manual n8n trigger, the system securely initializes the Replicate prediction, logs the request, and then enters a sophisticated polling loop. This loop intelligently uses the If n8n node and Wait n8n node to check the job status every 5 to 10 seconds, ensuring that resources are not wasted. When the job is complete, the n8n workflow handles success or failure gracefully, providing a structured JSON response. This advanced use of the n8n node structure makes this a powerful addition to any developer's collection of n8n templates.

How it Works

The process begins with the Manual Trigger n8n trigger. First, the 'Set API Token' n8n node securely defines your Replicate authentication key, ensuring it's available for subsequent HTTP requests. Next, the 'Set Other Parameters' n8n node configures all necessary inputs for the ComfyUI model, such as workflowjson, outputformat, and randomise_seeds.

The 'Create Other Prediction' n8n node, an HTTP Request n8n node, sends the initial POST request to Replicate, starting the AI generation process and receiving a prediction ID. This ID is immediately logged by the 'Log Request' n8n node for tracking.

Following a brief 'Wait 5s' n8n node delay, the 'Check Status' HTTP Request n8n node starts the polling loop, querying Replicate for the job's current state. The 'Is Complete?' If n8n node checks if the status is 'succeeded'. If successful, the 'Success Response' n8n node formats the output URL and metadata. If not, the 'Has Failed?' If n8n node checks for a 'failed' status, resulting in an 'Error Response' n8n node. If the job is still running, the n8n workflow routes the execution to the 'Wait 10s' n8n node, which delays execution before returning to the 'Check Status' n8n node, completing the intelligent retry logic. Finally, the 'Display Result' n8n node presents the final outcome of this automated n8n workflow.

Installation Guide


  1. Import the n8n workflow: Copy the provided JSON data and paste it into your n8n instance using the 'New' -> 'Import from JSON' option.

  2. Obtain Replicate Credentials: Sign up for an account on Replicate and generate your API token.

  3. Configure API Token: Locate the 'Set API Token' n8n node. Replace the placeholder value YOURREPLICATEAPITOKEN with your actual Replicate API key.

  4. Set Input Parameters: Review the 'Set Other Parameters' n8n node. Adjust settings like inputfile, outputformat, and most importantly, provide your ComfyUI workflow JSON string in the workflowjson field.

  5. Activate and Test: Activate the n8n workflow. Click the 'Manual Trigger' n8n trigger to initiate a test run and verify the connections and polling mechanism. This robust n8n templates setup is now ready for deployment.

Node Details


  • Manual Trigger: The starting n8n trigger for this n8n workflow, allowing manual execution for testing or integration via an external call if converted to a webhook.

  • Set API Token (Set n8n node): Stores the sensitive Replicate API key as a variable (apitoken) for secure use throughout the n8n workflow.

  • Set Other Parameters (Set n8n node): Aggregates all model-specific configuration parameters (like workflowjson, outputquality) before the API call.

  • Create Other Prediction (HTTP Request n8n node): Sends the initial POST request to api.replicate.com to queue the ComfyUI generation job, setting the Authorization header using the apitoken variable from the previous n8n node.

  • Log Request (Code n8n node): A custom n8n node snippet used for logging prediction IDs and timestamps, aiding in debugging and monitoring the n8n workflow's performance.

  • Wait 5s / Wait 10s (Wait n8n node): Implements necessary delays in the polling loop to prevent excessive API calls while waiting for the AI job to complete.

  • Check Status (HTTP Request n8n node): Continuously polls the Replicate endpoint using the job's ID to check the current status (starting, running, succeeded, or failed).

  • Is Complete? / Has Failed? (If n8n node): These critical flow control n8n node components manage the asynchronous logic, routing the execution path based on the job status received from Replicate.

  • Success Response / Error Response (Set n8n node): Structure the final output, providing clear, actionable JSON data detailing either the result URL or the failure reason for this n8n workflow.

Related n8n Workflows

Free

Nodes: 7 Nodes
Updated: December 26 2025
View all
Created by

Building AI Agents and Automations | Growth Marketer | Entrepreneur | Book Author & Podcast Host If you need any help with Automations, feel free to reach out via linkedin: https://www.linkedin.com/in/yaronbeen/ And check out my Youtube channel: https://www.youtube.com/@YaronBeen/videos

Featured*