SAM3 - Remove Background via Prompt

This ComfyUI workflow isolates a subject from any image using a simple text prompt and exports a PNG with a transparent background. It links a LoadImage node to a SAM3Segment node, then into SaveImage. You type what you want to keep (for example, "character", "dog", or "red car"), and the SAM3Segment node generates a precise foreground mask and applies it as an alpha channel so everything else becomes transparent.

Technically, SAM3Segment performs prompt-aware segmentation over the input image, producing a binary mask for regions that best match the prompt. That mask is composited with the original RGB to produce an RGBA cutout. Because the node is designed to work well out of the box, most settings can remain at their defaults. The included MarkdownNote provides a quick reminder of the two essentials: connect an image and provide a clear prompt. SaveImage then writes the final cutout as a PNG, preserving transparency for downstream compositing in design, video, or web workflows.

API

Use this workflow from code

Every Comfy workflow is a JSON graph. The payload below is this workflow, exactly as ComfyUI runs it — fetch it from the URL, keep it in version control, or load it in ComfyUI and run it node by node.

9be3d7110c75.json
Fetching workflow JSON…

Run it from TypeScript or Python with the Comfy SDK. The same code targets Comfy Cloud or a ComfyUI you host yourself — only the base URL changes.

// Install (beta)
npm i @comfyorg/sdk

// Run this workflow (TypeScript)
import { Comfy } from "@comfyorg/sdk";

const client = new Comfy({ apiKey: "comfyui-..." });
const wf = await client.workflows.fromFile("workflow_api.json");
const job = await client.run(wf);
await job.getOutputs("<output-node-id>")[0].toFile("output.png");

The SDK takes a workflow in API format: open this workflow in ComfyUI and use File → Export Workflow (API).

Comfy Cloud API access requires a plan with an API key.

FAQ

Frequently Asked Questions

View all workflows
Showing 30 of 30 templates