Animated data flow diagram

Flux AI Image Generator Agent with n8n & Hugging Face

Version: 1.0.0 | Last Updated: 2025-05-16

Integrates with:

Hugging Face AWS S3 HTML5

Overview

Unlock On-Demand AI Image Creation with this AI Agent

This AI Agent empowers you to generate unique, high-quality images directly from text prompts and predefined artistic styles. It provides a simple web form where you can input your desired image description and select a style. The agent then uses powerful AI models via the Hugging Face Inference API (like FLUX.1-schnell) to create the image. The final artwork is automatically uploaded to your S3-compatible storage (e.g., Cloudflare R2) and displayed on a results page, showcasing the generated image and even recent creations. This is perfect for quickly producing visuals for marketing, content, or presentations without needing complex design software.

Key Features & Benefits

  • AI-Powered Image Generation: Leverages cutting-edge text-to-image models from Hugging Face (e.g., FLUX.1-schnell, with options to use others) to turn your ideas into visuals.
  • Simple Form Input: An easy-to-use web form (via n8n Form Trigger) allows anyone to submit image prompts and choose from various artistic styles like 'Hyper-Surreal Escape', 'Neon Fauvism', and 'AI Dystopia'.
  • Customizable Styles: Comes with several predefined style prompts that inject specific artistic parameters (e.g., 'rule of thirds', 'cyberpunk', 'octane render') to guide the AI. You can easily modify these or add your own.
  • Automated S3 Upload: Generated images are automatically saved to your configured S3-compatible object storage, making them accessible and shareable.
  • Instant Webpage Display: A dynamic webpage is served back to the user, displaying the newly generated image and links to the template. It can also show previously generated images.
  • Error Handling: Includes basic error handling to inform the user if the image generation API encounters an issue.
  • Flexible Model Choice: While defaulted to FLUX.1-schnell, the Hugging Face node can be configured to use other compatible text-to-image models.

Use Cases

  • B2C E-commerce: Quickly generate unique product mockups or marketing creatives for social media campaigns and advertisements.
  • B2B SaaS: Create custom illustrations and graphics for blog posts, feature announcements, social media content, or sales presentations without significant design overhead.
  • Solopreneurs & Creators: Easily produce eye-catching visuals for branding, website content, course materials, or promotional ads on a budget.
  • Marketing Agencies: Rapidly prototype and generate diverse visual concepts for client campaigns, enhancing creative output and turnaround times.

Prerequisites

  • An n8n instance (Cloud or self-hosted).
  • Hugging Face API Key with access to text-to-image inference models (e.g., black-forest-labs/FLUX.1-schnell).
  • Credentials for an S3-compatible object storage service (e.g., Cloudflare R2, AWS S3) and a bucket configured for public read access if you intend to use the default webpage image display method.

Setup Instructions

  1. Download the n8n workflow JSON file.
  2. Import the workflow into your n8n instance.
  3. The 'n8n Form Trigger' node creates a public form. Note its webhook URL (e.g., your-n8n-domain/form/flux4free) to access the image generation form.
  4. In the 'Call hugginface inference api' node:
    • Go to the 'Authentication' parameter and select 'Generic Credential Type'. For 'Generic Auth Type', choose 'HTTP Header Auth'.
    • Click 'Create New Credential' for 'HTTP Header Auth'. Give your credential a name (e.g., 'Hugging Face Key'). Add one header: Name: Authorization, Value: Bearer YOUR_HUGGING_FACE_API_KEY. Replace YOUR_HUGGING_FACE_API_KEY with your actual key.
    • (Optional) You can change the Hugging Face model by modifying the URL in the 'URL' parameter (e.g., to https://api-inference.huggingface.co/models/black-forest-labs/FLUX.1-dev).
  5. In the 'Upload image to S3' node:
    • Configure your S3 credentials in the 'Credential' parameter.
    • Set the 'Bucket Name' to your desired S3 bucket.
    • Ensure this bucket allows public read access for the generated images if you want them to be displayed on the output page using the default HTML.
  6. In the 'Serve webpage' node (and 'Respond with error' if customizing further):
    • Review the HTML in the 'Response Body'. If your S3 public URL structure differs from the example (https://pub-d2d94462851644a78ea607e05f8a2d25.r2.dev/fg-{{ $execution.id }}.jpg), update the src attributes for <img> tags accordingly. The fg-{{ $execution.id }}.jpg part generates the dynamic filename.
  7. (Optional) Customize the 'stylePrompt' values in the various 'Set' nodes (e.g., 'Hyper-Surreal Escape', 'AI Dystopia') to fine-tune existing artistic styles or add new ones by duplicating and modifying these nodes, then connecting them to the 'Route by style' Switch node.
  8. Activate the workflow. Access the form via the URL from step 3 to start generating images.

Tags:

AI AgentImage GenerationHugging FaceAutomationCreative AIContent CreationS3FLUX

Want your own unique AI agent?

Talk to us - we know how to build custom AI agents for your specific needs.

Schedule a Consultation