How to loop image generation in n8n?

Hi everyone,

I’ve created a simple workflow in n8n that allows me to generate a detailed prompt from a short sentence using the OpenAI Message node. This optimized prompt is then used to generate an image via DALL·E 3, and I send the result to Slack.

Now I would like to implement a loop that allows me to generate multiple images from the same input — for example, 5 images based on a single sentence.

The idea is: I enter one sentence describing what kind of image I want, and the workflow should automatically generate 5 different images and send them to me.

What would be the best way to set this up in n8n?
Would you recommend using the Loop node, or a counter-based approach with Set and IF nodes?

Thanks a lot for your help!

Share the output returned by the last node

Information on your n8n setup

  • n8n version:
  • Database (default: SQLite):
  • n8n EXECUTIONS_PROCESS setting (default: own, main):
  • Running n8n via (Docker, npm, n8n cloud, desktop app):
  • Operating system:

Hi @Sebastian_Irmer Welcome to :n8n: n8n community :tada:

For this situation, I would use the loop node with the “Reset” option activated because we only receive 1 item from the chat node.,

Then you can leverage the use of {{ $runIndex }} in an If node to specify how many times do you want to run it…

Something like this:

1 Like

Very nice.

I’ve spent some time working with ComfyUI and I’m currently trying to build up my knowledge of n8n. I find the loop mechanics a bit unintuitive at first, but once you understand the underlying concept, it’s actually pretty straightforward. Thanks a lot for the quick help!

1 Like

You’re welcome!

Yeah, the loop stuff can definitely be tricky—just watch out for infinite loops! :sweat_smile:

I had one sneak up on me during testing and it totally broke my instance. Lesson learned the hard way! :joy:

Also, do not forget the loops docs, it’s so helpful:

:link: Loop Over Items (Split in Batches) | n8n Docs

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.