AI Image Generation via Replicate API Polling Loop - n8n Workflow

Automate high-fidelity AI image generation using the digitalhera/heranathalie model on Replicate. This robust n8n workflow handles asynchronous tasks, polling, and error reporting seamlessly.

Workflow Preview

Ready to automate?

Download this n8n workflow template and start using it instantly.

Who is this best for?


  • Content creators needing scalable AI image generation.

  • Developers integrating Replicate services into their applications.

  • Advanced n8n users seeking examples of robust API polling logic.

  • Users looking for ready-made n8n templates for complex AI tasks.

Overview

Generating complex AI media, such as images using models like digitalhera/heranathalie, is often an asynchronous process requiring the automation platform to initiate a job and then continuously check its status until completion. This dedicated n8n workflow solves this challenge by providing a complete, resilient automation pipeline built around the Replicate API. This specific n8n workflow template manages API credentials, handles all required input parameters (like prompt, size, and seed), initiates the prediction, and implements a crucial status polling loop. By using a series of HTTP Request and If n8n node components, the workflow ensures that the final image URL is only returned after the generation job is successfully finished, providing robust error handling if the prediction fails. This is a perfect example of an advanced n8n automation strategy.

How it Works

The process begins with the Manual Trigger n8n trigger, allowing for immediate execution when needed.


  1. Initialization: The workflow first runs the Set API Token n8n node to securely configure the Replicate API key, followed by the Set Other Parameters n8n node, where all necessary AI parameters (like the 'Create something amazing' default prompt, width, and height) are defined.

  2. Prediction Request: The Create Other Prediction n8n node (an HTTP Request) sends a POST request to the Replicate API, initiating the image generation using the specific digitalhera/heranathalie version. This returns an initial prediction ID.

  3. Polling Setup: A brief Wait 5s n8n node pauses the flow to give the service time to start the job. Then, the Check Status n8n node begins polling the Replicate endpoint using the prediction ID.

  4. Loop Logic: The Is Complete? n8n node evaluates the job status.

- If the status is 'succeeded', the workflow exits the loop and proceeds to the Success Response n8n node, returning the generated image URL.
- If the status is not 'succeeded', the flow moves to the Has Failed? n8n node. If the job status is 'failed', it proceeds to Error Response.
- If the status is neither 'succeeded' nor 'failed' (meaning it's still running), the Wait 10s n8n node introduces a delay before looping back to the Check Status n8n node to re-check the progress. This loop continues until a final status is reached, ensuring reliable task completion for this complex n8n workflow.

Installation Guide

To deploy this n8n workflow template and begin automating image generation, follow these steps:


  1. Import the JSON: Copy the provided JSON code and import it directly into your self-hosted or cloud n8n instance using the 'New' -> 'Import from JSON' option.

  2. Configure Credentials: Locate the Set API Token n8n node. Replace the placeholder value YOURREPLICATEAPITOKEN with your actual Replicate API key. This token is essential for authorizing the HTTP Request n8n node to communicate with the Replicate API.

  3. Adjust Parameters: Review the Set Other Parameters n8n node. Here you can customize the prompt, image dimensions (width, height), aspectratio, and other generation settings for the digitalhera/heranathalie model.

  4. Activate and Test: Activate the n8n workflow. Click 'Execute Workflow' or the Manual Trigger n8n trigger node to run a test job. Monitor the execution output to ensure the asynchronous polling loop successfully retrieves the final image URL.

Node Details

This n8n workflow template relies on several key n8n node types to manage the asynchronous API communication:

Manual Trigger: The starting n8n trigger for the entire automation, initiating the AI generation on demand.
Set (Set API Token & Set Other Parameters): These essential n8n node components store and define the necessary data, including the Replicate API token and detailed generation parameters (e.g., prompt: "Create something amazing", width: 512, height: 512).
HTTP Request (Create Other Prediction): This critical n8n node sends the initial POST request to https://api.replicate.com/v1/predictions. It uses expressions to dynamically include the parameters and the authorization header (Bearer {{ $json.api_token }}).
HTTP Request (Check Status): Used within the polling loop. This n8n node sends a GET request to retrieve the status of the prediction job using the unique ID received from the previous step.
Wait (Wait 5s & Wait 10s): These n8n node functions introduce necessary delays, preventing rate-limiting issues during the asynchronous polling process and allowing the AI model time to process the request.
If (Is Complete? & Has Failed?): Core flow control n8n node components that manage the polling logic. They check the incoming status ({{ $json.status }}) and direct the n8n workflow flow to either the success path, the error path, or back into the polling loop.

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*