# BiRefNet Background Removal

> Run BiRefNet Background Removal by infsh online or via API. Pay per run, no setup.

**URL:** https://inference.sh/apps/infsh/birefnet
**Last updated:** 2025-11-19

---

Removes backgrounds from images quickly and accurately.

- app: `infsh/birefnet`
- maker: [infsh](https://inference.sh/apps/infsh.md)
- category: [image](https://inference.sh/apps/category/image.md)
- tasks: [background removal](https://inference.sh/apps/tag/background-removal.md)
- price: GPU time, billed per millisecond
- runs via: api, javascript and python sdk, belt cli, mcp

## birefnet API Guide

### About
removes backgrounds from images quickly and accurately.

### 1. Calling the API

#### Install the Client

```bash
pip install inferencesh
```

#### Setup Your API Key
Set `INFERENCE_API_KEY` as an environment variable. Get your key from settings → api keys.

```bash
export INFERENCE_API_KEY="inf_your_key"
```

#### Run and Get Result

```python
import os
from inferencesh import inference

client = inference(api_key=os.environ["INFERENCE_API_KEY"])


result = client.run({
        "app": "infsh/birefnet@5sj9tz6b",
        "input": {
            "image": "https://example.com/file.png"
        }
    })

print(result["output"])
```

#### Stream Live Updates

```python
import os
from inferencesh import inference

client = inference(api_key=os.environ["INFERENCE_API_KEY"])


## stream=True yields updates as they arrive
for update in client.run({
        "app": "infsh/birefnet@5sj9tz6b",
        "input": {
            "image": "https://example.com/file.png"
        }
    }, stream=True):
    if update.get("progress"):
        print(f"progress: {update['progress']}%")
    if update.get("output"):
        print(f"output: {update['output']}")
```

### 2. Authentication
The API uses API keys for authentication. See the authentication docs for detailed setup instructions.

### 3. Files

#### Automatic Upload

```python
## local file paths are automatically uploaded
result = client.run({
    "app": "infsh/birefnet@5sj9tz6b",
    "input": {
        "image": "/path/to/local/image.png",  # detected & uploaded
        "audio": "https://example.com/audio.mp3",  # url passed through
    }
})
```

#### Manual Upload

```python
## upload and get a hosted URL
file = client.files.upload("/path/to/file.png")
print(file.uri)  # https://cloud.inference.sh/...
```

### 4. Schema

#### Input
- **background_color** (string): Background color to use when fill_background is True
- **fill_background** (boolean): Fill the background with a solid color instead of returning transparency
- **image** (string) *required*: image
- **return_mask** (boolean): Whether to use the matting model to return a mask (True) or the normal model for binary mask (False)

#### Output
- **result** (string): result

## other image apps

- [Gemini Nano Banana 2.1](https://inference.sh/apps/google/gemini-nano-banana-2-1.md): $1.50/M input, $0.0336–$0.1134/image (1K–4K), +$0.014/query Google Search
- [grok-imagine-image-2-0](https://inference.sh/apps/xai/grok-imagine-image-2-0.md): $0.04/img low 1k, $0.06/img low 2k, $0.06/img med 1k, $0.08/img med 2k; $0.01/source img (edits)
- [GPT Image 2.5 Sunburst](https://inference.sh/apps/openai/gpt-image-2-5-sunburst.md): $0.006-$0.21 per 1024x1024 image: low $0.006, medium $0.013, high $0.053, xhigh $0.094, max $0.21. Larger sizes cost more; edits add ~$0.008 per reference image.
- [GPT Image 2.5 Flare](https://inference.sh/apps/openai/gpt-image-2-5-flare.md): $0.006-$0.21/image at 1024x1024: low $0.0059, medium $0.0132, high $0.0527, xhigh $0.0937, max $0.2107. Larger sizes cost more; edits add ~$0.0083 per reference image.
- [Image Resize & Crop](https://inference.sh/apps/eval/resize.md): from $0.00000277/sec

## faq

### how much does BiRefNet Background Removal cost?

GPU time, billed per millisecond. you pay per run from your inference shell credits. no subscription is required.

### how do I run BiRefNet Background Removal via api?

call infsh/birefnet with the javascript or python sdk, the rest api, or `belt app run infsh/birefnet` from a terminal. the api reference on this page lists every input.

### who makes BiRefNet Background Removal?

BiRefNet Background Removal is made by infsh and runs on inference shell. every infsh app is listed at https://inference.sh/apps/infsh.

### can my agent use BiRefNet Background Removal?

yes. agents call it as a tool through the inference shell mcp server (https://api.inference.sh/mcp), the belt cli or the sdk, and pay per run like you do.

### what are the alternatives to BiRefNet Background Removal?

other image apps on inference shell include Gemini Nano Banana 2.1, grok-imagine-image-2-0, GPT Image 2.5 Sunburst, GPT Image 2.5 Flare. they run through the same api, so switching is a one-line change.
