AI Content Generation with Replicate Polling Loop - n8n Workflow

Create powerful AI-generated content or images using the Replicate API and this robust n8n workflow. Features polling logic, error handling, and structured output.

Workflow Preview

Ready to automate?

Download this n8n workflow template and start using it instantly.

Who is this best for?

Automation engineers seeking reliable AI generation solutions.
Developers needing production-ready n8n templates for external APIs.
Users who want to integrate complex text-to-content models into their n8n workflow.
Anyone looking to leverage the Replicate platform within an n8n automation.

Overview

This powerful n8n workflow provides a complete solution for asynchronously generating AI content or images using the digitalhera/herathaisbragatto2 model hosted on Replicate. Since AI generation tasks often take time, this n8n automation is designed with a resilient polling loop. This approach solves the problem of simple HTTP requests timing out by continuously checking the prediction status until the process is marked as 'succeeded' or 'failed'. The result is a highly reliable n8n workflow that handles API authentication, complex input parameters, logging, and comprehensive error handling, making it a perfect foundation for various AI applications. This reusable n8n template can be easily adapted for other generation models on Replicate.

How it Works


  1. Trigger Initiation: The process begins with the Manual Trigger n8n trigger, allowing for immediate execution and testing of the n8n workflow.

  2. Configuration: The n8n workflow first executes the Set API Token n8n node to define the required Replicate authentication key and then the Set Other Parameters n8n node to specify all generation inputs, such as the prompt, width, and height.

  3. Prediction Request: The Create Other Prediction n8n node sends a non-blocking POST request to the Replicate API, initiating the AI generation process and receiving a unique prediction ID.

  4. Logging: A Log Request custom code n8n node records the prediction ID for monitoring purposes.

  5. Polling Setup: The n8n workflow enters a status checking loop, starting with a short wait (Wait 5s).

  6. Status Check & Loop: The Check Status n8n node fetches the current state using the prediction ID.

  7. Conditional Routing: An Is Complete? n8n node checks if the prediction status is 'succeeded'. If not, the Has Failed? n8n node checks if the status is 'failed'.

  8. Retry Logic: If the status is neither succeeded nor failed (meaning it is still running), the n8n workflow waits 10 seconds (Wait 10s) and then loops back to the Check Status n8n node. This ensures the n8n automation is resource-efficient.

  9. Final Output: Upon completion, the n8n workflow routes the execution to either the Success Response or Error Response n8n node, consolidating the final output URL or error details into a structured JSON response displayed by the Display Result n8n node.

Installation Guide


  1. Import the n8n Workflow: Copy the provided JSON data and paste it into your n8n instance using the 'New' -> 'Import from JSON' option. This imports the complete n8n workflow structure.

  2. Configure Credentials: Locate the Set API Token n8n node.

Replace the placeholder YOURREPLICATEAPITOKEN with your actual token obtained from Replicate.com. This token is essential for the HTTP Request n8n node connections.

  1. Adjust Parameters (Optional but Recommended): Navigate to the Set Other Parameters n8n node.

Update the prompt value (default: "Create something amazing") to define the content you wish to generate.
* Adjust other input variables like width, height, or aspect
ratio as needed for your specific use case. This configuration flexibility makes this a powerful n8n template.

  1. Activate and Run: Click the 'Manual Trigger' n8n trigger to test the automation, or save and activate the n8n workflow to make it production-ready.

Node Details

Manual Trigger (n8n trigger): The starting n8n trigger for this automation, designed for immediate testing and execution control of the n8n workflow.
Set API Token (n8n node): Stores the Replicate API key in the workflow data, ensuring secure use across subsequent API calls.
Key Configuration: Defines the variable api_token.
Set Other Parameters (n8n node): Prepares the large input payload for the AI model.
Function: Aggregates input parameters like prompt, seed, width, and height.
Create Other Prediction (HTTP Request n8n node): Initiates the text-to-content generation request to Replicate.
Function: Sends a POST request to /v1/predictions. It sets the Authorization header using the Bearer token retrieved from the Set API Token n8n node.
Check Status (HTTP Request n8n node): Used inside the polling loop to retrieve the status of the running prediction.
Function: Sends a GET request to the prediction ID URL, continually checking for completion.
Is Complete? (If n8n node): Controls the flow of the n8n workflow.
Function: Checks if the API response status equals 'succeeded'.
Wait 10s (Wait n8n node): Provides the essential retry mechanism, pausing the n8n workflow execution before checking the status again, which is crucial for handling long-running AI tasks.

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*