Automate OpenAI Image Editing with n8n Workflow

Discover how this n8n workflow automates OpenAI ImageGen v1 image editing via chat triggers, saving you hours with seamless integration and instant image conversion.
chatTrigger
httpRequest
convertToFile
+2
Learn how to Build this Workflow with AI:
Workflow Identifier: 1618
NODES in Use: chatTrigger, set, httpRequest, convertToFile, stickyNote

Press CTRL+F5 if the workflow didn't load.

Visit through Desktop for Best experience

Opening Problem Statement

Meet Sarah, a freelance graphic designer who spends countless hours manually editing client images to meet specific creative prompts. With each project, she juggles sending images to different platforms, waiting for edits, and converting files to usable formats. This manual back-and-forth wastes Sarah at least 3-4 hours daily, delaying project delivery and increasing her workload stress.

Sarah desperately needs a streamlined solution that can automatically edit images based on textual instructions, handle image input seamlessly, and output ready-to-use files without manual intervention. That’s where this unique n8n workflow steps in.

What This Automation Does

This n8n workflow revolutionizes image editing by integrating OpenAI’s ImageGen v1 API with chat inputs and automated file conversion. When triggered, it:

  • Listens for chat messages containing image editing prompts and source images.
  • Extends OpenAI’s image edit requests by sending the prompt and image to the OpenAI API.
  • Receives the edited image in base64 format and converts it automatically to a binary file suitable for downloads or uploads.
  • Prepares the image for downstream automation like emailing, storing on cloud platforms, or posting on social media.
  • Saves Sarah at least 2-3 hours per project by automating the entire process from prompt to edited file.

Prerequisites ⚙️

  • n8n account (cloud or self-hosted). If you’re interested in self-hosting, check out Hostinger’s n8n setup guide.
  • OpenAI API key with access to ImageGen v1 capabilities.
  • Basic familiarity with n8n interfaces for setting up HTTP Request and Chat Trigger nodes.

Step-by-Step Guide

Step 1: Configure the Chat Trigger Node to Receive Image Prompts

Navigate to the “When chat message received” node. This node listens for new chat messages that include both text prompts and image attachments.

Under the node settings, enable the Allow File Uploads option and permit all MIME types (*) to accept any image formats.

This sets the stage to catch user input for image editing.

Common mistake: Forgetting to enable file uploads, causing image data not to be received.

Step 2: Set the OpenAI API Key

Click the “API KEY” node, and add your OpenAI API key in the assigned openAIKey field. This securely injects your authorization token into subsequent requests.

You can find your key at your OpenAI account dashboard.

Tip: Never share your key publicly and store it securely in n8n credentials.

Step 3: Set Up the HTTP Request Node for OpenAI Image Edit

