Background Removal API reference.
Remove image backgrounds programmatically. Authenticate with an API key and POST an image — you get the cut-out back in the response.
Quick start
- Create an API key in your dashboard.
- Send your image to the endpoint below with the key as a Bearer token.
- Receive the background-removed image in the response.
Base URL
https://api.remover.bgAuthentication
Pass your API key as a Bearer token. Create and manage keys in your dashboard. Keep keys secret — anyone with a key can spend your credits.
Authorization: Bearer rmbg_YOUR_API_KEYRemove background
POST/remove-bg
Send the image as multipart/form-data under the file field. Accepts PNG, JPEG or WebP up to 25 MB and 50 megapixels. The response body is the processed image; the remaining balance is returned in the X-Credits-Remaining header. An optional bg_image_file field can carry a background image (see below).
Parameters
All parameters are sent in the query string, except bg_image_file, which is a multipart field.
| Parameter | Type | Default | Description |
|---|---|---|---|
| format | png | jpeg | jpg | webp | default png | Output image format. |
| quality | number 0–1 | default 1 | Compression quality (jpeg/webp only). |
| trim | boolean | default true | Trim transparent edges around the subject. Trimming does not affect credit usage. |
| trim_margin | string | default 0 | Space to leave around the subject when trimming, e.g. "30px" or "10%" (relative to subject size). One value (all sides), two (top/bottom, left/right) or four (top, right, bottom, left). Capped at 50% of the subject size or 500 px per side; never extends past the original image borders. Only applies when trim is enabled. |
| transparent_windows | boolean | default true | Car photos only: cleans up the old background visible through the windows and keeps a natural, slightly transparent glass look. Set to false to get fully opaque windows. Images without car windows are unaffected. |
| shadow | auto | force | none | default auto | AI shadow. A dedicated shadow model generates a soft shadow that matches the subject's shape and where it meets the ground — there is nothing to tune by hand. With auto (the default) the shadow is added when a vehicle is detected; other subjects come back without one. Use force to apply the shadow to any subject, whatever is detected. Use none for a cutout with no shadow at all. The shadow is baked into the transparency, so it works on transparent results and with bg_ options alike. |
| bg_color | string | default — | Adds a solid color background. Hex code (e.g. 81d4fa, fff) or color name (e.g. green). 4-/8-digit hex codes add semi-transparency (e.g. 81d4fa77). If present, the other bg_ options must be empty. |
| bg_image_url | string | default — | Adds a background image from a URL. The image is centered and resized to fill the canvas while preserving its aspect ratio, unless it already has the exact same dimensions as the foreground. If present, the other bg_ options must be empty. |
| bg_image_file | file | default — | Adds a background image from a file, sent as a second multipart/form-data field (not a query parameter). PNG, JPEG or WebP up to 25 MB; scaled like bg_image_url. If present, the other bg_ options must be empty. |
| response | image | url | default image | Binary image (default) or JSON with a temporary download URL (kept for 24 hours). |
| session | 1 | default — | Opens a one-hour photo session so you can choose which objects stay (see Select objects). PNG only, untrimmed (trim defaults to false), no bg_ options, binary response. The session id comes back in the X-Photo-Session header. |
Examples
curl -X POST "https://api.remover.bg/remove-bg?format=png" \
-H "Authorization: Bearer rmbg_YOUR_API_KEY" \
-F "file=@photo.jpg" \
--output result.pngTransparent car windows
On car photos, the old background showing through the windows is cleaned up automatically and the glass keeps a natural, slightly transparent look (transparent_windows=true, the default). Prefer solid windows? Pass transparent_windows=false and they come back fully opaque. This only applies to vehicle photos — images without car windows are unaffected either way.
curl -X POST "https://api.remover.bg/remove-bg?transparent_windows=false" \
-H "Authorization: Bearer rmbg_YOUR_API_KEY" \
-F "file=@car.jpg" \
--output result.pngShadows
Results come with an AI shadow by default. A dedicated shadow model generates a soft shadow that matches the subject's shape and where it meets the ground, so there is nothing to tune by hand — the single shadow parameter only decides when it is there: auto (the default) adds it when a vehicle is detected, force adds it to any subject (a product, a person, a pet…), and none returns a cutout with no shadow at all. Vehicle detection is part of the window cleanup, so with transparent_windows=false use forceto keep the shadow. The shadow is part of the image's transparency, so it also works together with the bg_ options below and costs no extra credits.
curl -X POST "https://api.remover.bg/remove-bg?shadow=force" \
-H "Authorization: Bearer rmbg_YOUR_API_KEY" \
-F "file=@product.jpg" \
--output result.pngcurl -X POST "https://api.remover.bg/remove-bg?shadow=none" \
-H "Authorization: Bearer rmbg_YOUR_API_KEY" \
-F "file=@car.jpg" \
--output result.pngBackgrounds
Replace the removed background in the same call. Pass bg_color for a solid color (hex or color name; use a 4-/8-digit hex code for semi-transparency), bg_image_url to load a background image from a URL, or upload one directly as a bg_image_file multipart field. Background images are centered and scaled to fill the canvas while keeping their aspect ratio. Only one bg_ option can be used per request, and backgrounds do not affect credit usage.
# Solid color
curl -X POST "https://api.remover.bg/remove-bg?bg_color=81d4fa" \
-H "Authorization: Bearer rmbg_YOUR_API_KEY" \
-F "file=@photo.jpg" \
--output result.png
# Background image from a URL
curl -X POST "https://api.remover.bg/remove-bg?bg_image_url=https%3A%2F%2Fexample.com%2Fbeach.jpg" \
-H "Authorization: Bearer rmbg_YOUR_API_KEY" \
-F "file=@photo.jpg" \
--output result.png
# Background image from a file
curl -X POST "https://api.remover.bg/remove-bg" \
-H "Authorization: Bearer rmbg_YOUR_API_KEY" \
-F "file=@photo.jpg" \
-F "bg_image_file=@beach.jpg" \
--output result.pngResponse formats
By default the response body is the processed image (binary). Pass ?response=url to instead receive JSON with a temporary download URL:
curl -X POST "https://api.remover.bg/remove-bg?response=url" \
-H "Authorization: Bearer rmbg_YOUR_API_KEY" \
-F "file=@photo.jpg"{
"url": "https://.../outputs/.../abc.png?X-Amz-...",
"format": "png",
"model": "quality",
"expiresAt": "2026-06-20T10:00:00.000Z"
}Stored results — including the URL above — are automatically deleted after 24 hours. Download promptly or use the default binary response.
Select objects
Decide which objects stay in the cutout: keep only the car and drop the person next to it, remove leftovers such as a hanging cable, or bring back something the automatic cutout left out. You pay for the background removal once; finding objects and applying a selection are free.
1. Remove the background with a session
Add session=1 to /remove-bg. The response is the usual image, plus an X-Photo-Session header with the session id and X-Photo-Session-Expires. The session lasts 1 hour and only your account can use it. Sessions need a PNG, untrimmed result (trim defaults to false here), without bg_ options or response=url.
curl -X POST "https://api.remover.bg/remove-bg?session=1" \
-H "Authorization: Bearer rmbg_YOUR_API_KEY" \
-F "file=@car.jpg" \
-D headers.txt \
--output result.png2. Find the objects
POST/photos/{session_id}/objects
Send an empty JSON body to list the objects in the photo. Boxes are in pixels of the original image; each mask is a grayscale PNG (white = object) at maskWidth × maskHeight. inCutout tells whether the current cutout already contains the object, and parentIdmarks parts of another object (a car's wheels or plate). initialIds is what the automatic cutout kept. To look for something specific, send up to three English words — they are added to the list and returned in foundIds.
curl -X POST "https://api.remover.bg/photos/SESSION_ID/objects" \
-H "Authorization: Bearer rmbg_YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{}'
# Look for specific things
curl -X POST "https://api.remover.bg/photos/SESSION_ID/objects" \
-H "Authorization: Bearer rmbg_YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{"words": ["dog", "suitcase"]}'{
"sessionId": "4274a568663844be82f215d9270856a1",
"width": 1500,
"height": 2000,
"maskWidth": 1440,
"maskHeight": 1920,
"objects": [
{
"id": "o1",
"name": "car",
"score": 0.93,
"box": [96, 610, 1410, 1720],
"maskUrl": "data:image/png;base64,iVBORw0KGgo...",
"inCutout": true,
"parentId": null
},
{
"id": "o2",
"name": "wheel",
"score": 0.88,
"box": [180, 1390, 470, 1712],
"maskUrl": "data:image/png;base64,iVBORw0KGgo...",
"inCutout": true,
"parentId": "o1"
}
],
"initialIds": ["o1"],
"foundIds": [],
"expiresAt": "2026-11-19T10:00:00.000Z"
}3. Apply the selection
POST/photos/{session_id}/apply
Send the ids to keep. The response is a PNG the size of the original. Only the listed objects stay: anything else the cutout had is removed, including leftovers that were not detected as objects, and listed objects the cutout had left out are added back. Fine edges such as hair are kept. The AI shadow stays only while every id in initialIds is kept. You can apply as many selections as you like within the session.
curl -X POST "https://api.remover.bg/photos/SESSION_ID/apply" \
-H "Authorization: Bearer rmbg_YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{"keep": ["o1"]}' \
--output selection.pngLimits per session: 12 object searches and 40 selections. An expired session returns 404; if object detection is busy you get 409 with a Retry-After header.
Get account
GET/account
Returns your remaining credits, active subscription and recent usage. Does not consume credits. Also available at /me.
Examples
curl "https://api.remover.bg/account" \
-H "Authorization: Bearer rmbg_YOUR_API_KEY"Response
{
"credits": 142,
"subscription": {
"plan": "pro_yearly",
"status": "active",
"currentPeriodEnd": "2027-01-15T00:00:00.000Z"
},
"usage": { "last30Days": 37 }
}Responses & errors
/remove-bg returns the processed image (binary) on 200, with headers X-Credits-Remaining (balance after the call) and X-Output-File (suggested filename). Errors return JSON: { "error": "message" }.
| Status | Meaning |
|---|---|
| 400 | Missing file or invalid parameter. |
| 401 | Missing or invalid API key. |
| 402 | Insufficient credits. |
| 404 | Photo session not found or expired (Select objects). |
| 409 | Object detection is busy — retry after the Retry-After header (Select objects). |
| 413 | File too large (max 25 MB) or image above 50 megapixels. |
| 415 | Unsupported file type (use PNG, JPEG or WebP). |
| 422 | Invalid request body, e.g. an unknown object id (Select objects). |
| 429 | Per-session limit reached (Select objects). |
| 503 | Server busy — retry shortly. |
| 504 | Processing timed out. |
Credits & pricing
Each successful /remove-bg call consumes 1 credit. Failed requests are not charged. Top up or subscribe on the pricing page.
API changelog
- Improved
Small leftovers that are detached from the subject and sit well away from it — such as a stray piece of cable — are now removed automatically, before shadows and trimming, so trimmed results are tighter. Thin parts close to the subject, such as chair wires or bicycle frames, are kept.
- New
Added object selection:
session=1on/remove-bgopens a one-hour photo session;POST /photos/{id}/objectslists the objects in the photo andPOST /photos/{id}/applykeeps only the ones you choose — leftovers such as hanging cables are removed. Both are free. - New
Added
shadow=force— applies the AI shadow to any subject, not only to detected vehicles.auto(default) andnoneare unchanged. - Changed
Shadows are now produced by a dedicated AI model and are on by default. A single
shadowparameter takesauto(default) ornone; the oldshadow_type,shadow_opacityandshadow_directionparameters have been removed. Shadows still do not affect credit usage. - New
Added
shadow_direction(−60 to 60 degrees) — 0 drops the shadow straight down, positive tilts it right, negative left. Applies to bothcaranddropshadows. - New
Added shadows:
shadow_type(auto,car,drop,none) withshadow_opacity(0–100 orauto) — a soft drop shadow under the subject (a larger, softer one for vehicles), falling straight down by default. Shadows do not affect credit usage. - New
Added background replacement:
bg_color(solid color, semi-transparent hex supported),bg_image_urlandbg_image_file(custom image, centered and scaled to fill the canvas). Backgrounds do not affect credit usage. - New
Added the
trim_marginparameter — leave a pixel (30px) or percentage (10%) margin around the subject when trimming. - New
Added the
transparent_windowsparameter — choose between naturally transparent or fully opaque car windows. - Improved
Car photos now get clean windows automatically: the old background visible through the glass is removed and a subtle transparency is kept.
- Changed
Simplified to a single high-quality model. Every call now costs exactly 1 credit; the
typeparameter is no longer needed and is ignored. - New
The
X-Trimresponse header now reports how much was trimmed from each edge, so results can be repositioned precisely over the original. - Improved
response=urldownload links are now signed, private URLs that expire together with the stored result (24 hours). - New
Added
response=url— receive JSON with a temporary download URL instead of the binary image. - Launch
Public API launch:
POST /remove-bgandGET /accountwith API-key authentication. PNG, JPEG and WebP supported as input and output formats.
Video endpoint
Upload a clip, poll the job, download the result. Not part of the public API yet.