remove.bg-compatible Background Removal API
ClearBG's background removal API takes the same endpoint path, fields and X-Api-Key header as remove.bg's API v1.0. Change the host to api.clearbg.org, use a ClearBG key, and your requests keep working. A full-resolution image costs 1 credit ($0.05 to $0.01 with packs); 50 preview calls a month are free.
Migrate from remove.bg in one line
The only differences in a typical call are the host and the key:
curl -H 'X-Api-Key: YOUR_REMOVE_BG_KEY' \
-F 'image_file=@photo.jpg' \
-F 'size=auto' \
-f https://api.remove.bg/v1.0/removebg -o no-bg.pngcurl -H 'X-Api-Key: YOUR_CLEARBG_KEY' \
-F 'image_file=@photo.jpg' \
-F 'size=auto' \
-f https://api.clearbg.org/v1.0/removebg -o no-bg.pngBackground removal API endpoint and authentication
POST https://api.clearbg.org/v1.0/removebg removes the background. GET https://api.clearbg.org/v1.0/account returns your balance and costs nothing.
Send your key in the X-Api-Key header. Keys start with cbg_live_, are shown once when you create them, and can be revoked on your account page; each account can have 10 active keys. OAuth is not supported. The API has no CORS headers: call it from your server, never from a browser, so the key stays private.
Request bodies can be multipart/form-data, application/json or application/x-www-form-urlencoded. Give exactly one image source: image_file (a file upload), image_file_b64 (base64, with or without a data: prefix) or image_url (a public http or https address we download, up to 3 redirects, 20 seconds and 25 MB).
Input images: JPG, PNG or WebP (checked from the file's bytes, not its name), up to 25 MB and 12,000 pixels on a side.
Parameters
Fields that don't change the picture are accepted and ignored. Fields that would change it in a way we can't do are refused with a 400 error, so you never get a different image without knowing.
| Field | remove.bg | ClearBG |
|---|---|---|
image_file | File upload | Supported (multipart) |
image_file_b64 | Base64 image | Supported, with or without a data:…;base64, prefix |
image_url | Downloaded by the server | Supported for public http(s) addresses on ports 80 and 443; 3 redirects, 20 s, 25 MB. A bad address returns invalid_image_url, a failed download failed_image_download |
size | Default preview | Default preview too. preview, small, regular: 0.25 MP. medium: 1.5 MP. hd: 4 MP. full, 4k, auto, 50MP: original resolution up to 25 MP. Anything else: invalid_size |
format | auto, png, jpg, webp, zip | auto (PNG), png, webp, and jpg on white or on bg_color. zip: 400 invalid_format |
channels | rgba or alpha | Same; alpha always returns a grayscale PNG |
bg_color | Hex or colour name | 3- or 6-digit hex (with or without #) and the 17 basic CSS colour names. Semi-transparent hex: 400 invalid_bg_color |
bg_image_url, bg_image_file | Background image | Not supported: 400 invalid_bg_image_url |
crop | Crop to the subject | Supported |
crop_margin | Margin around the crop | Only 0; anything else: 400 invalid_crop_margin |
roi | Region of interest | Only the whole image; anything else: 400 invalid_roi |
scale, position | Resize or move the subject | Only original; anything else: 400 invalid_scale or invalid_position |
add_shadow, shadow_type | Drop shadow | Off is accepted; asking for a shadow: 400 unsupported_shadow |
type, type_level, semitransparency, shadow_opacity | Foreground hints | Accepted and ignored |
Response
By default the response body is the image itself (image/png, image/webp or image/jpeg). Send Accept: application/json to get remove.bg's JSON instead, with the image as base64 in data.result_b64 and the foreground box in foreground_top, foreground_left, foreground_width and foreground_height.
curl -H 'X-Api-Key: YOUR_CLEARBG_KEY' \
-H 'Accept: application/json' \
-F 'image_url=https://example.com/photo.jpg' \
-F 'size=full' -F 'format=jpg' -F 'bg_color=ffffff' \
https://api.clearbg.org/v1.0/removebg{"data":{"result_b64":"iVBORw0KGgo…","foreground_top":0,"foreground_left":0,"foreground_width":1200,"foreground_height":800}}Response headers
| Header | Value |
|---|---|
X-Credits-Charged | 1 for a full-resolution image, 0 for a preview |
X-Width, X-Height | Size of the result, after scaling and cropping |
X-Foreground-Top, -Left, -Width, -Height | The subject's box (pixels with alpha of at least 0.05) |
X-RateLimit-Limit, -Remaining, -Reset | Requests a minute, left this minute, reset time (Unix seconds) |
Retry-After | Seconds to wait, on 429 and 503 only |
X-Type | Not sent: ClearBG doesn't classify the subject |
Check your balance
curl -H 'X-Api-Key: YOUR_CLEARBG_KEY' https://api.clearbg.org/v1.0/account
{"data":{"attributes":{"credits":{"total":96,"subscription":0,"payg":96,"enterprise":0},"api":{"free_calls":50,"sizes":"all"}}}}Errors
Errors use remove.bg's shape: {"errors":[{"title":"…","code":"…","detail":"…"}]} (detail is sometimes missing). A failed request never costs a credit.
HTTP/1.1 402 Payment Required
{"errors":[{"title":"Insufficient credits","code":"insufficient_credits","detail":"A full-resolution image costs 1 credit. Buy credits on https://clearbg.org/pricing."}]}| Status | code | When |
|---|---|---|
| 400 | missing_source, multiple_sources, invalid_image_url, failed_image_download, file_too_large, invalid_file_type, resolution_too_high, failed_to_read_image, unknown_foreground, invalid_size, invalid_format, invalid_channels, invalid_bg_color, invalid_bg_image_url, multiple_bg_sources, invalid_roi, invalid_crop_margin, invalid_scale, invalid_position, unsupported_shadow, invalid_request | Something is wrong with the parameters or the image (the codes match remove.bg's, plus the last two) |
| 402 | insufficient_credits | No credit for a full-resolution image, or this month's 50 free previews are used |
| 403 | auth_failed | The key is missing, wrong or revoked |
| 404, 405 | not_found, method_not_allowed | Another path or method |
| 429 | rate_limit_exceeded | More than 500 requests in a minute on this key |
| 500 | internal_error, timeout | The GPU failed, or did not answer in 90 seconds and again in a 45-second retry |
| 503 | service_busy | Paused, or at the day's safety limit; try again after Retry-After |
Rate limits and free previews
- 500 requests a minute per key. Every response carries
X-RateLimit-Limit,X-RateLimit-RemainingandX-RateLimit-Reset; past the limit you get a 429 withRetry-After. remove.bg counts megapixel-weighted images instead of requests. - 50 preview calls (0.25 megapixels, the default
size) a month are free per email address (several accounts on one address share them). After that, previews return 402 until the next calendar month (UTC); remove.bg charged 0.25 credits each instead. - Up to 4 images per account are processed at the same time, across all of its keys. A fifth request at once gets a 429 with
Retry-After: 2; send in parallel up to 4 and queue the rest. - If the service is paused or busy you get a 503 with
Retry-After, and nothing is charged. - Requests are synchronous: we wait up to 90 seconds for the GPU, and if it was still starting up we try once more for up to 45 seconds. Set your client timeout to at least 150 seconds.
Background removal API price per image
One credit is one full-resolution image, on the API and on the website. Plan credits are used first, then pack credits. Packs never expire; plan credits reset every month. See pricing to buy.
| What you buy | Price | Per image |
|---|---|---|
| 100 credits (never expire) | $5.00 | $0.050 |
| 1,000 credits (never expire) | $25.00 | $0.025 |
| 10,000 credits (never expire) | $150.00 | $0.015 |
| 50,000 credits (never expire) | $500.00 | $0.010 |
| Starter plan, 500 credits a month | $9.00 a month or $86.00 a year | $0.0180 monthly, $0.0143 yearly |
| Pro plan, 2,500 credits a month | $29.00 a month or $278.00 a year | $0.0116 monthly, $0.0093 yearly |
| Business plan, 10,000 credits a month | $79.00 a month or $758.00 a year | $0.0079 monthly, $0.0063 yearly |
| Preview (0.25 MP), 50 a month | Free | $0 |
Code samples
Each sample uploads photo.jpg at full resolution and saves the transparent PNG. Put your key in the CLEARBG_API_KEY environment variable.
curl
curl -H 'X-Api-Key: YOUR_CLEARBG_KEY' \
-F 'image_file=@photo.jpg' \
-F 'size=full' \
-f https://api.clearbg.org/v1.0/removebg -o photo-clearbg.pngPython (requests)
import os
import requests
response = requests.post(
"https://api.clearbg.org/v1.0/removebg",
files={"image_file": open("photo.jpg", "rb")},
data={"size": "full"},
headers={"X-Api-Key": os.environ["CLEARBG_API_KEY"]},
timeout=120,
)
if response.status_code == 200:
with open("photo-clearbg.png", "wb") as out:
out.write(response.content)
else:
print(response.status_code, response.json()["errors"])Node.js (fetch)
// Node.js 18 or later (built-in fetch, FormData and Blob)
import { readFile, writeFile } from 'node:fs/promises';
const form = new FormData();
form.append('image_file', new Blob([await readFile('photo.jpg')]), 'photo.jpg');
form.append('size', 'full');
const res = await fetch('https://api.clearbg.org/v1.0/removebg', {
method: 'POST',
headers: { 'X-Api-Key': process.env.CLEARBG_API_KEY },
body: form,
signal: AbortSignal.timeout(120_000),
});
if (!res.ok) throw new Error(JSON.stringify(await res.json()));
await writeFile('photo-clearbg.png', Buffer.from(await res.arrayBuffer()));PHP (cURL)
<?php
$ch = curl_init('https://api.clearbg.org/v1.0/removebg');
curl_setopt_array($ch, [
CURLOPT_POST => true,
CURLOPT_HTTPHEADER => ['X-Api-Key: ' . getenv('CLEARBG_API_KEY')],
CURLOPT_POSTFIELDS => [
'image_file' => new CURLFile('photo.jpg'),
'size' => 'full',
],
CURLOPT_RETURNTRANSFER => true,
CURLOPT_TIMEOUT => 120,
]);
$body = curl_exec($ch);
$status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if ($status === 200) {
file_put_contents('photo-clearbg.png', $body);
} else {
echo $body;
}Get a background removal API key
Sign in with Google or an email link, then create a key under API keys on your account page. Copy it when it is shown: we only keep a hash of it.
Questions about migrating from the remove.bg API
Is the output the same size as remove.bg's?
The size values map to the same megapixel limits up to hd (4 MP). full, 4k, auto and 50MP return the original resolution capped at 25 megapixels, where remove.bg allowed up to 50.
Do I get the X-Type header?
No. remove.bg sends a foreground category there; ClearBG doesn't classify images, so it leaves the header out rather than guess.
Can I test without paying?
Yes: 50 preview calls a month are free on every account, and the website gives one free full-resolution image a day. Full-resolution API calls need credits from the start.
Do you keep the images I send?
No. The original is deleted as soon as the GPU has read it and the result right after the response is sent. Only the request's size, cost and timing stay for your usage table. Nothing is used for training.
Can I keep using the remove.bg SDKs and plugins?
A library that lets you set the base URL can point at https://api.clearbg.org/v1.0. One that hard-codes api.remove.bg needs that line changed. We haven't tested specific SDKs.