Replicate AI Assistant Generation and Polling Loop - n8n Workflow

Use this robust n8n workflow to automate asynchronous AI generation with Replicate. This n8n workflow includes necessary polling logic, an n8n trigger, and HTTP request n8n node configuration for reliable results.

Workflow Preview

Ready to automate?

Download this n8n workflow template and start using it instantly.

Who is this best for?

Developers needing asynchronous AI processing handled automatically.
Data scientists integrating specialized Replicate models (like aihilums/sehatsanjha) into production tools.
Automation specialists looking for reusable n8n templates for polling long-running tasks.
Users who need a reliable n8n node structure for external API interaction and status checking.

Overview

When dealing with computationally intensive AI models, the results are rarely instant. Replicate uses an asynchronous prediction system, meaning the initial request returns an ID, and you must poll that ID until the job is complete. This specialized n8n workflow solves this complexity entirely. It acts as a resilient polling mechanism, ensuring that once the initial prediction is created using the HTTP Request n8n node, the process pauses and continuously checks the status until the 'succeeded' message is received. This removes the manual burden of managing long-running tasks and provides a powerful, self-contained n8n workflow for integrating advanced AI capabilities. This specific n8n workflow template uses the aihilums/sehatsanjha model, demonstrating a practical application of core logic flow control within n8n.

How it Works

The n8n workflow initiates with a manual n8n trigger.


  1. Initialization: The n8n trigger starts the process, and the first n8n node (Set API Key) defines the Replicate API key as a flow variable.

  2. Start Prediction: An HTTP Request n8n node sends a POST request to Replicate to start the AI generation job, using the stored API key for authorization.

  3. Extract ID: A Code n8n node (Extract Prediction ID) captures the Prediction ID returned by Replicate, along with the polling URL.

  4. Wait: The n8n workflow pauses for 2 seconds using the Wait n8n node to prevent aggressive polling and rate limiting.

  5. Check Status: Another HTTP Request n8n node (Check Prediction Status) uses the extracted Prediction URL to query Replicate for the job's current status.

  6. Loop Control: An IF n8n node (Check If Complete) checks if the status is 'succeeded'. If the prediction has not succeeded, the n8n workflow loops back to the Wait n8n node, repeating the polling cycle.

  7. Finalize: If the prediction status is 'succeeded', the n8n workflow exits the loop and passes the final output to the Process Result Code n8n node for structured data output.

Installation Guide

To use this n8n workflow template, follow these steps:


  1. Import: Copy the provided JSON code and import it directly into your n8n instance via the 'New' menu (Templates or Import from JSON).

  2. API Key Setup: Locate the Set API Key n8n node. Replace the placeholder value YOURREPLICATEAPI_KEY with your actual Replicate API key.

  3. Model Configuration (Optional): Review the Create Prediction HTTP Request n8n node. The JSON body defines the model version (currently 8d601ed5dfe3c91d7dacdc17a127497519acfdb4c4eefbec3db17b6d87734a69). Adjust the version and input parameters if you wish to use a different Replicate model or specific inputs.

  4. Execution: Since this n8n workflow starts with a Manual n8n trigger, simply click the 'Execute Workflow' button to run your automation.

Node Details

This n8n workflow relies on several core n8n node types to manage the asynchronous API calls:

On clicking 'execute' (Manual Trigger): This serves as the initial n8n trigger, allowing the user to start the n8n workflow on demand.
Set API Key (Set n8n node): Essential for secure configuration. It stores the Replicate API key as an item, which is then dynamically referenced by subsequent HTTP Request n8n node calls.
Create Prediction (HTTP Request n8n node):
Function: Starts the AI generation process by hitting the Replicate /v1/predictions endpoint.
Key Configuration: Uses Generic Credential Type to dynamically set the Authorization header using an expression: ={{ 'Bearer ' + $('Set API Key').item.json.replicateapikey }}.
Extract Prediction ID (Code n8n node):
Function: Parses the initial response body to extract the unique prediction ID and constructs the necessary polling URL (predictionUrl). This data is crucial for the continuous polling loop managed by other n8n nodes.
Wait (Wait n8n node):
Function: Implements a 2-second delay between polling attempts to manage resource usage and adhere to API best practices. This ensures the n8n workflow is efficient.
Check Prediction Status (HTTP Request n8n node):
Function: Polls the specific prediction URL to retrieve the current status of the AI job.
Check If Complete (IF n8n node):
Function: Controls the flow logic. It checks if the $json.status equals succeeded. If true, the n8n workflow proceeds; otherwise, it loops back to the Wait n8n node.
Process Result (Code n8n node):
* Function: Once the job succeeds, this final n8n node structures the output, extracting key metrics, the final output URL, and metadata for easy consumption by downstream systems.

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*