Asynchronous AI Image Generation with Replicate Polling Loop - n8n Workflow

Learn how to use this powerful n8n workflow template to generate AI content asynchronously via Replicate, featuring a robust n8n polling logic using HTTP Request, Wait, and If nodes.

Workflow Preview

Ready to automate?

Download this n8n workflow template and start using it instantly.

Who is this best for?

Users needing to automate asynchronous AI tasks where results are not returned immediately.
Developers looking for a reliable n8n template for integrating long-running API services like Replicate.
Technical marketers or designers utilizing AI models (specifically the creativeathive/lemaar-door-mockedup model) for content generation.
Anyone seeking expert n8n workflow examples demonstrating core logic flow control.

Overview

Generating complex AI images often takes time, meaning the initial API request only returns a prediction ID, not the final output. This requires 'polling' the service repeatedly until the job is complete. This specialized n8n workflow solves this challenge by implementing a robust, self-correcting polling loop.

The automation starts with an n8n trigger, initializes the job with Replicate, and then enters a loop using the Wait and If n8n nodes. This loop ensures the workflow pauses (Wait node), checks the status (HTTP Request n8n node), and only proceeds when the generation is 'succeeded'. This powerful logic makes this n8n template highly reliable for handling external asynchronous tasks, a critical pattern for advanced n8n automation.

How it Works

This n8n workflow executes through a structured sequence designed specifically for asynchronous API interactions:


  1. Manual Start: The workflow begins with the 'On clicking 'execute'' n8n trigger, allowing for manual testing and execution.

  2. API Key Setup: The 'Set API Key' n8n node initializes the required Replicate API key, ensuring secure authentication for subsequent steps.

  3. Create Prediction: An HTTP Request n8n node sends a POST request to Replicate's API, initiating the AI generation using the specified model (creativeathive/lemaar-door-mockedup) and input parameters (prompt, seed, etc.).

  4. Extract ID: The 'Extract Prediction ID' n8n node immediately processes the API response, extracting the unique prediction ID and constructing the required polling URL.

  5. Initiate Polling: The workflow moves to the 'Wait' n8n node, which pauses execution for 2 seconds to prevent overwhelming the API during the polling cycle.

  6. Check Status: The 'Check Prediction Status' HTTP Request n8n node then uses the extracted URL and API key to query the status of the AI generation job.

  7. Loop Control: The 'Check If Complete' If n8n node analyzes the status. If the status is 'succeeded', the workflow proceeds to process the result. If the status is anything else (e.g., 'processing', 'starting'), the workflow loops back to the 'Wait' n8n node, restarting the 2-second pause and subsequent status check. This polling logic is a core feature of the n8n workflow.

  8. Process Result: Once the job is complete, the 'Process Result' n8n node extracts the final output data, including the URL of the generated image, completion metrics, and other relevant metadata.

Installation Guide

To deploy this comprehensive n8n workflow, follow these steps:


  1. Import the n8n Workflow: Copy the provided JSON code and import it directly into your n8n instance via the 'Workflows' section using the 'Import from JSON' button.

  2. Setup Replicate Credentials: You will need a Replicate API key. Obtain this key from your Replicate account settings.

  3. Configure API Key Node: Locate the 'Set API Key' n8n node within the imported workflow. In the configuration for the replicateapikey assignment, replace the placeholder value YOURREPLICATEAPI_KEY with your actual Replicate API key.

  4. Configure Input Prompt: Locate the 'Create Prediction' n8n node. Edit the JSON body to set your desired prompt value and adjust inputs like seed, width, and height as needed for the model.

  5. Activate and Test: Activate the n8n workflow and click the 'Execute Workflow' button to test the full asynchronous polling sequence.

Node Details

This n8n workflow leverages several key n8n node types to manage its complex logic:

On clicking 'execute' (Manual Trigger n8n trigger): The starting point for this specific n8n workflow template, allowing manual initiation of the process.
Set API Key (Set n8n node): Used to inject the required Replicate API key securely into the workflow data stream, enabling authentication for subsequent HTTP Requests.
Create Prediction (HTTP Request n8n node): Responsible for calling the Replicate API to start the asynchronous image generation job. It sends the input prompt and model configuration.
Extract Prediction ID (Code n8n node): A crucial custom code n8n node that extracts the unique ID needed for the polling process and generates the endpoint URL for status checks.
Wait (Wait n8n node): Implements the necessary time delay (2 seconds) within the polling loop, ensuring the workflow doesn't hammer the external API and allows time for processing.
Check Prediction Status (HTTP Request n8n node): The core of the polling mechanism. This n8n node repeatedly queries the Replicate service status based on the prediction ID.
Check If Complete (If n8n node): Provides the flow control for the n8n workflow. It checks if the status equals 'succeeded'. If true, the workflow exits the loop; if false, it is routed back to the Wait node.
Process Result (Code n8n node): Executes upon completion, cleaning up and presenting the final image output URL and metadata for downstream use.

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*