OpenAI API - Repeat String to List
One Prompt, N Requests, No Guessing the Count
- Strings
What it is
Take one complete prompt and make N copies of it as a string list. That's it, and it's the piece that makes image batching work.
Here's the situation it solves. You have a batch of twelve images and you want the same instruction applied to each - "describe this image as a booru tag list, no preamble." Chat completion in a batch needs a prompt per request, and the batch node checks that its prompt count matches its image-group count. You could paste the same prompt twelve times. Or you could wire the group count in and let the node do it - and then, when you switch to a batch of thirty, nothing breaks.
The important difference from Multiline String to List: this node preserves the text exactly, whitespace and line breaks included. So a multi-paragraph prompt with internal formatting survives as one prompt, repeated. The other node is for many short lines; this one is for one long text, copied.
How it works
count copies of text come out as a real ComfyUI execution list. Batched Chat Completion is an input-list node, so it receives the whole list and iterates it itself, sending one independent request per copy - that's what keeps positions aligned with the image groups on the other input.
Which is the neat part: the Count output of Image Batch to List plugs straight into this node's Count input. Then the number of prompts is, by construction, the number of image groups, and the "prompts and image_batches must have equal lengths" error becomes something you can't hit. Wire it that way even when you know the number. You'll thank yourself when the batch size changes.
Two of these chained is legal and proves nothing useful - if you need two different strings per request, that's a prompting problem, not a plumbing one.
Inputs and outputs
- Text (
text) - multiline STRING, default empty. "The complete prompt to repeat for each request." - Count (
count) - integer, default 1, minimum 1. The tooltip points at the intended wiring: "optionally connect the Image Batch to List count output."
Output: Strings - a STRING execution list of repeated prompts, for Batched Chat Completion's User Prompts input.
Install
Ships in the pack. ComfyUI Manager → search OpenAI API or Comfpod, or:
cd ComfyUI/custom_nodes
git clone https://github.com/lany42/comfyui-openai-api
cd comfyui-openai-api
/path/to/ComfyUI/.venv/bin/python -m pip install -r requirements.txt
# restart ComfyUI
Needs the openai SDK v2 (>=2.7.1,<3), numpy, Pillow and Python 3.13+.
Where people get burned
Count and image groups drift apart. If you leave the Count widget at 6 and later swap in a 10-image batch, you get a length mismatch error - which is the good outcome. The bad outcome is a 6-image batch with a manually-set count of 6, running quietly while you believe it processed 10. Connect the count output and stop thinking about it.
Cost multiplied by count. A batch of 20 with a shared 900-token prompt and a vision model is 20 full image-plus-text requests. It's the same bill the individual nodes would run up, but it arrives all at once.
Count of 1 hides wiring mistakes. With a single copy, a batch node that never received image groups looks like it worked: one request, one response, and no indication that the images weren't attached. Test with two images before you trust the graph.
Identical prompts plus a seed equals identical responses. If you repeat one prompt and pin a seed in the options chain, expect the copies to come back looking the same. For captioning that's fine; for variation, drop the seed and lift the temperature a little.
Inputs (2)
| Name | Type | Default | Description |
|---|---|---|---|
| text | STRING | The complete prompt to repeat for each request | |
| count | INT | 1 | Number of copies; optionally connect the Image Batch to List count output |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| Strings | STRING | Repeated prompts as a STRING execution list for Batched Chat Completion |