AI Image Generation Polling Loop for Replicate - n8n Workflow

Generate AI images using the creativeathive Lemaar Doorhandle model via Replicate API. This n8n workflow template includes robust polling logic and HTTP request n8n nodes.

Workflow Preview

Ready to automate?

Download this n8n workflow template and start using it instantly.

Who is this best for?


  • Developers and engineers needing automated AI image generation integrated into their services.

  • Users looking for reusable n8n templates for handling asynchronous API polling.

  • Automation specialists deploying specific Replicate models who require reliable status checks.

  • n8n users who need examples of robust API interaction using conditional logic and the HTTP Request n8n node.

Overview

This sophisticated n8n workflow addresses the challenge of managing long-running, asynchronous tasks, specifically AI image generation via the Replicate API using the creativeathive/lemaar-doorhandle-newset model. Since API calls for generation often take time, a standard linear n8n workflow would fail. This specific n8n workflow template implements a crucial polling loop using a combination of the HTTP Request n8n node, a Wait n8n node, and an If n8n node.

This structure ensures the n8n automation reliably initiates the job, pauses gracefully, and then repeatedly checks the status until the image generation is complete, ultimately retrieving the output URL. This reliable polling mechanism is a vital pattern for any high-performance automation built with n8n.

How it Works

The execution of this n8n workflow begins when the Manual n8n trigger, 'On clicking 'execute'', is activated.


  1. Setup and Initiation: The 'Set API Key' n8n node securely defines the required Replicate API key. The subsequent 'Create Prediction' HTTP Request n8n node sends the configuration (prompt, model version, dimensions) to the Replicate API, starting the asynchronous AI generation job.

  2. ID Extraction and Polling Start: The 'Extract Prediction ID' Code n8n node immediately parses the initial response to obtain the unique predictionId and constructs the endpoint required for status checking.

  3. Polling Loop: The workflow enters a loop starting with the 'Wait' n8n node, which pauses execution for 2 seconds. This pause is critical for respecting API rate limits.

  4. Status Check: The 'Check Prediction Status' HTTP Request n8n node polls the prediction URL using the previously extracted ID.

  5. Conditional Flow: The 'Check If Complete' If n8n node evaluates the status received from Replicate. If the status equals 'succeeded', the n8n workflow exits the loop and proceeds to 'Process Result'. If the status is anything else (e.g., 'processing'), the flow returns to the 'Wait' n8n node, repeating the polling cycle.

  6. Final Result: Once complete, the 'Process Result' Code n8n node extracts the final output, including the URL to the generated image, completing this robust n8n template.

Installation Guide


  1. Import: Copy the provided JSON data and import it directly into your n8n instance as a new n8n workflow.

  2. API Key Configuration: Locate the 'Set API Key' n8n node. Update the 'replicateapikey' assignment with your actual Replicate API key. Note: For production, it is highly recommended to store credentials using the n8n credentials system instead of using a Set n8n node for security.

  3. Prompt Configuration: In the 'Create Prediction' HTTP Request n8n node, modify the JSON body to include your desired input prompt and other generation parameters (width, height, lora_scale).

  4. Activation: Ensure the n8n workflow is active and test the entire flow by clicking the 'Execute Workflow' button on the starting n8n trigger.

Node Details


  • On clicking 'execute' (Manual Trigger n8n trigger): Initiates the flow execution. Perfect for testing and development of the n8n workflow.

  • Set API Key (Set n8n node): Used to inject the Replicate API key into the flow data, which is then utilized in the Authorization headers of the subsequent HTTP Request n8n node.

  • Create Prediction (HTTP Request n8n node): Initiates the AI generation. Key settings include the POST method, URL https://api.replicate.com/v1/predictions, and using the API key for Authorization: Bearer header construction.

  • Extract Prediction ID (Code n8n node): Critical for asynchronous operations. This n8n node extracts the unique prediction ID needed for subsequent polling requests.

  • Wait (Wait n8n node): Enforces a 2-second delay between polling attempts, preventing the n8n workflow from overloading the Replicate API.

  • Check Prediction Status (HTTP Request n8n node): The polling component. Sends a GET request to the specific prediction URL obtained earlier to check the current status of the AI job.

  • Check If Complete (If n8n node): Controls the polling loop. It checks if the status field equals 'succeeded'. If true, it proceeds to output the result; if false, it loops back to the 'Wait' n8n node.

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*