Replicate AI Generator Polling Loop - n8n Workflow

Use this comprehensive n8n workflow to automate asynchronous AI image or content generation using Replicate's API. This n8n template implements a robust polling loop for status checks.

Workflow Preview

Ready to automate?

Download this n8n workflow template and start using it instantly.

Who is this best for?


  • Users needing to automate generative AI tasks (like image or video creation) that require time to process.

  • Developers integrating third-party asynchronous APIs like Replicate into their n8n workflow.

  • Anyone looking for robust n8n templates demonstrating advanced control flow and polling logic.

  • Content creators utilizing the ligua033/lorealcantara model.

Overview

Many generative AI services, including Replicate, operate asynchronously. When you request a resource (like an image), the API returns a prediction ID rather than the final output immediately. The challenge is continually checking that ID until the task is complete—a process known as polling.

This specialized n8n workflow solves this problem by implementing a tight polling loop. It initializes the generation request, captures the unique prediction ID, and then uses a combination of the n8n wait node and the n8n if node to repeatedly check the status URL. This ensures your n8n automation waits efficiently and only proceeds once the result is ready, making it a reliable n8n template for complex AI integrations.

How it Works

This n8n workflow operates through a structured sequence designed to manage asynchronous API calls:


  1. Start and Setup: The workflow begins with a Manual Trigger, functioning as the primary n8n trigger. Immediately following, the 'Set API Key' n8n node configures the necessary replicateapikey for subsequent HTTP requests.

  2. Initiate Generation: The 'Create Prediction' HTTP Request n8n node sends a POST request to the Replicate API, initiating the content generation using the specified ligua033/lorealcantara model and input parameters.

  3. Extract ID: The 'Extract Prediction ID' Code n8n node processes the initial response, extracting the crucial prediction ID and constructing the status check URL.

  4. Polling Loop Entry: The n8n workflow enters the polling sequence starting with the 'Wait' n8n node, which pauses execution for 2 seconds to prevent overwhelming the API.

  5. Check Status: The 'Check Prediction Status' HTTP Request n8n node performs a GET request to the prediction URL, fetching the current status (e.g., 'processing', 'succeeded', 'failed').

  6. Conditional Check: The 'Check If Complete' n8n if node evaluates the returned status. If the status is 'succeeded' (True branch), the workflow proceeds to process the output. If the status is anything else (False branch), the n8n template loops back to the 'Wait' node, restarting the 2-second delay and status check until completion.

  7. Final Output: Once 'succeeded', the 'Process Result' Code n8n node formats and outputs the final result, including the generated content URL (the output array from Replicate).

Installation Guide

To deploy this powerful n8n workflow, follow these steps:


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

  2. API Credentials: Locate the 'Set API Key' n8n node. Update the value of replicateapikey with your actual Replicate API key. This key is used dynamically across all subsequent HTTP Request n8n nodes for Bearer token authentication.

  3. Input Configuration: In the 'Create Prediction' n8n node, review and modify the jsonBody parameters (prompt, seed, width, height, lora_scale) to match your desired content specifications.

  4. Activation: Ensure the n8n workflow is active and execute it using the 'On clicking 'execute'' n8n trigger for testing.

Node Details

On clicking 'execute' (Manual Trigger)


  • Function: Acts as the starting n8n trigger for immediate testing and execution of the n8n workflow.

  • Key Configuration: None (Standard manual execution).

Set API Key (Set)


  • Function: Securely defines the replicateapikey variable, making it accessible as a Bearer token across various n8n nodes.

  • Key Configuration: Defines the assignment replicateapikey.

Create Prediction (HTTP Request)


  • Function: Sends the initial asynchronous generation request to the Replicate API endpoint for the ligua033/lorealcantara model.

  • Key Configuration: Method POST, URL https://api.replicate.com/v1/predictions, Authentication Generic HTTP Header using the dynamically retrieved API key, jsonBody defining the input prompt and model configuration.

Extract Prediction ID (Code)


  • Function: Parses the JSON response from the prediction creation step to isolate the unique predictionId and constructs the necessary predictionUrl for polling.

  • Key Configuration: Uses custom JavaScript to return predictionId, status, and predictionUrl.

Wait (Wait)


  • Function: Pauses the n8n workflow execution for 2 seconds. This pause is vital to implement the delay required in the polling loop, managing API request frequency.

  • Key Configuration: Amount: 2, Unit: seconds.

Check Prediction Status (HTTP Request)


  • Function: Performs a GET request using the extracted predictionUrl to check if the AI generation is finished.

  • Key Configuration: URL is dynamically set using ={{ $json.predictionUrl }}, authenticated with the API key.

Check If Complete (If)


  • Function: Controls the polling loop flow. Checks if the status returned by the previous HTTP Request n8n node is equal to 'succeeded'.

  • Key Configuration: Condition: $json.status equals succeeded. Routes the execution back to the Wait node if false.

Process Result (Code)


  • Function: Executes upon successful completion, cleaning and structuring the final generated output, including the resulting image URL and process metrics, completing the 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*