Automated AI media creation with MagicHour AI and GPT-4 prompt optimization
This workflow automates AI-powered image and video generation using MagicHour.ai's API, enhanced by GPT-4.1 for intelligent prompt optimization. It processes webhook requests, refines prompts using AI, generates media content, and returns the final output.
Who's it for
Content creators, marketers, social media managers, and developers who need automated AI media generation at scale. Perfect for teams building applications that require on-demand image or video creation without manual intervention.
How it works
The workflow receives a webhook POST request containing generation parameters (type, orientation, style, duration). GPT-4.1 analyzes and optimizes the user's prompt based on the request type (image or video), then sends it to MagicHour.ai's API. The workflow monitors the generation status through polling loops, downloads the completed media, and returns it via webhook response. Error handling ensures failed requests are captured and reported.
Requirements
- n8n instance (self-hosted or cloud)
- MagicHour.ai account with API access (Bearer token)
- OpenAI API account for GPT-4.1 access
- Basic understanding of webhooks and JSON
How to set up
Configure credentials:
- Add MagicHour.ai Bearer token in HTTP Request nodes (ai-image-generator, text-to-video, Get Image Details, Get Video Details)
- Add OpenAI API credentials in both Generate Image Prompt and Generate video Prompt nodes
Activate the workflow:
- Enable the workflow to activate the webhook endpoint
- Copy the webhook URL from the Webhook trigger node
Test the workflow:
Download the n8n-magichour HTML tester Click here to download
For image generation, send a POST request with this structure:
{
"action": "generate",
"type": "image",
"parameters": {
"name": "My Image",
"image_count": 1,
"orientation": "landscape",
"style": {
"prompt": "A serene mountain landscape at sunset",
"tool": "realistic"
}
}
}
For video generation, use:
{
"action": "generate",
"type": "video",
"parameters": {
"name": "My Video",
"end_seconds": 5,
"orientation": "landscape",
"resolution": "1080p",
"style": {
"prompt": "A dog running through a field"
}
}
}
How to customize the workflow
Adjust AI prompt optimization: Modify the system prompts in Generate Image Prompt or Generate video Prompt nodes to change how GPT-4.1 refines user inputs. Current prompts enforce strict character limits and avoid unauthorized content.
Change polling intervals: Modify the Wait nodes to adjust how frequently the workflow checks generation status (useful for longer video renders).
Modify response format: Update the Respond to Webhook node to customize the output structure sent back to the caller.
Add multiple output formats: Extend Download Image/Video nodes to save files to cloud storage (Google Drive, S3) instead of just returning via webhook.
Implement queue management: Add a database node before MagicHour.ai calls to queue requests and prevent API rate limiting.
n8n Workflow: AI Media Creation with MagicHour.ai and GPT-4 Prompt Optimization
This n8n workflow automates the process of generating AI-optimized prompts and then using those prompts to create media via an external AI service. It's designed to streamline content creation by integrating advanced AI capabilities.
What it does
This workflow simplifies and automates the following steps:
- Receives a Trigger: The workflow starts by listening for an incoming webhook. This webhook likely contains initial data or a request to start the AI media creation process.
- Sets Initial Data: It then processes the incoming data, potentially setting or transforming fields for subsequent AI operations.
- Optimizes Prompt with OpenAI: It sends a request to OpenAI (likely using GPT-4 or a similar model) to optimize a prompt. This step enhances the initial prompt for better results from the media generation AI.
- Conditional Logic: It includes a conditional check (
Ifnode), which suggests that the workflow might branch based on the output of the OpenAI optimization or some other criteria. - Creates Media via HTTP Request: If the condition is met (or as a direct follow-up to the prompt optimization), it makes an HTTP request to an external API. This API is presumed to be
MagicHour.ai(based on the directory name) or a similar service that takes the optimized prompt and generates media. - Waits for Completion (Optional): A
Waitnode is included, indicating that the workflow might pause for a specified duration, possibly waiting for the media generation process to complete or for a callback. - Responds to Webhook: Finally, it responds to the initial webhook, indicating the status or providing the results of the media creation process.
Prerequisites/Requirements
To use this workflow, you will need:
- n8n Instance: A running n8n instance.
- OpenAI API Key: An API key for OpenAI to utilize models like GPT-4 for prompt optimization.
- MagicHour.ai Account/API Access: Access to the MagicHour.ai API (or a similar AI media creation service) to generate media.
- Webhook Source: An application or service that can send HTTP POST requests to trigger this workflow.
Setup/Usage
- Import the Workflow: Download the provided JSON and import it into your n8n instance.
- Configure Credentials:
- OpenAI Node: Configure your OpenAI API credentials in the "OpenAI" node (ID: 1250).
- HTTP Request Node: Configure the "HTTP Request" node (ID: 19) with the correct API endpoint and authentication details for your AI media creation service (e.g., MagicHour.ai).
- Activate the Webhook Trigger:
- The "Webhook" node (ID: 47) will generate a unique URL when activated. Copy this URL.
- Configure your external application or service to send POST requests to this URL to initiate the workflow.
- Adjust 'Edit Fields' Node: Modify the "Edit Fields" node (ID: 38) to correctly process and prepare the data received from your webhook for the OpenAI prompt optimization.
- Review 'If' Node Logic: Examine the "If" node (ID: 20) and adjust its conditions based on your specific requirements for branching the workflow.
- Configure 'Wait' Node: If necessary, adjust the duration in the "Wait" node (ID: 514) to accommodate the expected processing time of your media creation API.
- Test the Workflow: Run a test trigger from your external application to ensure the workflow executes as expected and generates the desired media.
Related Templates
Generate song lyrics and music from text prompts using OpenAI and Fal.ai Minimax
Spark your creativity instantly in any chat—turn a simple prompt like "heartbreak ballad" into original, full-length lyrics and a professional AI-generated music track, all without leaving your conversation. 📋 What This Template Does This chat-triggered workflow harnesses AI to generate detailed, genre-matched song lyrics (at least 600 characters) from user messages, then queues them for music synthesis via Fal.ai's minimax-music model. It polls asynchronously until the track is ready, delivering lyrics and audio URL back in chat. Crafts original, structured lyrics with verses, choruses, and bridges using OpenAI Submits to Fal.ai for melody, instrumentation, and vocals aligned to the style Handles long-running generations with smart looping and status checks Returns complete song package (lyrics + audio link) for seamless sharing 🔧 Prerequisites n8n account (self-hosted or cloud with chat integration enabled) OpenAI account with API access for GPT models Fal.ai account for AI music generation 🔑 Required Credentials OpenAI API Setup Go to platform.openai.com → API keys (sidebar) Click "Create new secret key" → Name it (e.g., "n8n Songwriter") Copy the key and add to n8n as "OpenAI API" credential type Test by sending a simple chat completion request Fal.ai HTTP Header Auth Setup Sign up at fal.ai → Dashboard → API Keys Generate a new API key → Copy it In n8n, create "HTTP Header Auth" credential: Name="Fal.ai", Header Name="Authorization", Header Value="Key [Your API Key]" Test with a simple GET to their queue endpoint (e.g., /status) ⚙️ Configuration Steps Import the workflow JSON into your n8n instance Assign OpenAI API credentials to the "OpenAI Chat Model" node Assign Fal.ai HTTP Header Auth to the "Generate Music Track", "Check Generation Status", and "Fetch Final Result" nodes Activate the workflow—chat trigger will appear in your n8n chat interface Test by messaging: "Create an upbeat pop song about road trips" 🎯 Use Cases Content Creators: YouTubers generating custom jingles for videos on the fly, streamlining production from idea to audio export Educators: Music teachers using chat prompts to create era-specific folk tunes for classroom discussions, fostering interactive learning Gift Personalization: Friends crafting anniversary R&B tracks from shared memories via quick chats, delivering emotional audio surprises Artist Brainstorming: Songwriters prototyping hip-hop beats in real-time during sessions, accelerating collaboration and iteration ⚠️ Troubleshooting Invalid JSON from AI Agent: Ensure the system prompt stresses valid JSON; test the agent standalone with a sample query Music Generation Fails (401/403): Verify Fal.ai API key has minimax-music access; check usage quotas in dashboard Status Polling Loops Indefinitely: Bump wait time to 45-60s for complex tracks; inspect fal.ai queue logs for bottlenecks Lyrics Under 600 Characters: Tweak agent prompt to enforce fuller structures like [V1][C][V2][B][C]; verify output length in executions
AI-powered code review with linting, red-marked corrections in Google Sheets & Slack
Advanced Code Review Automation (AI + Lint + Slack) Who’s it for For software engineers, QA teams, and tech leads who want to automate intelligent code reviews with both AI-driven suggestions and rule-based linting — all managed in Google Sheets with instant Slack summaries. How it works This workflow performs a two-layer review system: Lint Check: Runs a lightweight static analysis to find common issues (e.g., use of var, console.log, unbalanced braces). AI Review: Sends valid code to Gemini AI, which provides human-like review feedback with severity classification (Critical, Major, Minor) and visual highlights (red/orange tags). Formatter: Combines lint and AI results, calculating an overall score (0–10). Aggregator: Summarizes results for quick comparison. Google Sheets Writer: Appends results to your review log. Slack Notification: Posts a concise summary (e.g., number of issues and average score) to your team’s channel. How to set up Connect Google Sheets and Slack credentials in n8n. Replace placeholders (<YOURSPREADSHEETID>, <YOURSHEETGIDORNAME>, <YOURSLACKCHANNEL_ID>). Adjust the AI review prompt or lint rules as needed. Activate the workflow — reviews will start automatically whenever new code is added to the sheet. Requirements Google Sheets and Slack integrations enabled A configured AI node (Gemini, OpenAI, or compatible) Proper permissions to write to your target Google Sheet How to customize Add more linting rules (naming conventions, spacing, forbidden APIs) Extend the AI prompt for project-specific guidelines Customize the Slack message formatting Export analytics to a dashboard (e.g., Notion or Data Studio) Why it’s valuable This workflow brings realistic, team-oriented AI-assisted code review to n8n — combining the speed of automated linting with the nuance of human-style feedback. It saves time, improves code quality, and keeps your team’s review history transparent and centralized.
Synchronizing WooCommerce inventory and creating products with Google Gemini AI and BrowserAct
Synchronize WooCommerce Inventory & Create Products with Gemini AI & BrowserAct This sophisticated n8n template automates WooCommerce inventory management by scraping supplier data, updating existing products, and intelligently creating new ones with AI-formatted descriptions. This workflow is essential for e-commerce operators, dropshippers, and inventory managers who need to ensure their product pricing and stock levels are synchronized with multiple third-party suppliers, minimizing overselling and maximizing profit. --- Self-Hosted Only This Workflow uses a community contribution and is designed and tested for self-hosted n8n instances only. --- How it works The workflow is typically run by a Schedule Trigger (though a Manual Trigger is also shown) to check stock automatically. It reads a list of suppliers and their inventory page URLs from a central Google Sheet. The workflow loops through each supplier: A BrowserAct node scrapes the current stock and price data from the supplier's inventory page. A Code node parses this bulk data into individual product items. It then loops through each individual product found. The workflow checks WooCommerce to see if the product already exists based on its name. If the product exists: It proceeds to update the existing product's price and stock quantity. If the product DOES NOT exist: An If node checks if the missing product's category matches a predefined type (optional filtering). If it passes the filter, a second BrowserAct workflow scrapes detailed product attributes from a dedicated product page (e.g., DigiKey). An AI Agent (Gemini) transforms these attributes into a specific, styled HTML table for the product description. Finally, the product is created in WooCommerce with all scraped details and the AI-generated description. Error Handling: Multiple Slack nodes are configured to alert your team immediately if any scraping task fails or if the product update/creation process encounters an issue. Note: This workflow does not support image uploads for new products. To enable this functionality, you must modify both the n8n and BrowserAct workflows. --- Requirements BrowserAct API account for web scraping BrowserAct n8n Community Node -> (n8n Nodes BrowserAct) BrowserAct templates named “WooCommerce Inventory & Stock Synchronization” and “WooCommerce Product Data Reconciliation” Google Sheets credentials for the supplier list WooCommerce credentials for product management Google Gemini account for the AI Agent Slack credentials for error alerts --- Need Help? How to Find Your BrowseAct API Key & Workflow ID How to Connect n8n to Browseract How to Use & Customize BrowserAct Templates How to Use the BrowserAct N8N Community Node --- Workflow Guidance and Showcase STOP Overselling! Auto-Sync WooCommerce Inventory from ANY Supplier