AI-Powered Instagram Content Generation from Trends - n8n Workflow

Automate Instagram content creation using this powerful n8n workflow. Scrape trending posts, leverage OpenAI and Replicate AI to generate unique images and engaging captions, and manage automated publishing.

Workflow Preview

Ready to automate?

Download this n8n workflow template and start using it instantly.

Who is this best for?


  • Social Media Managers needing automated, trend-relevant content.

  • Content Creators focusing on 3D art, design, or visual media.

  • Digital Agencies looking for advanced, AI-driven n8n templates for clients.

  • Users wanting a complex, scheduled n8n workflow that integrates scraping, database logic, and multiple AI services.

Overview

Maintaining a fresh and relevant social media presence requires constant trend monitoring and content creation. This advanced n8n workflow solves the tedious manual process by automating the discovery, generation, and publishing stages entirely. It uses RapidAPI to scrape top trending Instagram posts based on specific hashtags (like #blender3d and #isometric). After filtering and deduplicating content against a PostgreSQL database, the workflow leverages OpenAI's analysis capabilities to describe the image and generate high-quality, SEO-friendly captions. Crucially, it uses Replicate's Flux model to generate an entirely new, unique image based on the analyzed prompt, avoiding copyright issues while replicating the aesthetic trend. The final content is then automatically published to an Instagram Business Account, with all status updates monitored and reported via Telegram. This comprehensive n8n node sequence ensures continuous, automated, and trend-aware content delivery.

How it Works

This n8n workflow executes on a predefined schedule (using the n8n trigger node) at 13:05 and 19:05 daily, ensuring timely content drops.


  1. Initialization and Scraping: The workflow first retrieves critical credentials (Instagram ID, Telegram Chat ID, Rapid API Key, Replicate Token) using Set n8n nodes. It then uses the HTTP Request n8n node to query RapidAPI for top posts under specified hashtags.

  2. Filtering and Merging: Two Code n8n nodes filter the scraped results to include only images and normalize the data fields (prompt, code, thumbnail URL). The results are combined using the Merge n8n node.

  3. Deduplication: The workflow iterates through each item using the Loop Over Items n8n node. A Postgres n8n node checks the database (top_trends table) for existing content codes. If the content is new, it proceeds; otherwise, the If Data is Exist n8n node skips the item.

  4. Database Recording & AI Analysis: New content metadata is inserted into the PostgreSQL database. Next, the OpenAI (Langchain) n8n node analyzes the trend image thumbnail and generates a detailed description. A second OpenAI n8n node uses this description to generate an engaging Instagram caption complete with relevant hashtags.

  5. Image Generation: An HTTP Request n8n node calls the Replicate API (Flux Schnell model) using the detailed AI description to generate a unique, stylized image, utilizing a Prefer: wait header for immediate results.

  6. Instagram Publication: The Facebook Graph API n8n node prepares the media (image URL and caption) for upload. The n8n workflow then enters a monitoring loop: it checks the media status (Check Status Of Media Before Uploaded). If the status is FINISHED, the If media status is finished n8n node triggers the final publication.

  7. Notification: Post-publication, the status is checked again. If the content is PUBLISHED, a success message is sent via a Telegram n8n node. Error paths throughout the n8n template ensure immediate Telegram notifications if database connection or media upload issues arise.

Installation Guide

To use this powerful n8n workflow, follow these steps:


  1. Import: Copy the provided JSON data and import it into your n8n instance as a new workflow.

  2. Credentials: Set up the required credentials for the n8n nodes:

Postgres: Connect your PostgreSQL database, ensuring the toptrends table is created as specified in the sticky notes.
OpenAI API: Configure your OpenAI account credentials.
Facebook Graph API: Set up credentials for your Instagram Business Account connection.
Telegram API: Configure your Telegram bot credentials.

  1. Parameter Configuration: Update the initial Set n8n nodes with your specific IDs and keys:

Replicate params: Input your replicatetoken.
Instagram params: Input your instagrambusinessaccountid.
Telegram Params: Input your telegramchat_id.
Rapid Api params: Input your x-rapid-api-key (used for the Instagram Scraper).

  1. Activation: Once all credentials and parameters are configured, activate the n8n workflow. It will run automatically based on the schedule defined in the initial n8n trigger.

Node Details

Schedule Trigger1 (n8n trigger): Initiates the flow based on a cron schedule (5 13,19 ), allowing for twice-daily execution of the entire n8n workflow.
HTTP Request (get trends): Uses the Instagram Scraper RapidAPI key to retrieve top trending posts for specific hashtags like #blender3d and #isometric.
Code (filter content): Filters the scraped results, ensuring only image posts are processed, and extracts key data points such as the prompt text and thumbnail URL.
Postgres (Check Data on Database Is Exist): This n8n node performs a lookup in the top_trends table to prevent publishing duplicate content, utilizing the content code as the unique identifier.
OpenAi (Analyze Image): An advanced LangChain n8n node using GPT-4o-mini to visually analyze the trending post's thumbnail URL and generate a detailed description, crucial for prompt engineering.
OpenAi (Generate Instagram Caption): Generates a concise, engaging Instagram caption (under 150 words) based on the image description, automatically including relevant hashtags. This is a key step in this n8n template.
HTTP Request (Generate image on flux): Calls the Replicate AI API to generate a new, unique image, based on the AI-generated detailed description, using the powerful Flux Schnell model.
Facebook Graph API (Prepare data on Instagram): Uploads the newly generated image and AI caption to Instagram's content queue, starting the publishing process within this robust n8n workflow.
If (If media status is finished): Controls the publishing flow, ensuring the media is ready before the final publication command is issued.


  • Telegram (Telegram1): Sends a successful publication confirmation message once the post status is confirmed as PUBLISHED by the final Check status of post n8n node.

Related n8n Workflows

Free

Nodes: 12 Nodes
Updated: December 26 2025
View all
Created by
mustafa kendigüzel
mustafa kendigüzel

Full-stack developer with 5+ years of experience in scalable software solutions. Skilled in Node.js, NestJS, PostgreSQL, and cloud platforms like AWS and Google Cloud. Expertise in microservices, real-time data processing, and API development. Passionate about delivering high-performance applications and driving innovation through cutting-edge technologies.

Featured*