Replicate AI Generator Polling Loop for 2ndmoises_generator Model - n8n Workflow

Use this robust n8n workflow to automate content generation with Replicate's moicarmonas/2ndmoises_generator AI model. Features automated status polling and secure API key handling.

Workflow Preview

Ready to automate?

Download this n8n workflow template and start using it instantly.

Who is this best for?


  • Developers and automators needing to integrate asynchronous AI tasks into their pipeline using n8n.

  • Users looking for advanced n8n templates featuring HTTP request polling and control flow.

  • Businesses wanting to utilize specialized Replicate models like moicarmonas/2ndmoises_generator for automated content creation.

  • Technical users who want to see how to implement secure API key management within an n8n node sequence.

Overview

Integrating external AI models often requires handling asynchronous operations—you initiate a task, and then you must periodically check if it's finished. This specific n8n workflow solves this by providing a reliable pattern for interacting with Replicate, a popular platform for running open-source AI models.

The automation initiates a generation request using the moicarmonas/2ndmoises_generator model. Instead of failing while waiting, the n8n workflow implements a vital polling loop using the 'Wait' n8n node and an 'If' n8n node, ensuring the system patiently checks the status until the generation succeeds before retrieving the final output. This robust design makes this n8n template essential for reliable AI operations.

How it Works

The entire process is initiated by a manual n8n trigger for immediate execution or testing.


  1. Setup and Initialization: The initial 'Set API Key' n8n node securely stores the Replicate API key, which is immediately used by the next step.

  2. Create Prediction: An 'HTTP Request' n8n node sends a POST request to Replicate to start the content generation task using predefined input parameters (prompt, seed, etc.).

  3. Extraction: A 'Code' n8n node, 'Extract Prediction ID', processes the initial response, extracting the unique prediction ID and the specific API URL required for checking its status.

  4. Wait and Poll: The n8n workflow enters a polling sequence. It first executes a 'Wait' n8n node, pausing the execution for 2 seconds. The subsequent 'Check Prediction Status' n8n node uses the extracted URL and the stored API key to query Replicate for the job status.

  5. Flow Control: The 'Check If Complete' n8n node evaluates the returned status. If the status is 'succeeded', the flow proceeds to the final processing step. If the status is anything else (like 'processing'), the flow loops back to the 'Wait' n8n node, repeating the polling cycle until the job is done. This complex flow control logic ensures reliable completion.

  6. Result Processing: Once the generation is complete, the 'Process Result' n8n node extracts and structures the final output (e.g., the generated content URL and metadata) for use in subsequent n8n node sequences.

Installation Guide

To deploy this n8n workflow, follow these steps:


  1. Import the n8n template: Copy the provided JSON code and import it into your n8n instance via the 'Workflows' > 'New' > 'Import from JSON' option.

  2. Configure Credentials: The workflow requires a Replicate API key.

Locate the 'Set API Key' n8n node.
Replace the placeholder value YOURREPLICATEAPIKEY with your actual Replicate API key.

  1. Customize AI Inputs: Locate the 'Create Prediction' n8n node and modify the jsonBody to set the specific prompt and configuration parameters (like width, height, and lorascale) required for the moicarmonas/2ndmoises_generator model.

  2. Activate and Run: Save the n8n workflow. Use the 'Execute Workflow' button on the 'On clicking 'execute'' n8n trigger node to test the flow.

Node Details

On clicking 'execute' (Manual Trigger): The starting n8n trigger. Used for manual execution and testing of the n8n workflow.
Set API Key (Set): Function: Securely assigns the Replicate API key to an item variable (replicateapikey) accessible by subsequent HTTP request n8n nodes.
Create Prediction (HTTP Request): Function: Initiates the asynchronous generation task on the Replicate platform for the specified model. Key Configuration: Uses POST method to https://api.replicate.com/v1/predictions and includes the API key in the Authorization header.
Extract Prediction ID (Code): Function: A custom n8n node script that pulls the unique id from the creation response and constructs the polling URL for status checks. Key Configuration: Prepares data needed for the loop control.
Wait (Wait): Function: Pauses the n8n workflow execution for a defined time (2 seconds) before polling the status again, preventing excessive API calls.
Check Prediction Status (HTTP Request): Function: Checks the real-time status of the running AI job using a GET request to the specific prediction URL. Key Configuration: URL is dynamically set using expression ={{ $json.predictionUrl }}.
Check If Complete (If): Function: Implements the crucial decision logic. If the status is 'succeeded', it completes the loop; otherwise, it directs the flow back to the 'Wait' n8n node.
Process Result (Code): Function: Finalizes the output by structuring the completed prediction data, making the resulting generated content URL easily accessible for the rest of 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*