AI Image Generation using Replicate and Digitalhera Model - n8n Workflow

Automate AI image generation using the Digitalhera Herathaisbragatto model on Replicate. This n8n workflow template handles asynchronous polling and result extraction.

Workflow Preview

Ready to automate?

Download this n8n workflow template and start using it instantly.

Who is this best for?

Creative agencies needing bulk content generation.
Developers building internal tools for image creation.
Users seeking advanced n8n templates for asynchronous API polling.
Automation specialists looking for a reliable n8n workflow to integrate Replicate services.

Overview

This comprehensive n8n workflow provides a robust solution for initiating and monitoring long-running AI generation tasks using the Replicate API. Unlike simple synchronous API calls, Replicate models, especially those for complex image generation like the Digitalhera Herathaisbragatto model, require asynchronous processing. This n8n template elegantly solves the asynchronous challenge by implementing a precise polling loop. It ensures that the job is submitted, waits efficiently, and only proceeds to process the final output once the AI image generation is complete. Utilizing this n8n workflow saves significant development time when integrating powerful AI capabilities into existing applications or internal business processes.

How it Works

The n8n workflow is designed to execute manually, but it can easily be adapted with any standard n8n trigger (like a Webhook or Schedule).


  1. Start and Setup: The n8n workflow starts with the 'On clicking 'execute'' n8n trigger. It immediately routes execution to the 'Set API Key' n8n node, which securely prepares the necessary Replicate credential (API key) for subsequent HTTP requests.

  2. Create Prediction: The 'Create Prediction' n8n node sends a POST request to Replicate, initializing the AI generation job. This call uses HTTP header authentication configured within this specific n8n node.

  3. Extraction: The response, which is an initial job status, is processed by the 'Extract Prediction ID' n8n node. This code node extracts the unique predictionId and constructs the endpoint URL required for status checks.

  4. Polling Loop Initiation: The n8n workflow enters a polling loop starting with the 'Wait' n8n node, which pauses execution for 2 seconds to allow processing time on the Replicate server.

  5. Status Check: The 'Check Prediction Status' n8n node makes a subsequent GET request to the polling URL to retrieve the current status of the AI task.

  6. Loop Control: The 'Check If Complete' n8n node evaluates the job status. If the status is succeeded, the n8n workflow breaks the loop and proceeds to 'Process Result'. If the status is anything else (e.g., 'processing', 'starting'), the flow loops back to the 'Wait' n8n node, repeating the check until completion.

  7. Final Output: Once complete, the 'Process Result' n8n node extracts the generated output URL (the AI image location) and other critical metadata, finalizing the n8n workflow execution.

Installation Guide

To use this powerful n8n workflow template, follow these steps:


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

  2. API Key Configuration: Open the 'Set API Key' n8n node. Replace the placeholder value YOURREPLICATEAPI_KEY with your actual Replicate API key. Ensure this key is correct, as all subsequent HTTP requests depend on it.

  3. Input Customization: Open the 'Create Prediction' n8n node. Modify the prompt value within the JSON body to specify the AI content you wish to generate.

  4. Save and Activate: Save the n8n workflow. Since the n8n trigger is manual, you can click 'Execute Workflow' to test the full loop immediately.

  5. Credentials: Note that this n8n template uses generic HTTP Header authentication configured directly within the HTTP Request n8n node, utilizing the variable set earlier for the API key.

Node Details

On clicking 'execute' (n8n trigger): Manual trigger initiating the flow, ideal for immediate testing of the n8n workflow.
Set API Key (Set n8n node): Essential n8n node for securely managing credentials. It stores the Replicate API key in a temporary variable (replicateapikey) accessible by subsequent nodes.
Create Prediction (HTTP Request n8n node): Sends the initial asynchronous request to Replicate, specifying the digitalhera/herathaisbragatto model version and input parameters (prompt, seed, dimensions). Uses the variable set by the previous n8n node for authorization.
Extract Prediction ID (Code n8n node): A critical custom code n8n node that parses the API response to retrieve the prediction ID and calculate the dynamic URL needed for polling.
Wait (Wait n8n node): Implements a necessary 2-second delay to prevent aggressive polling and respect Replicate's rate limits while the AI model processes.
Check Prediction Status (HTTP Request n8n node): Polls the dynamically generated prediction URL to monitor job progress.


  • Check If Complete (If n8n node): Controls the polling loop. It checks if the status equals succeeded. If true, the n8n workflow completes; otherwise, 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*