Open the “HTTP Request” node and configure it as follows:

  • Method: POST
  • URL: https://api.openai.com/v1/images/edits
  • Authentication: Add a header with Authorization: Bearer {{ $json.openAIKey }}.
  • Content Type: multipart/form-data
  • Body Parameters:
    • image: pass the binary data from the chat input field named data0.
    • prompt: set dynamically from chat input text: {{ $('When chat message received').item.json.chatInput }}.
    • Model: gpt-image-1
    • Number of images: 1
    • Size: 1024x1024
    • Quality: high

    Save your settings.

    Common mistake: Failing to bind the chat input correctly, leading to incomplete API requests.

    Step 4: Convert API Response Base64 to Binary File

    Attach and configure the “Convert to File” node. Set it to convert the base64 encoded image found under the property data[0].b64_json into a binary file.

    This step is crucial to transform OpenAI’s raw image data into a usable file format, such as PNG or JPEG, for further processing.

    Expected outcome: The node outputs the edited image as a file attached to the workflow data for easy download or cloud upload.

    Customizations ✏️

    • Change image size: In the HTTP Request node, update the size parameter (e.g., 512×512) to generate smaller images for faster processing.
    • Add multiple images: Modify the n parameter to request more than one edited image per prompt.
    • Integrate storage nodes: Add nodes to upload converted files directly to Supabase or AWS S3 buckets for automated cloud backups.
    • Send via Email: Chain a Gmail node after the conversion to email the edited image to clients immediately.

    Troubleshooting 🔧

    Problem: “401 Unauthorized” or API Key Rejected

    Cause: Incorrect or expired OpenAI API key.

    Solution: Verify the API key in the “API KEY” node. Regenerate your OpenAI key from the platform if needed and update the node configuration.

    Problem: Image Upload Fails at Chat Trigger Node

    Cause: File uploads not enabled or MIME types restricted.

    Solution: In the “When chat message received” node, enable file uploads and set allowed MIME types to *.

    Pre-Production Checklist ✅

    • Test chat triggers with various image formats to ensure uploads succeed.
    • Confirm API key is valid and has ImageGen access.
    • Validate that HTTP Request’s body parameters dynamically receive chat input.
    • Ensure Convert to File node outputs correctly by inspecting binary data post-run.
    • Run a full test from chat message to final image file conversion.

    Deployment Guide

    Activate the workflow by turning it on in n8n and expose the webhook URL from the chat trigger node.

    Monitor incoming messages and API responses via the n8n execution logs. Consider setting up email notifications for failure alerts.

    This setup requires no additional infrastructure beyond n8n and OpenAI API credentials, making deployment straightforward and quick.

    FAQs

    Q1: Can I use another OpenAI model for image edits?
    Yes, replace the model parameter in the HTTP Request node with your preferred version if supported.

    Q2: Does this workflow consume a lot of API credits?
    Each image edit request counts against your OpenAI usage quota, so monitor your API consumption accordingly.

    Q3: Is it secure to upload images via chat trigger?
    The workflow runs under your n8n instance security. Make sure to secure your webhook URL to prevent unauthorized usage.

    Conclusion

    With this n8n workflow, Sarah automated her image editing pipeline, cutting down daily manual work by hours and accelerating her project deliveries. By integrating OpenAI’s ImageGen, she transforms text prompts into edited images instantly and manages files effortlessly.

    Now it’s your turn to set this up, saving time and expanding your creative possibilities. For next steps, explore automating image distribution via email, incorporating watermarking nodes, or building a full SaaS AI image editing service using similar n8n flows.

Related Workflows

Automate Viral UGC Video Creation Using n8n + Degaus (Beginner-Friendly Guide)

Learn how to automate viral UGC video creation using n8n, AI prompts, and Degaus. This beginner-friendly guide shows how to import, configure, and run the workflow without technical complexity.
Form Trigger
Google Sheets
Gmail
+37
Free

AI SEO Blog Writer Automation in n8n (Beginner Guide)

A complete beginner guide to building an AI-powered SEO blog writer automation using n8n.
AI Agent
Google Sheets
httpRequest
+5
Free

Automate CrowdStrike Alerts with VirusTotal, Jira & Slack

This workflow automates processing of CrowdStrike detections by enriching threat data via VirusTotal, creating Jira tickets for incident tracking, and notifying teams on Slack for quick response. Save hours daily by transforming complex threat data into actionable alerts effortlessly.
scheduleTrigger
httpRequest
jira
+5
Free

Automate Telegram Invoices to Notion with AI Summaries & Reports

Save hours on financial tracking by automating invoice extraction from Telegram photos to Notion using Google Gemini AI. This workflow extracts data, records transactions, and generates detailed spending reports with charts sent on schedule via Telegram.
lmChatGoogleGemini
telegramTrigger
notion
+9
Free

Automate Email Replies with n8n and AI-Powered Summarization

Save hours managing your inbox with this n8n workflow that uses IMAP email triggers, AI summarization, and vector search to draft concise replies requiring minimal review. Automate business email processing efficiently with AI guidance and Gmail integration.
emailReadImap
vectorStoreQdrant
emailSend
+12
Free

Automate Email Campaigns Using n8n with Gmail & Google Sheets

This n8n workflow automates personalized email outreach campaigns by integrating Gmail and Google Sheets, saving hours of manual follow-up work and reducing errors in email sequences. It ensures timely follow-ups based on previous email interactions, optimizing communication efficiency.
googleSheets
gmail
code
+5
Free