Automated Portrait Series Generation via Replicate AI - n8n Workflow

Use this robust n8n workflow template to automate the creation of portrait image series from a single input using the Replicate API. Features resilient polling and error handling.

Workflow Preview

Ready to automate?

Download this n8n workflow template and start using it instantly.

Who is this best for?


  • Developers building AI-powered applications or tools.

  • Automation specialists needing resilient n8n templates for external API calls.

  • Creatives and marketers looking to rapidly generate image assets using the flux-kontext-apps/portrait-series model.

  • Users seeking advanced examples of asynchronous handling within an n8n node structure.

Overview

This comprehensive n8n workflow provides a production-ready solution for leveraging powerful AI models on Replicate. Specifically, it targets the flux-kontext-apps/portrait-series model to generate multiple, high-quality portrait images from a single source input. Unlike simple synchronous calls, this n8n template manages the entire asynchronous lifecycle: initiating the prediction, logging the request ID, waiting, and repeatedly checking the status until the image generation succeeds or fails. This critical polling logic ensures that even long-running AI tasks are handled reliably within your n8n infrastructure. Every n8n node is configured for maximum efficiency, providing structured success and error responses, making this a highly valuable n8n workflow for image automation.

How it Works

The process begins with the Manual Trigger, which acts as the initial n8n trigger for execution.


  1. Configuration: The flow first uses a Set n8n node to define the required Replicate API token and another Set n8n node (Set Image Parameters) to configure inputs like the source inputimage, numimages, and background details for the AI model.

  2. Request Initiation: The Create Image Prediction HTTP Request n8n node sends a POST request to the Replicate API, starting the image generation task. It receives a prediction ID and logs it using the Log Request Code n8n node.

  3. Polling Loop: The n8n workflow enters a polling loop. It first pauses via the Wait 5s n8n node. It then uses the Check Status HTTP Request n8n node to fetch the current status of the prediction using the received ID.

  4. Decision Making: The Is Complete? If n8n node checks if the status is 'succeeded'.

If successful, the output image URL is captured and formatted by the Success Response n8n node.
If not successful, the flow moves to the Has Failed? If n8n node, checking for the 'failed' status.
If failed, the Error Response n8n node formats the failure message.
If neither 'succeeded' nor 'failed' (meaning it is still processing), the flow hits the Wait 10s n8n node before looping back to Check Status to poll again.

  1. Final Output: Regardless of success or failure, the results are consolidated and displayed by the final Display Result n8n node, completing the execution of this complex n8n workflow.

Installation Guide

To deploy this powerful n8n workflow, follow these steps:


  1. Import: Copy the provided JSON data and import it directly into your n8n instance via the 'New' menu and 'Import from JSON'. This instantly sets up the entire n8n workflow structure.

  2. API Key Setup: Locate the Set API Token n8n node. Edit this node and replace the placeholder YOURREPLICATEAPITOKEN with your actual Replicate API key. Ensure this key is correct, as it is essential for the Create Image Prediction n8n node.

  3. Parameter Customization: Open the Set Image Parameters n8n node. Update the inputimage URL to point to the source image you wish to use. Adjust optional parameters like num_images (default 4) or background as needed.

  4. Execution: Once configured, click the 'Manual Trigger' n8n trigger node and run the n8n workflow to test the image generation process.

Node Details

This n8n workflow utilizes several key n8n node types to achieve reliable asynchronous AI generation:

Manual Trigger: The starting n8n trigger point for manually executing the workflow.
Set API Token / Set Image Parameters (Set n8n node): Used for initializing variables, securely storing the API key, and setting the required model inputs (e.g., inputimage, numimages). This decoupling makes the n8n workflow easier to manage.
Create Image Prediction (HTTP Request n8n node): The core action n8n node that initiates the AI generation. Key configuration includes using the POST method, setting the Authorization: Bearer {{ $json.api_token }} header, and passing the dynamic image input parameters in the JSON body.
Log Request (Code n8n node): A utility n8n node used for monitoring and debugging, ensuring the prediction ID is logged after the initial API call.
Wait 5s / Wait 10s (Wait n8n node): Essential for managing the polling delay, ensuring the n8n workflow doesn't overwhelm the Replicate API while waiting for results.
Check Status (HTTP Request n8n node): Repeatedly polls the status URL (/v1/predictions/{{ id }}) using the prediction ID to monitor progress.
Is Complete? / Has Failed? (If n8n node): These conditional n8n nodes implement the core polling logic, directing the flow based on whether the AI job has 'succeeded', 'failed', or is still 'processing'.
Success Response / Error Response (Set n8n node): Used to structure the final output data, ensuring the consumer of this n8n workflow receives a clear, standardized JSON object detailing the result or the error.

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*