---
title: "Deploy Background Removal API | (Just Updated) rembg, Weights Baked In, 2GB RAM Floor"
description: "rembg cutouts, weights baked in, commercial-safe models only, 2GB RAM floor"
category: "AI/ML"
url: https://railway.com/deploy/background-removal-api-or-just-updated-r
---

# Deploy Background Removal API | (Just Updated) rembg, Weights Baked In, 2GB RAM Floor

rembg cutouts, weights baked in, commercial-safe models only, 2GB RAM floor

**[Deploy Background Removal API | (Just Updated) rembg, Weights Baked In, 2GB RAM Floor on Railway](https://railway.com/template/background-removal-api-or-just-updated-r)**

Machine-readable deploy manifest (JSON, validated by TemplateCI): https://railway.com/deploy/background-removal-api-or-just-updated-r/manifest.json

- **Creator:** SuperSlowSloth
- **Category:** AI/ML

## Template content

### rembg

- **Image:** ghcr.io/bon5co/rembg-railway:2.0.84
- **Health check:** /health
- **Public domain:** Yes

## Documentation

# Deploy and Host rembg Background Removal API on Railway

rembg is the open-source background remover: send it a photo, get back a transparent PNG with the subject cut out. This template serves rembg's own HTTP API with the ONNX weights already inside the image, a bearer token on every route, and a model set restricted to weights that are licensed for commercial use.

## About Hosting rembg Background Removal API

This template runs rembg 2.0.84's FastAPI server on CPU — no GPU bill. The default U²-Net weights are baked into the image, so the very first request is answered in under a second instead of downloading hundreds of megabytes inside a request the platform edge abandons after five minutes. ONNX Runtime's thread pools are sized from the container's own CPU quota rather than the host's core count, which a container otherwise sees and oversubscribes. Every route except the health check requires `Authorization: Bearer $API_KEY`, and the key is generated for you at deploy; the container refuses to start without one. A volume at `/data` keeps the model cache across redeploys. Measured floor is **2 GB of RAM**: on Railway's 8 vCPU box the service sits at 0.70 GB idle and 1.63 GB with the default model serving, and a 1 GB container is OOM-killed on its first image. Keep several models loaded at once and it reaches 2.4 GB, so give it 4 GB if you plan to switch models per request. Free and Trial plans cannot run it.

## Why Deploy rembg Background Removal API on Railway?

Railway is a singular platform to deploy your infrastructure stack. Railway will host your infrastructure so you don't have to deal with configuration, while allowing you to vertically and horizontally scale it.

By deploying rembg Background Removal API on Railway, you are one step closer to supporting a complete full-stack application with minimal burden. Host your servers, databases, AI agents, and more on Railway.

- **Answers the first request** — the default model ships inside the image, so there is no multi-hundred-megabyte download hiding in your first API call.
- **Licensed for commercial use** — every model this deployment will serve is Apache-2.0 or MIT. Weights with non-commercial terms are refused with an explanatory 400 rather than quietly used.
- **Private by default** — a bearer token guards every processing route, and the container will not boot with an empty key.
- **Per-image pricing you control** — flat CPU pricing instead of per-image SaaS fees, on your own domain, with your images never leaving your infrastructure.

## Common Use Cases

- **E-commerce product shots** — cut every catalogue photo onto a transparent or brand-coloured background in a batch job.
- **Profile pictures and avatars** — let users upload a photo and get a clean cutout back, without sending it to a third-party API.
- **Creative and CV pipelines** — pre-process images for compositing, dataset preparation, or an agent workflow that needs a mask rather than a photo.

## Dependencies for rembg Background Removal API Hosting

- A volume mounted at `/data` (included in this template) for the model cache.
- A service with at least **2 GB RAM** — measured: 0.70 GB idle, 1.63 GB serving the default model, 2.4 GB with two models loaded, OOM-killed at 1 GB. Free and Trial plans cannot run it; allow 4 GB if you use several models or the 927 MB BiRefNet weights.

### Deployment Dependencies

- [danielgatis/rembg](https://github.com/danielgatis/rembg) — the upstream project and HTTP API (MIT)
- [bon5co/rembg-railway](https://github.com/bon5co/rembg-railway) — the Railway-tuned image this template deploys (MIT)
- [xuebinqin/U-2-Net](https://github.com/xuebinqin/U-2-Net) — the `u2net`, `u2netp` and `u2net_human_seg` weights baked in or offered here, **Apache-2.0**; `silueta` is a size-reduced U²-Net redistributed by rembg under MIT
- [ZhengPeng7/BiRefNet](https://github.com/ZhengPeng7/BiRefNet) — the optional `birefnet-general`, `birefnet-general-lite` and `birefnet-portrait` weights, **MIT**
- Not shipped, deliberately: `bria-rmbg` (BRIA RMBG-2.0 weights are non-commercial only) and `isnet-general-use` / `isnet-anime` (trained on DIS5K, whose terms of use prohibit commercial use)

### Implementation Details

Remove a background:

```bash
curl -X POST https://your-deployment.example.com/api/remove \
  -H "Authorization: Bearer $API_KEY" \
  -F file=@photo.jpg -o cutout.png
```

Pick a different model per request, or from a public URL:

```bash
curl -X POST https://your-deployment.example.com/api/remove \
  -H "Authorization: Bearer $API_KEY" \
  -F file=@photo.jpg -F model=silueta -o cutout.png

curl -G https://your-deployment.example.com/api/remove \
  -H "Authorization: Bearer $API_KEY" \
  --data-urlencode "url=https://example.com/photo.jpg" -o cutout.png
```

`u2net` (default), `u2netp` and `silueta` are inside the image. The BiRefNet models are 213 MB–927 MB and download on demand, so fetch one off the request path before you use it:

```bash
curl -X POST "https://your-deployment.example.com/preload?model=birefnet-general-lite" \
  -H "Authorization: Bearer $API_KEY"
```

Set `REMBG_MODEL` to change the default for requests that name no model. `GET /health` is open and reports which model is loaded; interactive OpenAPI docs are at `/api`. Upstream's alpha-matting, mask-only and background-colour options are all unchanged — this template wraps rembg's routes rather than replacing them.


## Similar templates

- [Chat Chat](https://railway.com/deploy/-WWW5r) — Chat Chat, your own unified chat and search to AI platform.
- [stella](https://railway.com/deploy/stella) — Self-host stella with web, API, Postgres, Redis, and object storage.
- [Hermes Agent | OpenClaw Alternative with Dashboard](https://railway.com/deploy/hermes-agent-or-openclaw-alternative-wit) — Self-Hosted Hermes AI Agent for Telegram, Discord & Slack

Open this page in a browser: https://railway.com/deploy/background-removal-api-or-just-updated-r
