Nodes/Stability API nodes for ComfyUI/Stability Replace Background and Relight
ComfyUI Node

Stability Replace Background and Relight

New background, new light, one async call

By Stability-AI·Created 2 years ago·Updated about a year ago· 64
Stability Replace Background and Relight
  • subject_image
  • background_reference
  • light_reference
  • IMAGE
background_prompt
foreground_prompt
negative_prompt
preserve_original_subject0.60
original_background_depth0.50
keep_original_backgroundfalse
light_source_direction
light_source_strength0.30
seed0
output_format
api_key_override

This is the most ambitious node in the pack, and the name says exactly what it does: cut your subject out, put a new background behind it, and re-light the whole thing to match. Product shots, portraits, "put this vase in a museum at golden hour" - that's the territory. It calls stable-image/edit/replace-background-and-relight on Stability's servers, and it's the most configurable edit node they ship, which also makes it the one with the most ways to go wrong.

It's a cloud node from the official "Stability API nodes for ComfyUI" pack: credits per call, API key required, zero VRAM. Locally, this job is a pipeline - cutout, composite, and an IC-Light pass for the relighting - and IC-Light is a good mental model for what the server is doing here, including its weaknesses. The community has been meh on this whole pack ("not local, not interested"), and this is the node where that sentiment is most justified if you have the local stack. It's also where the cloud earns its keep, because the local equivalent is genuinely multi-step and fiddly.

How it works

The one required input is subject_image - the thing to keep. The background comes from one of two places: a background_reference image, or a background_prompt describing the new scene. Then you steer the edit:

  • preserve_original_subject (0.0–1.0, default 0.6) - how faithfully the subject survives the compositing. If your subject morphs or gets restyled, raise this.
  • keep_original_background (boolean) - composite the subject onto its own original background, purely for the relighting pass. Useful when you only want the light fixed.
  • original_background_depth (0.0–1.0, default 0.5) - how much the original background's depth is preserved when generating the replacement. Mostly a realism dial.
  • foreground_prompt - optionally describe the subject so the model handles it better.
  • The lighting block: light_source_direction (none/above/below/left/right), light_source_strength (0.0–1.0, default 0.3), and light_reference - an image whose lighting you want to borrow. For product shots, a light_reference of the studio setup you're mimicking is the secret weapon.
  • negative_prompt, seed, output_format - the standard furniture.

Like Creative Upscale, this route is async: it submits, then polls Stability's results endpoint for up to about four minutes. Big jobs make it feel slow. Plan for the wait.

Output is a single IMAGE tensor.

Installing it

From the "Stability API nodes for ComfyUI" pack - ComfyUI Manager, or:

cd ComfyUI/custom_nodes
git clone https://github.com/Stability-AI/ComfyUI-SAI_API
# restart ComfyUI

No model downloads; requests is the only dependency beyond ComfyUI's own stack. Key via SAI_API_KEY, a sai_platform_key.txt file, or the per-node api_key_override (which embeds the key in the workflow - don't share those files).

Common issues

  • Subject gets relit into something unrecognizable - raise preserve_original_subject; the relighting can get aggressive the way IC-Light does, especially on skin. Keep the light strength modest and check what light_source_direction is doing.
  • The wait feels like a hang - it's polling, up to ~240 seconds. That's the async design.
  • Background has nothing to do with your reference - if you supplied both a background_reference and a background_prompt, they can fight. Pick one source of truth.
  • "payment_required" - credits ran out; this is a heavier job than the single-image edits, so the bucket drains faster.

When it works, it's a genuinely impressive one-node product-shot machine. When it doesn't, it's usually the subject preservation or the lighting fighting you - and those are both dials you control.

CategoryStability

Inputs (14)

NameTypeDefaultDescription
subject_imageIMAGE
background_referenceoptIMAGE
background_promptoptSTRING
foreground_promptoptSTRING
negative_promptoptSTRING
preserve_original_subjectoptFLOAT0.600–1
original_background_depthoptFLOAT0.500–1
keep_original_backgroundoptBOOLEANfalse
light_source_directionoptCOMBO5 options: none, above, below, left, right
light_referenceoptIMAGE
light_source_strengthoptFLOAT0.300–1
seedoptINT00–4294967294
output_formatoptCOMBO3 options: png, webp, jpeg
api_key_overrideoptSTRING

Outputs (1)

NameTypeDescription
IMAGEIMAGE