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 - Change image size: In the HTTP Request node, update the
sizeparameter (e.g., 512×512) to generate smaller images for faster processing. - Add multiple images: Modify the
nparameter 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.
- 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.
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 ✏️
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 ✅
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.