OpenAI API - Multiline String to List
Turn a Text File of Prompts Into a Batch
- Strings
What it is
One text box in, an execution list of strings out - one entry per non-empty line, whitespace trimmed off both ends. Paste twenty prompts, get twenty entries. That's the node.
It's the "I have a list in a text file" end of the pack's batch machinery, and it pairs directly with Batched Chat Completion's prompts input. The companion node, Repeat String to List, handles the opposite case (one prompt, many copies); this one handles many distinct prompts, one each.
How it works
It splits on line breaks, strips each line, and drops anything that ends up empty. Blank lines in the middle of your text are simply discarded, and so is trailing whitespace - paste from a spreadsheet or a markdown file and you don't get a stray space smuggled onto the front of a caption.
Note the inputs the downstream node will accept: Batched Chat Completion's prompts is a force-input socket rather than a text widget, which is why a plain text box can't plug into it directly. A list-producing node has to sit in between. That's this one.
The one trap to know before you rely on it: each line becomes a prompt, so a prompt containing its own line breaks survives only as its first line, or gets split into two requests. Multiline String to List is for a stack of short prompts - one caption, one tag string, one instruction per line. If your text is one long multi-paragraph prompt that you want sent N times, you want Repeat String to List instead; that one preserves whitespace and line breaks exactly.
The output is a genuine ComfyUI execution list: a downstream input-list node receives the whole list and iterates over it itself, which is what makes ordering work end to end - request one uses line one, response one comes back at position one.
Inputs and outputs
- Text (
text) - multiline STRING, default empty. "Text to split into one string per nonempty line."
Output: Strings - a STRING execution list of trimmed, non-empty lines. Wire it into Batched Chat Completion's User Prompts input, or into CLIP Text Encode List's Prompts if you already have the text and just need one conditioning per line.
Install
It's part of 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
The pack needs the openai SDK v2 (>=2.7.1,<3), numpy and Pillow, and Python 3.13+. No weights.
The workflow it's for
Paste your list of rough ideas into the text box. Out comes N strings. Feed them into Batched Chat Completion with a vision model and an Image Batch to List group count if you have images to pair them with, and you get N captions in order. Then either Multiline String to List again (if each response contains several lines you want separated) or straight into CLIP Text Encode List if you're generating from the rewritten prompts.
It's also the cheapest way to test a prompt change across a whole set: edit one line, re-queue, and only the requests that changed cost you anything.
Where people get burned
A prompt got split in half. You pasted a prompt with a line break inside it and the node dutifully made two requests. Check the string count before queuing a batch - the node will happily send 31 requests when you wrote 20 prompts with 11 awkward wraps.
Trailing commas or bullets stay in. The node trims whitespace, not punctuation. A - or 1. at the start of a line is part of the prompt, and the model will read it as one. Clean your list first.
Empty input is quietly N=0. If you forget to paste anything, the downstream batch node has nothing to do and complains that at least one prompt or image batch must be supplied. That error is this node's fault nine times out of ten.
Line endings. Text pasted from Windows tools can carry carriage returns; the trim handles them, but if you ever build this list programmatically, write \n and not \r\n and save yourself a debugging session.
Inputs (1)
| Name | Type | Default | Description |
|---|---|---|---|
| text | STRING | Text to split into one string per nonempty line |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| Strings | STRING | Trimmed, nonempty lines as a STRING execution list |