AI Image Generation with Replicate Nazanin Model and Polling - n8n Workflow

Automate AI image generation using the Replicate Citoreh Nazanin model. This advanced n8n workflow features asynchronous job initiation and status polling using n8n node logic.

Workflow Preview

Ready to automate?

Download this n8n workflow template and start using it instantly.

Who is this best for?

Developers needing to integrate asynchronous AI image generation into their applications.
Technical users looking for n8n templates that demonstrate robust polling loops for long-running API tasks.
Content creators and designers seeking a repeatable automated process for generating AI art using a specific Replicate model.
n8n automation specialists interested in mastering the HTTP Request n8n node for third-party integrations.

Overview

This powerful n8n workflow template provides a reliable solution for running resource-intensive AI generation tasks using the Replicate API. Since complex image generation often requires queuing time, this n8n workflow utilizes an essential asynchronous polling structure.

Instead of making a synchronous call that could time out, the n8n node logic immediately extracts a prediction ID after initiation, pauses execution, and then repeatedly checks the job status until the image generation succeeds. This polling pattern is critical for building reliable n8n workflow automations that interact with job-queued services, ensuring the final output is captured correctly without workflow failures. This specific n8n workflow is tailored to the citoreh/nazanin model.

How it Works

The entire process of this n8n workflow is designed to manage the asynchronous nature of Replicate's API:


  1. Trigger: The n8n workflow starts via the 'On clicking 'execute'' n8n trigger, signaling a manual run.

  2. API Key Setup: The 'Set API Key' n8n node defines the necessary Replicate authentication token, which is referenced securely in subsequent HTTP requests.

  3. Initiate Prediction: The first 'Create Prediction' HTTP Request n8n node sends a POST request to Replicate, starting the image generation job for the Nazanin model and passing the required prompt.

  4. Extract ID: The 'Extract Prediction ID' Code n8n node processes the initial response, extracting the unique job id and constructing the specific URL needed for status checking.

  5. Wait and Poll: The n8n workflow enters a polling loop, starting with the 'Wait' n8n node which pauses execution for 2 seconds to avoid excessive API calls.

  6. Check Status: The 'Check Prediction Status' HTTP Request n8n node polls the specific prediction URL to retrieve the current status of the AI job.

  7. Conditional Check: The 'Check If Complete' If n8n node checks if the status is succeeded. If the status is not successful (i.e., 'processing' or 'starting'), the n8n workflow cycles back to the 'Wait' n8n node.

  8. Process Result: Once the status is succeeded, the n8n workflow proceeds to the 'Process Result' Code n8n node, which cleans up and formats the final output, including the URL to the generated image.

Installation Guide


  1. Import: Download the provided n8n workflow JSON and import it directly into your n8n instance.

  2. Credentials: This n8n template relies on manually setting the Replicate API key.

  3. Configure API Key: Open the 'Set API Key' n8n node and replace YOURREPLICATEAPI_KEY with your actual Replicate API token.

  4. Configure Prompt: Open the 'Create Prediction' HTTP Request n8n node. Modify the jsonBody to set your desired image generation prompt and specific input parameters (like width, height, or seed).

  5. Test: Execute the n8n workflow manually to confirm the successful generation and polling process.

Node Details

On clicking 'execute' (Manual Trigger): Serves as the starting point, initiating this specific n8n workflow on command. This is the primary n8n trigger for manual execution.
Set API Key (Set): A crucial n8n node for securely injecting the required Replicate API key into the workflow data stream, which is then utilized for authorization headers.
Create Prediction (HTTP Request): Initiates the long-running task by making a POST request to the Replicate API, defining the use of the citoreh/nazanin model. This core n8n node starts the AI generation.
Extract Prediction ID (Code): This Code n8n node is essential for asynchronous processing. It extracts the job ID from the API response and dynamically creates the polling URL for the next steps in the n8n workflow.
Wait (Wait): Manages the polling interval, pausing the n8n workflow for 2 seconds to prevent rate-limiting issues while waiting for the AI job to finish.
Check Prediction Status (HTTP Request): Polls the dynamically constructed URL using the Replicate API key to retrieve the current status of the prediction job.
Check If Complete (If): The control flow n8n node that determines whether the job is complete (succeeded). If not, it routes the execution back to the 'Wait' n8n node, maintaining the polling loop structure.
Process Result (Code): The final processing n8n node that formats and extracts the generated image output URL and relevant metadata once the job status indicates success.

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*