Extensions/Foldbun Stack
ComfyUI Extension

Foldbun Stack

SAM 3 text segmentation, BiRefNet background removal and OCR for ComfyUI through the Foldbun Stack API: no local models, no VRAM.

By Foldbun·Created about 12 hours ago·Updated about 12 hours ago· 0
Foldbun/comfyui-foldbun-stack
Nodes—
On cloudLocal install
Stars0
Updatedabout 12 hours ago
Readme

Foldbun Stack for ComfyUI

Segmentation, background removal and OCR in ComfyUI without installing a single model.

This node pack sends your image to the Foldbun Stack vision API and gives back standard ComfyUI MASK, IMAGE and STRING values. Nothing is downloaded, nothing runs on your GPU, so it works on any machine that can run ComfyUI, including CPU-only ones.

| Node | What it does | Model | |---|---|---| | Stack: Segment by text | Finds every object that matches a text prompt | SAM 3 | | Stack: Segment by point / box | Segments one object from clicks and/or a box | SAM Lite or SAM 3 | | Stack: Remove background | Cuts out the main subject with a fine alpha matte | BiRefNet | | Stack: OCR | Reads text from photos, screenshots and crops | PP-OCR |

All nodes are in the category Foldbun Stack (right-click the canvas, or double-click and search for foldbun).

Install

ComfyUI Manager / Registry. Search for "Foldbun Stack" (registry id comfyui-foldbun-stack) and install.

From git.

cd ComfyUI/custom_nodes
git clone https://github.com/Foldbun/comfyui-foldbun-stack

Restart ComfyUI. The pack needs no extra Python packages: it uses torch, numpy and Pillow, which ComfyUI already installs, and the standard library for HTTP.

It uses ComfyUI's current node API (see Why the V3 node API), so keep ComfyUI reasonably up to date.

Set up access

The free tier works out of the box. With nothing set, the pack uses its own public project ID, so you can try every node right after installing. The free tier has usage limits, shared fairly between everyone who uses the pack.

For paid use (higher limits, no free-tier queue), or to use your own free-tier project, set one of these in the environment of the process that runs ComfyUI before you start it:

| Variable | Use | |---|---| | FOLDBUN_STACK_API_KEY | Your API key (starts with fbs_). Paid use. Create one at https://stack.foldbun.com/console/keys. | | FOLDBUN_STACK_PROJECT | Your own free-tier project ID (starts with fbp_), used instead of the pack's. |

export FOLDBUN_STACK_API_KEY=fbs_...        # paid use
# or
export FOLDBUN_STACK_PROJECT=fbp_...        # free tier

