How to Remove Backgrounds With the BiRefNet API

Background removal used to be the slowest part of any image pipeline. You generate a batch of renders, then somebody sits masking hair and fabric edges one file at a time. BiRefNet changed the economics of that step, and because it is exposed through a plain HTTP API you can bolt it onto whatever you already use to generate images.

This guide covers what BiRefNet actually is, how to call it, which model variant to pick, and how to wire it into a generation workflow so cutouts happen automatically instead of by hand. If you want the no-code version first, our walkthrough on removing backgrounds from images with AI covers the browser-based route.

What BiRefNet is

BiRefNet stands for Bilateral Reference Network. It is a high resolution dichotomous image segmentation model, which is a long way of saying it decides, pixel by pixel, what is subject and what is background. It was built for the hard cases: strands of hair, chain link, glassware, fur, transparent fabric. Those are exactly the edges where older matting models smear or clip, as anyone who has compared AI photo enhancement tools at full zoom will recognise.

The practical difference shows up in alpha quality. Compared with the classic U2Net-style removers behind a lot of free web tools, BiRefNet holds fine detail at full resolution rather than downsampling the mask and scaling it back up. If you have ever produced a cutout that looked fine as a thumbnail and fell apart at 100 percent, that is the problem it solves. The same detail question comes up when you make image backgrounds transparent with AI for logos and packshots.

Where the API lives

BiRefNet is open weights, so you have two routes. Self host it on a GPU with the published PyTorch code, or call a hosted endpoint and skip the infrastructure entirely. Hosted is the sane default unless your volume justifies a dedicated box, and the same reasoning applies to most AI content generation APIs.

The most common hosted route is fal, which exposes fal-ai/birefnet and a second generation fal-ai/birefnet/v2 endpoint. Both take an image URL and return a cutout. Replicate hosts community builds too, and ComfyUI has a BiRefNet node if you prefer a local graph. Developers who have worked through a hosted image endpoint before will find the request shape familiar, much like the pattern in our Nano Banana 2 API guide.

Product packshot of a glass perfume bottle isolated on pure white, dramatic side lighting, magazine quality

Making your first call

The fal client is the shortest path. Install it, export your key, and submit an image URL. The setup is the same three steps you would follow for any of the endpoints covered in our FLUX Pro API pricing and code examples.

npm install @fal-ai/client
export FAL_KEY="your-key-here"
import { fal } from "@fal-ai/client";

const result = await fal.subscribe("fal-ai/birefnet/v2", {
  input: {
    image_url: "https://example.com/product.jpg",
    model: "General Use (Light)",
    refine_foreground: true,
    output_format: "png"
  }
});

console.log(result.data.image.url);

The response gives you a PNG with a real alpha channel, not a white background pretending to be transparent. Accepted inputs are jpg, jpeg, png, webp, gif and avif. If you would rather not manage keys and clients at all, Wireflow’s creative tools expose the same model as a node you drop onto a canvas.

Picking the right model variant

The endpoint ships several sets of weights, and the choice matters more than most of the other parameters. The trade-off is always speed against edge fidelity, the same tension you see across AI image editors.

Variant Best for Trade-off
General Use (Light) Most images, batch jobs Fastest, slightly softer on fine hair
General Use (Heavy) Hero shots, print output Noticeably slower per image
Portrait People, headshots, UGC Weaker on non-human subjects
Matting Semi-transparent edges, glass, smoke Softer alpha, needs review

Start with Light. Move to Heavy only for images that get scrutinized at full size, because the latency difference compounds fast across a batch. For a view of what else sits at each quality tier, see the roundup of free background remover tools.

Wide editorial shot of a leather jacket floating against a deep gradient backdrop, sharp cutout edges, volumetric light

The parameters that actually change output

Most of the input fields are cosmetic. Three are not, and they are the ones worth setting deliberately before you run a batch through the API.

  • refine_foreground applies a mask-guided pass that cleans colour fringing at the edge. Leave it on for anything with hair or fabric. It costs a little time and it is almost always the right call.
  • output_mask returns the raw segmentation mask alongside the cutout. Useful when you want to composite yourself, feather the edge, or reuse the mask for a shadow layer.
  • resolution controls the working size of the segmentation. Pushing it up helps on very large source files and does nothing useful on small ones.

One habit worth adopting: keep the mask, not just the cutout. Masks are cheap to store and let you re-composite later without a second API call. That matters when you are producing product photos for ecommerce and the background spec changes halfway through the shoot.

Wiring it into a generation pipeline

Removal is rarely the last step. Once you are building pipelines with REST APIs, the chain usually looks like this:

  1. Generate or upload the source image.
  2. Run BiRefNet to get a cutout plus mask.
  3. Composite onto a new background, a solid colour, or a generated scene.
  4. Upscale if the final asset is going to print or a large hero slot.
  5. Push the result to your CDN or storage bucket.

Each of those is its own call, which means the interesting engineering problem is orchestration rather than any single model. You can hand-roll it with a queue and retry logic, or use a canvas that already handles the wiring; visual builders are worth a look if you would rather not maintain that glue yourself.

The upscaling step at the end deserves its own attention, and our guide to upscaling images via API covers the resolution ceilings. Do the upscale after the cutout, not before, or you pay for pixels you are about to discard.

Studio portrait of a model with flyaway hair against a matte backdrop, rim lit, lookbook quality

Common failure modes

Thin structures are still the hard case. Bicycle spokes, mesh, wire fencing and flyaway hair will occasionally get partially eaten, and the fix is usually the Heavy model plus a higher resolution setting rather than a different tool. Reviewing those files in a visual canvas editor is faster than opening them one at a time.

Low contrast between subject and background is the other one. A grey jacket on a grey wall gives the model very little to work with. If you control the source, shoot or generate against a background that differs in luminance, not only in hue. That is a good argument for generating your backgrounds deliberately instead of accepting whatever the original frame had.

FAQ

Is BiRefNet free to use? The weights are open and you can self host at no licence cost. Hosted endpoints charge per image, typically fractions of a cent, so the real question is whether you want to run GPUs. A price comparison of hosted image endpoints sits in our Recraft V4 API examples.

How fast is a single request? On a hosted endpoint with the Light model, expect roughly one to three seconds per image at normal web resolution. Heavy roughly doubles that, which is why batch jobs usually stay on Light.

Does it return true transparency? Yes. Request PNG or webp output and you get a real alpha channel. JPEG cannot carry alpha, so it flattens to a background colour, a constraint shared by most AI image generators.

Can it handle batches? The endpoint is one image per call. Batching is your job: fan out concurrent requests with a sensible cap, usually five to twenty in flight depending on your rate limit.

Does it work on AI generated images? It works well on them, often better than on photographs, because generated subjects tend to have cleaner separation. Anything from the FLUX model family cuts out reliably.

What about video? BiRefNet is a still image model. Frame-by-frame removal works but flickers without temporal smoothing, so use a dedicated video matting model if that is your use case.

Should I use v1 or v2? Use v2. It has better edge handling and the same interface, so there is no migration cost. Teams already orchestrating several APIs can swap the model string and be done.

Wrapping up

BiRefNet is the current default for high quality background removal, and the API makes it a two-line addition to any pipeline. Pick the Light variant, turn on foreground refinement, keep the mask, and reach for Heavy only on images that will be looked at closely.

The bigger win is not the removal itself but removing the manual step entirely, which is where a graph-based approach like the AI node editor pattern earns its keep.