Automated Photorealistic Image Generation via Replicate API - n8n Workflow

Use this robust n8n workflow to generate high-quality, photorealistic images using the black-forest-labs/flux-krea-dev model on Replicate. Features automated polling and error handling.

Workflow Preview

Ready to automate?

Download this n8n workflow template and start using it instantly.

Who is this best for?

Creative Agencies & Marketers: Rapidly prototype visuals for campaigns using AI.
Developers & Integrators: Users looking for production-ready n8n templates integrating external AI APIs.


  • n8n Automation Specialists: Individuals needing a complex example of API polling, flow control, and error handling within an n8n workflow.

Overview

This comprehensive n8n workflow provides a robust solution for integrating powerful AI image generation capabilities—specifically the highly acclaimed black-forest-labs/flux-krea-dev model—into any business process. Since AI generation is an asynchronous task, a major challenge is waiting for the result. This n8n workflow solves this through intelligent, automated polling logic using the HTTP Request n8n node.

By leveraging this pre-built n8n template, users can initiate an image request, automatically handle the waiting period, check the status repeatedly, and cleanly route the process to a success path (returning the image URL) or an error path (returning failure details). This structured approach makes the n8n workflow production-ready, featuring full parameter configuration and logging via dedicated n8n node steps.

How it Works

This n8n workflow is initiated by a Manual Trigger n8n trigger for immediate testing and execution.


  1. Initialization: The workflow starts by defining credentials in the Set API Token n8n node and crucial generation parameters (like prompt, aspect_ratio, and guidance) in the Set Image Parameters n8n node.

  2. Request Submission: The Create Image Prediction n8n node (an HTTP Request node) sends the generation parameters to the Replicate API, starting the background process and receiving a Prediction ID.

  3. Initial Wait & Log: The workflow logs the request details using a Code n8n node, then pauses for 5 seconds using the Wait 5s n8n node.

  4. Polling Loop: The Check Status n8n node polls Replicate using the Prediction ID to fetch the current status.

  5. Flow Control: The Is Complete? n8n node checks if the status is succeeded.

If Success, the flow routes to the Success Response n8n node, which formats the final output, including the generated image URL.
If Not Succeeded, the Has Failed? n8n node checks for a failed status. If Failed, it routes to the Error Response n8n node.
* If the status is still running/processing, the workflow routes to the Wait 10s n8n node, which pauses execution before looping back to the Check Status n8n node, continuing the polling cycle until completion.

  1. Final Output: Both success and error paths converge at the Display Result n8n node, presenting the outcome in a clean, structured JSON format.

Installation Guide

To deploy this powerful n8n workflow and start generating images, follow these steps:


  1. Import the n8n Template: Copy the provided JSON data and import it directly into your self-hosted or cloud n8n instance using the 'New' -> 'Import from JSON' feature.

  2. Obtain Replicate API Key: Sign up for an account at Replicate and retrieve your API token.

  3. Configure Credentials: Locate the Set API Token n8n node (Position: -608,-80). Replace the placeholder value YOURREPLICATEAPITOKEN with your actual Replicate API key.

  4. Customize Generation: Adjust the parameters in the Set Image Parameters n8n node (Position: -288,-128). Here, you can change the prompt, aspectratio, num_outputs, and other model settings.

  5. Execution: Activate the n8n workflow, and click the 'Manual Trigger' n8n trigger to run the first test execution. Review the output of the final n8n node to confirm the image URL or error message.

Node Details

Manual Trigger (n8n trigger): The starting point for this specific n8n workflow. Used here for manual testing and demonstration.
Set API Token (n8n node): A Set n8n node used to securely store and pass the Replicate Bearer Token into subsequent HTTP Request nodes.
Set Image Parameters (n8n node): Defines all input parameters for the AI model, including the text prompt, seed, guidance, and required technical settings like aspectratio and outputformat.
Create Image Prediction (HTTP Request n8n node): Sends the initial POST request to the Replicate API. Key configuration: Uses POST method, sends the generation inputs in the JSON body, and includes the Authorization: Bearer {{ $json.api_token }} header.
Check Status (HTTP Request n8n node): Used within the polling loop. Sends a GET request to the specific prediction ID endpoint to retrieve the current status (starting, processing, succeeded, or failed).
Is Complete? (If n8n node): The core flow control mechanism. Checks if the status equals succeeded. This n8n node routes the workflow either to success or continues the polling.


  • Wait 5s / Wait 10s (n8n node): Essential for asynchronous API handling, preventing unnecessary rapid polling and managing resource usage while waiting for the AI model to finish generating the image. This clever use of the Wait n8n node ensures efficient resource management within the overall n8n workflow structure.

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*