(FOLDBUN_API_KEY is accepted as another name for the key.) With a key, the key pays, and the project ID (yours, or the pack's) is sent along as the source project, which is used for statistics only.

Keys are never widgets, on purpose. ComfyUI saves every widget value into your workflow files and into the metadata of every image it saves, and people share both. The nodes therefore have no key field, and the pack never writes your key into a workflow, an output, a log line or an error message (anything that looks like a key is redacted from error text).

If you cannot set environment variables (for example on some hosted ComfyUI services), you can instead put the values into a JSON file, foldbun_stack.json in the ComfyUI user directory (or any path in FOLDBUN_STACK_CONFIG):

{ "api_key": "fbs_...", "project_id": "fbp_..." }

Environment variables win over the file. If the file holds a key and is readable by other users, a warning is logged; run chmod 600 on it.

Nodes

Images are ComfyUI IMAGE batches. A batch is processed one image per request, in order, with a progress bar when it has more than one image.

Stack: Segment by text (SAM 3)

Describe what you want in words; every matching object is found.

| Input | Type | Notes | |---|---|---| | image | IMAGE | | | prompt | STRING | One prompt per line, at most 50 lines of 200 characters. Example: dog | | threshold | FLOAT | Lowest confidence kept, 0 to 1 (default 0.5) | | max_instances | INT | Most objects returned, highest scores first (default 100) |

| Output | Type | Notes | |---|---|---| | mask | MASK | All found objects merged, one mask per input image | | instance_masks | MASK | One mask per found object, all images of the batch in order; a single empty mask when nothing was found | | instances_json | STRING | JSON list of {image, label, score, bbox}; bbox is [x1, y1, x2, y2] in pixels of your original image | | count | INT | Number of objects found |

Stack: Segment by point / box

Segments one object from clicks and/or a box.

| Input | Type | Notes | |---|---|---| | image | IMAGE | | | positive_points | STRING | Points on the object, one per line, as x,y in pixels | | negative_points | STRING | Points on things to leave out, same format | | box | STRING | Optional x1,y1,x2,y2 in pixels | | model | COMBO | sam-lite (faster, cheaper) or sam3 |

You need at least one positive point or a box. Coordinates are pixels of the input image, and the same prompts apply to every image of a batch. Outputs: mask (MASK) and instances_json (STRING, {image, score, bbox}).

Stack: Remove background (BiRefNet)

| Input | Type | |---|---| | image | IMAGE |

| Output | Type | Notes | |---|---|---| | image | IMAGE | RGBA: your original pixels with the subject matte as alpha | | mask | MASK | Subject = 1, background = 0 |

The cutout is built here from your original pixels, so colours stay exactly as they were and the result keeps the resolution of the input, even if the image had to be shrunk for upload. Connect image to Save Image to get a PNG with a transparent background.

Stack: OCR (PP-OCR)

| Input | Type | Notes | |---|---|---| | image | IMAGE | | | min_confidence | FLOAT | Lines below this confidence are dropped (default 0.5) | | word_boxes | BOOLEAN | Also return word-level boxes in the JSON |

| Output | Type | Notes | |---|---|---| | text | STRING | Recognised lines, one per line, roughly top to bottom (this is not a reading-order guarantee); several images are separated by an empty line | | lines_json | STRING | One entry per image: {image, width, height, lines}; each line has text, confidence, bbox and, when the API gives it, quad, all in pixels of your original image |

Example workflows

In examples/. Drag a file onto the ComfyUI canvas, or use Workflow > Open.

  • segment-by-text.json: Load Image, Segment by text, Convert Mask to Image, Preview Image.
  • remove-background.json: Load Image, Remove background, Save Image.

Both load example.png, the sample image that ships with ComfyUI; pick your own image in Load Image.

Limits

  • Image size. Images are shrunk only when needed and never enlarged. Segmentation and background removal send at most 2048 px on the longest side and 4 megapixels; OCR sends up to 8192 px and 9 megapixels so that small text stays readable. The encoded image must also stay under 4 MB on the free tier (the API's free-tier limit) or 12 MB with an API key (the API accepts up to 20 MiB; the lower cap keeps uploads quick); if it does not, it is scaled down in 20 % steps until it does. Everything that comes back (masks, boxes, quads) is mapped back to the original resolution of the image you gave the node.
  • Alpha and colour. Input images are sent as RGB; an alpha channel is dropped, grayscale is expanded.
  • Free tier. The free tier takes images inline only and has usage limits. When a limit is reached the node shows the server's message as it is, and waits and retries only for short waits (up to 3 retries, never longer than 45 s); longer waits are reported as an error.
  • Cancel. Pressing Cancel in ComfyUI stops the node, including while it waits to retry.

Why the V3 node API

The nodes use ComfyUI's V3 schema (comfy_api.latest: io.ComfyNode, io.Schema, comfy_entrypoint) rather than the older class-attribute style. Inputs, outputs and tooltips are declared in one typed place, the pack loads through a single entry point, and it follows the node API that ComfyUI itself is moving to. The price is that very old ComfyUI versions that predate comfy_api are not supported.

Privacy

Every node uploads the images you give it to Foldbun Stack servers for processing; nothing is processed locally. Do not use these nodes on images you are not allowed to send to a third-party service. See the Foldbun privacy policy for how data is handled.

Links

Development

cd comfyui
python -m pytest -q tests
COMFYUI_PATH=/path/to/ComfyUI python -m pytest -q tests   # also loads the pack with a ComfyUI checkout

The unit tests use a fake transport and make no network calls.

License

MIT