Asynchronous AI Generation with Replicate Polling - n8n Workflow

Use this robust n8n workflow template to automate AI content generation via the Replicate API. Features dynamic polling, custom code scripting, and secure API key management.

Workflow Preview

Ready to automate?

Download this n8n workflow template and start using it instantly.

Who is this best for?

This n8n workflow template is ideal for:
Developers needing to integrate asynchronous AI models (like Replicate) into backend processes.
Automation specialists seeking reusable n8n templates for API polling logic.
Users looking to utilize the creativeathive/lemaar-door-wm model directly within an n8n environment.
Engineers requiring a robust n8n workflow example for handling long-running external tasks.

Overview

Generating complex AI content, such as images or extended text, often involves asynchronous API calls, meaning the initial request returns immediately while the actual generation happens in the background. This sophisticated n8n workflow solves the complexity of managing this asynchronous process.

It initializes a job on Replicate using the specified AI model (creativeathive/lemaar-door-wm) and then enters a reliable polling loop. This loop, orchestrated using the Wait, HTTP Request, and If n8n node components, continuously checks the job status until completion. This specific n8n workflow ensures that you receive the final output only when the AI generation is successfully done, providing a stable foundation for integrating powerful AI capabilities into any larger n8n automation.

How it Works

This n8n workflow is initiated by a manual n8n trigger and follows a multi-step execution logic focused on secure authentication and asynchronous API management:


  1. Start: The process begins with the 'On clicking 'execute'' manual n8n trigger, ideal for testing or scheduled execution (by changing the n8n trigger type).

  2. Authentication Setup: The 'Set API Key' n8n node securely stores the Replicate API key, which is then dynamically injected into subsequent HTTP headers.

  3. Initiate Prediction: The 'Create Prediction' n8n node sends a POST request to the Replicate API to start the generation process for the creativeathive/lemaar-door-wm model, passing parameters like prompt, seed, width, and height.

  4. Extract ID: The 'Extract Prediction ID' n8n node captures the unique predictionId and the specific status URL returned by Replicate. This is vital for the polling sequence.

  5. Wait and Poll: The 'Wait' n8n node pauses the n8n workflow for 2 seconds. This is followed by the 'Check Prediction Status' n8n node, which uses the extracted URL to poll Replicate for the current job status.

  6. Loop Control: The 'Check If Complete' n8n node acts as the flow controller. It checks if the status is 'succeeded'.

If the job is not successful (still running or failed), the n8n workflow loops back to the 'Wait' n8n node to repeat the check.
If the job is successful, the n8n workflow proceeds to the final processing step.

  1. Process Output: The 'Process Result' n8n node extracts the generated output (the image or content URL) and metrics from the final successful response.

Installation Guide

To deploy this n8n workflow template:


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

  2. API Key Configuration: Locate the 'Set API Key' n8n node. Update the replicateapikey assignment with your actual Replicate API key. Ensure this key is available as a bearer token for the subsequent HTTP Request n8n node configurations.

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

  4. Activation: Ensure the n8n workflow is marked 'Active' and execute the 'On clicking 'execute'' n8n trigger to test the generation and polling logic.

Node Details

This n8n workflow uses several critical nodes to achieve reliable asynchronous generation:

On clicking 'execute' (n8n trigger): The manual n8n trigger used to initiate the automation run.
Set API Key (Set n8n node): Essential for secure parameter management. It defines the replicateapikey variable used for authorization headers throughout the n8n workflow.
Create Prediction (HTTP Request n8n node): Submits the initial job to Replicate. Key Configuration: Uses POST method, specifies the creativeathive/lemaar-door-wm model version, and uses generic HTTP Header Authentication (Bearer {{ API Key }}).
Extract Prediction ID (Code n8n node): A custom n8n node that runs JavaScript to extract the id and constructs the polling URL (predictionUrl) for dynamic status checking.
Wait (Wait n8n node): Temporarily halts the n8n workflow execution for 2 seconds, preventing rate limiting during the polling phase.
Check Prediction Status (HTTP Request n8n node): Polls the dynamically created predictionUrl. Key Configuration: Uses GET method and the secure authorization header.
Check If Complete (If n8n node): Determines the flow path. Key Configuration: Checks if $json.status is strictly equal to succeeded.
Process Result (Code n8n node): A final custom n8n node that cleans up and structures the resulting data, making the output URLs readily accessible to subsequent steps in 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*