AI Avatar Generation with Replicate Polling Logic - n8n Workflow

Use this comprehensive n8n workflow to automate AI avatar generation via the Replicate babysea/babyavatar model. This n8n template expertly handles asynchronous job polling.

Workflow Preview

Ready to automate?

Download this n8n workflow template and start using it instantly.

Who is this best for?

AI content creators and artists needing automated avatar generation.
Developers building applications that require integrating Replicate AI services.
Users looking for an advanced n8n template demonstrating reliable API polling logic.
Automation specialists seeking pre-built n8n workflows for complex, delayed tasks.

Overview

Generating complex AI images, especially avatars, often involves asynchronous APIs, meaning the initial request triggers a job, and the results must be periodically checked (polled) until completion. This can be challenging to implement reliably. This specialized n8n workflow solves this problem by providing a stable, production-ready polling mechanism for Replicate’s babysea/babyavatar model. By utilizing this n8n workflow, users can initiate avatar creation on demand, automate the waiting period using the designated n8n node, and seamlessly retrieve the final high-resolution image output. This highly efficient n8n template ensures minimal latency and maximum reliability for your AI automation tasks.

How it Works

This automation starts with the 'On clicking 'execute'' n8n trigger, allowing for manual execution or integration into larger n8n workflows.


  1. API Key Setup: The 'Set API Key' n8n node securely stores the Replicate API key, dynamically preparing it for subsequent HTTP calls.

  2. Create Prediction: The first 'Create Prediction' HTTP Request n8n node sends a POST request to Replicate, initiating the avatar generation job using the specified model (babysea/babyavatar). This request defines parameters like seed, width, height, and number of outputs.

  3. Extract ID: The 'Extract Prediction ID' Code n8n node immediately processes the response, extracting the unique predictionId and constructing the specific URL needed for status checking.

  4. Wait: The 'Wait' n8n node pauses the execution for a short period (e.g., 2 seconds) to avoid hammering the API, which is critical for good API hygiene.

  5. Polling Loop (Check Status): The 'Check Prediction Status' HTTP Request n8n node queries the status URL using the extracted ID.

  6. Conditional Check: The 'Check If Complete' If n8n node evaluates the status. If the status is 'succeeded', the n8n workflow proceeds to 'Process Result'. If the status is anything else (e.g., 'processing', 'starting'), the flow loops back to the 'Wait' n8n node, continuing the polling cycle until the AI generation is finalized.

  7. Process Result: The final 'Process Result' Code n8n node structures the successful output, returning the image URL and metadata for further use in the larger n8n workflow.

Installation Guide

To install and utilize this robust n8n workflow, follow these steps:


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

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

  3. Authentication: Ensure the HTTP Request n8n nodes ('Create Prediction' and 'Check Prediction Status') are using the generic HTTP Header Authentication setup defined in the provided n8n template, referencing the key set in the previous step.

  4. Activate and Test: Save the n8n workflow, ensure it is marked as 'Active' (if using a non-manual trigger, though this uses a manual n8n trigger for testing), and click 'Execute Workflow' to test the full polling sequence.

Node Details

On clicking 'execute' (Manual Trigger n8n trigger): Initiates the n8n workflow manually for testing or as the starting point for a larger automation. This essential n8n trigger allows on-demand avatar generation.
Set API Key (Set n8n node): A utility n8n node used to define the replicateapikey variable, ensuring the sensitive key is stored and referenced securely across multiple HTTP calls.
Create Prediction (HTTP Request n8n node): Submits the asynchronous job to Replicate. Key configuration includes using a POST method, specifying the model version, and setting authentication headers using an expression that includes the API key.
Extract Prediction ID (Code n8n node): A custom scripting n8n node that pulls the unique id from the initial Replicate response and generates the necessary predictionUrl for subsequent polling requests.
Wait (Wait n8n node): Controls the polling frequency, pausing the n8n workflow for 2 seconds between status checks to prevent API rate limiting.
Check Prediction Status (HTTP Request n8n node): The core polling n8n node. It GETs the status using the dynamically generated predictionUrl until a result is returned.
Check If Complete (If n8n node): Manages the loop control. This crucial logic n8n node checks if the status equals 'succeeded'. If true, the n8n workflow exits the loop; otherwise, it returns to the 'Wait' n8n node to continue polling.
Process Result (Code n8n node): Parses the final successful JSON output, extracting the generated image URLs and relevant completion metadata for downstream actions within 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*