How to generate AI images in an n8n workflow
In n8n, call an image API with the HTTP Request node, then use the Convert to File node to turn the base64 image into a binary file you can upload, email or post. n8n can't pay x402 calls on its own, so the practical route is our AI Image Generator on RapidAPI, paid by card, with a free plan of 10 images a month. The image comes back as a 1024×1024 JPEG.
Try it free Image Generation API — pictures from a text prompt · $0.03 / call
The workflow
- Trigger: a Form, a schedule, a new row in Google Sheets, or a chat message with the prompt.
- HTTP Request node: POST the prompt to the image API.
- Convert to File node: operation "Move Base64 String to File", source property: the image_base64 field (check the HTTP node's output panel for its exact path), file name image.jpg.
- Destination: Google Drive upload, Telegram "Send Photo", email attachment or a CMS node, all reading the binary property.
HTTP Request node settings (RapidAPI)
- Subscribe to a plan at https://rapidapi.com/VPNKorp/api/ai-image-generator32 (Free: 10 images a month; $9.99 for 500).
- Method: POST. URL: copy the endpoint from the RapidAPI code panel.
- Headers: X-RapidAPI-Key with your key (store it as an n8n credential, Header Auth) and X-RapidAPI-Host as shown on RapidAPI.
- Body: JSON, as below. Put the prompt from the trigger into it with an expression.
- Options: set Timeout to 60000 ms or more; generation takes a few seconds.
{
"prompt": "{{ $json.prompt }}",
"steps": 6
}
Why not call the x402 endpoint directly
POST https://iamai.markets/api/x402/services/ij0SpjTJvY-K answers 402 with the price first. Paying it means signing a USDC payment on Base with a wallet and repeating the request, which the stock HTTP Request node can't do.
If you run your own x402 client as a small service, n8n can call that instead. For most workflows the RapidAPI key is simpler.
Prompt tips that matter in automations
- Build prompts from a template plus fields, for example "flat illustration of {{ $json.topic }}, white background, no text". Consistent wording gives consistent images.
- Keep prompts under 2,000 characters; trim long text from the trigger first.
- Prompts asking for sexual, violent, hateful or self-harm images are refused. Add an IF node after the request to catch errors so one bad prompt doesn't stop the run.
- Output is always square. If you need 16:9, crop it in a later step or use the HD API from code.
Other ways to get images in n8n
| Option | How | Note |
|---|---|---|
| OpenAI node | Built-in node, image generation | Needs an OpenAI API key and billing |
| Any image API via HTTP Request | Same pattern as above | Check whether it returns a link or base64 |
| AI Image Generator on RapidAPI | HTTP Request with a RapidAPI key | Card plans, free 10 images a month |
The product
Questions
Does this work on n8n Cloud and self-hosted?
Yes, it only uses the HTTP Request and Convert to File nodes, which both have.
Can I test a prompt before building the workflow?
Yes, try it on the listing page: 5 free tries a day, no sign-up.
Related
Updated 2026-12-01
