# BiRefNet Background Removal > Remove the background from an image and get a transparent-PNG cutout, with 11 selectable checkpoints and a soft alpha matte that keeps individual hair strands separated. ## Overview - **Endpoint**: `https://queue.modelrunner.run/zhengpeng7/birefnet` - **Model ID**: `zhengpeng7/birefnet` - **Category**: image-to-image - **Kind**: inference - **Tags**: birefnet, background-removal, remove-background, cutout, transparent-png, alpha-matte, image-matting, hair-matting, segmentation, anime, product-photo, image-to-image ## Pricing - **Estimated Price**: $0.004 average per output ## Request Lifecycle This model runs on the ModelRunner **asynchronous queue API** — a single POST does not return the output. Every call requires an `Authorization: Key $MODEL_RUNNER_KEY` header. Run three steps: 1. **Submit** — `POST https://queue.modelrunner.run/zhengpeng7/birefnet` with a JSON body holding the input fields at the top level. The body may also include a reserved top-level `metadata` object — a flat string map (max 16 keys, key ≤64 / value ≤512 chars) stored on the request for your own tagging. It is never sent to the model; filter your request history with `GET https://queue.modelrunner.run/requests?metadata=` (exact key=value matches, AND-ed). The response carries request handles only (no output yet): ```json { "status": "IN_QUEUE", "request_id": "<21-char id>", "status_url": "https://queue.modelrunner.run/zhengpeng7/birefnet/requests//status", "response_url": "https://queue.modelrunner.run/zhengpeng7/birefnet/requests/", "cancel_url": "https://queue.modelrunner.run/zhengpeng7/birefnet/requests//cancel" } ``` 2. **Poll status** — `GET ` until `status` is `COMPLETED`. Possible values are `IN_QUEUE`, `IN_PROGRESS`, `COMPLETED`, `FAILED`, `CANCELLED`. A `FAILED` request responds with HTTP 400 and an `error` field. 3. **Read result** — `GET `. Returns the finished request, including the generated `output`: ```json { "id": "", "status": "COMPLETED", "output": ..., "input": ... } ``` The JavaScript and Python SDKs below perform steps 2–3 for you. In any language without an SDK (Swift, Go, Kotlin, etc.) you must implement the polling loop and the final result fetch yourself — see the cURL example for the full flow. ### Input Schema - **`image`** (`string`, _required_): Source image to cut out. Still images (PNG, JPEG, WebP) are the normal case. An animated GIF or WebP is also accepted and comes back as an animated WebP with transparency, processed frame by frame — cost and turnaround scale with the frame count. Video files are not supported. - **`variant`** (`VariantEnum`, _optional_): Which BiRefNet checkpoint to run. 'general' is the all-purpose default. Pick a specialist when your subject fits one: 'portrait' for people, 'matting' or 'dynamic-matting' for hair and fur, 'toonout' for anime and flat-colour illustration, 'lite' / 'lite-2k' / 'lite-matting' for a smaller, faster backbone. The '-hr' and '-2k' checkpoints infer at a higher internal resolution for a more accurate matte — the returned image is still the size of your input, never larger. - Default: `"general"` - Options: `"general"`, `"general-hr"`, `"portrait"`, `"matting"`, `"matting-hr"`, `"dynamic"`, `"dynamic-matting"`, `"lite"`, `"lite-2k"`, `"lite-matting"`, `"toonout"` - **`mask_blur`** (`integer`, _optional_): Gaussian blur radius in pixels applied to the matte, softening the cut edge. - Default: `0` - Range: `0` to `64` - **`precision`** (`PrecisionEnum`, _optional_): GPU inference precision. 'fp32' is full precision and the default; 'fp16' is somewhat faster and uses less memory, with negligible quality difference. - Default: `"fp32"` - Options: `"fp16"`, `"fp32"` - **`refine_fg`** (`boolean`, _optional_): Refine foreground colours (FB blur fusion) so soft edges do not carry colour bleed from the original background. Worth enabling when compositing onto a light or strongly coloured backdrop. Ignored when output_format is 'mask'. - Default: `false` - **`resolution`** (`integer`, _optional_): Square inference resolution. 0 uses the chosen checkpoint's native resolution (1024, or 2048 for the HR and 2K checkpoints). This sets how finely the matte is computed, not the size of the returned image — the output always matches the input's dimensions. Higher values cost more compute time. - Default: `0` - Range: `0` to `2048` - **`mask_offset`** (`integer`, _optional_): Grow (positive) or shrink (negative) the matte by this many pixels. A small positive value removes a thin background fringe; a small negative value bites into the subject. - Default: `0` - Range: `-64` to `64` - **`output_format`** (`OutputFormatEnum`, _optional_): 'cutout' returns an RGBA image with the background removed. 'mask' returns the raw single-channel alpha matte instead, for pipelines that key the subject themselves. - Default: `"cutout"` - Options: `"cutout"`, `"mask"` ### Output Schema _No `Output` schema properties are available._ ## Default Example **Input** ```json { "image": "https://media.modelrunner.ai/rJ3Rl8kf4LLzo6SBVlH6n.png", "variant": "portrait", "mask_blur": 0, "precision": "fp32", "refine_fg": true, "resolution": 0, "mask_offset": 0, "output_format": "cutout" } ``` **Output** ```json "https://media.modelrunner.ai/5TAWAVSC0EV0bX2CKoXDD.png" ``` ## Usage Examples ### cURL The queue API is asynchronous: submit the request, poll `status_url` until it is `COMPLETED`, then read the result from `response_url`. Requires `jq`. ```bash # 1. Submit the request (returns request handles, not the output) SUBMIT=$(curl --silent --request POST \ --url https://queue.modelrunner.run/zhengpeng7/birefnet \ --header "Authorization: Key $MODEL_RUNNER_KEY" \ --header "Content-Type: application/json" \ --data '{ "image": "https://media.modelrunner.ai/rJ3Rl8kf4LLzo6SBVlH6n.png", "variant": "portrait", "mask_blur": 0, "precision": "fp32", "refine_fg": true, "resolution": 0, "mask_offset": 0, "output_format": "cutout" }') STATUS_URL=$(echo "$SUBMIT" | jq -r '.status_url') RESPONSE_URL=$(echo "$SUBMIT" | jq -r '.response_url') # 2. Poll until the request leaves the queue / in-progress state while true; do STATUS=$(curl --silent --url "$STATUS_URL" \ --header "Authorization: Key $MODEL_RUNNER_KEY" | jq -r '.status') echo "Status: $STATUS" case "$STATUS" in COMPLETED) break ;; FAILED|CANCELLED) echo "Request $STATUS"; exit 1 ;; esac sleep 1 done # 3. Read the finished request, including the generated output curl --silent --url "$RESPONSE_URL" \ --header "Authorization: Key $MODEL_RUNNER_KEY" ``` ### JavaScript ```javascript import { modelrunner } from "@modelrunner/client"; const result = await modelrunner.subscribe("zhengpeng7/birefnet", { input: { "image": "https://media.modelrunner.ai/rJ3Rl8kf4LLzo6SBVlH6n.png", "variant": "portrait", "mask_blur": 0, "precision": "fp32", "refine_fg": true, "resolution": 0, "mask_offset": 0, "output_format": "cutout" } }); console.log(result.data); ``` ### Python ```python import asyncio import modelrunner_ai async def main(): response = await modelrunner_ai.submit_async( "zhengpeng7/birefnet", arguments={ "image": "https://media.modelrunner.ai/rJ3Rl8kf4LLzo6SBVlH6n.png", "variant": "portrait", "mask_blur": 0, "precision": "fp32", "refine_fg": true, "resolution": 0, "mask_offset": 0, "output_format": "cutout" } ) result = await response.get() print(result["output"]) asyncio.run(main()) ``` ## Additional Resources - [Playground](https://modelrunner.ai/models/zhengpeng7/birefnet) - [OpenAPI Schema](https://modelrunner.ai/models/zhengpeng7/birefnet/openapi.json) - [LLM Instructions](https://modelrunner.ai/models/zhengpeng7/birefnet/llms.txt) - [GitHub](https://github.com/ZhengPeng7/BiRefNet) - [License](https://github.com/ZhengPeng7/BiRefNet/blob/main/LICENSE) - [Weights](https://huggingface.co/ZhengPeng7/BiRefNet) - [Paper](https://arxiv.org/abs/2401.03407)