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.

Get an API key50 free preview calls a month

Migrate from remove.bg in one line

The only differences in a typical call are the host and the key:

Before: remove.bg
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.png
After: ClearBG
curl -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.png

Background 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.

Fieldremove.bgClearBG
image_fileFile uploadSupported (multipart)
image_file_b64Base64 imageSupported, with or without a data:…;base64, prefix
image_urlDownloaded by the serverSupported 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
sizeDefault previewDefault 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
formatauto, png, jpg, webp, zipauto (PNG), png, webp, and jpg on white or on bg_color. zip: 400 invalid_format
channelsrgba or alphaSame; alpha always returns a grayscale PNG
bg_colorHex or colour name3- 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_fileBackground imageNot supported: 400 invalid_bg_image_url
cropCrop to the subjectSupported
crop_marginMargin around the cropOnly 0; anything else: 400 invalid_crop_margin
roiRegion of interestOnly the whole image; anything else: 400 invalid_roi
scale, positionResize or move the subjectOnly original; anything else: 400 invalid_scale or invalid_position
add_shadow, shadow_typeDrop shadowOff is accepted; asking for a shadow: 400 unsupported_shadow
type, type_level, semitransparency, shadow_opacityForeground hintsAccepted 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.

JSON response, from an image URL, as a JPG on white
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
Response
{"data":{"result_b64":"iVBORw0KGgo…","foreground_top":0,"foreground_left":0,"foreground_width":1200,"foreground_height":800}}

Response headers

HeaderValue
X-Credits-Charged1 for a full-resolution image, 0 for a preview
X-Width, X-HeightSize of the result, after scaling and cropping
X-Foreground-Top, -Left, -Width, -HeightThe subject's box (pixels with alpha of at least 0.05)
X-RateLimit-Limit, -Remaining, -ResetRequests a minute, left this minute, reset time (Unix seconds)
Retry-AfterSeconds to wait, on 429 and 503 only
X-TypeNot sent: ClearBG doesn't classify the subject

Check your balance

curl
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.

Example error
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."}]}
StatuscodeWhen
400missing_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_requestSomething is wrong with the parameters or the image (the codes match remove.bg's, plus the last two)
402insufficient_creditsNo credit for a full-resolution image, or this month's 50 free previews are used
403auth_failedThe key is missing, wrong or revoked
404, 405not_found, method_not_allowedAnother path or method
429rate_limit_exceededMore than 500 requests in a minute on this key
500internal_error, timeoutThe GPU failed, or did not answer in 90 seconds and again in a 45-second retry
503service_busyPaused, 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-Remaining and X-RateLimit-Reset; past the limit you get a 429 with Retry-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 buyPricePer 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 monthFree$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
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.png

Python (requests)

Python (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 (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 (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.

Get an API key

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.