# BiRefNet (birefnet)

`birefnet` (BiRefNet) separates the foreground subject from the background with hair-level detail. It returns either an RGBA cutout of the subject, or the 8-bit grayscale alpha matte on its own.

| | |
|---|---|
| Model ID | `birefnet` (default model of the endpoint) |
| Model | BiRefNet, general model (Peng Zheng et al.) |
| Weights | Official general model (`ZhengPeng7/BiRefNet`) |
| Use cases | [Background removal](https://stack.foldbun.com/docs/use-cases/background-removal/) |
| Endpoints | `POST /v1/remove-background` |
| Pool | Paid: billed from the balance |
| Billing units | `image`. Units and prices: [Billing](https://stack.foldbun.com/docs/billing/#price-list) |
| Licence | MIT |

## How it works

A call is one forward pass of a segmentation network over the whole image, followed by packing the result as an image.

**Prediction.** The image is resized to 1024 × 1024 pixels and normalised, and BiRefNet predicts for every pixel how much of it belongs to the foreground subject. The network keeps high-resolution detail, which is why thin structures such as hair keep soft, partly transparent edges. The prediction is scaled back to the size of the image and stored as 8-bit values: 255 is the subject, 0 is the background, and the values between are partly transparent pixels. This is the alpha matte.

**Output.** With `options.output` set to `matte`, the matte is returned as it is, as a grayscale image. With `cutout` (default), the colours of the input image and the matte as the alpha channel form an RGBA image, so the background is transparent. Both outputs come from the same pass; they differ only in how the result is packed. The image is then encoded as PNG or WebP, as `options.format` says.

Every call runs the full model on its own image. There is no reusable encoding, so there is no cache discount, and a call is billed as one `image` at the same price for the cutout and the matte.

## In each use case

### Background removal

- `birefnet` is the default model of `POST /v1/remove-background`. One image per call.
- `options.output` returns a `cutout` (default) or a `matte`, and `options.format` encodes it as `png` (default) or `webp`; see [Output formats](https://stack.foldbun.com/docs/use-cases/background-removal/#output-formats).
- The long side of the result is the smaller of the image's long side and `options.size` (an integer from 64 to 4096, default 2048). The aspect ratio is kept, and an image is never enlarged. The result is returned inline as base64 in `data`.

Use case guide and example call: [Background removal](https://stack.foldbun.com/docs/use-cases/background-removal/).

## Limits and notes

- One image per call. Every call runs the full model; there is no cache discount.
- Image limits: see [Images](https://stack.foldbun.com/docs/images/). When the image is larger than `options.size`, the result is scaled down on its long side to that value.
- Latency: the recorded call had `timing.processingMs` of 882 ms. The figure depends on the image, on queueing and on node load, and it is not a guarantee.
