This API removes the background from a photo and returns a transparent PNG, a JPG on a color, a WebP, a ZIP or an alpha mask. It accepts remove.bg's request format, so an existing integration keeps working when you change two things: the host and the API key. remove.bg's FAQ says its self-service API stops accepting requests on December 1, 2026, and its successor, Leonardo.Ai, uses a different JSON-only API.
Requests go to https://api.backgroundremoverpng.com/v1.0/removebg; https://backgroundremoverpng.com/v1.0/removebg works too. Calls are paid with the same image credits as the website.
Get an API key
- Open your account, enter your email address and type the code we send you. Keys need an email-verified account; a browser that only bought credits at checkout verifies with the same email.
- Under API keys, name the key and choose Create key. Copy it straight away: it is shown once and we keep only a hash of it.
- Keep the key on your server. Anyone with it can spend your credits, so revoke it from the account page if it leaks.
Sample code
These are remove.bg's own samples with the host and key changed. Replace INSERT_YOUR_API_KEY_HERE with your key.
cURL, with a file:
$ curl -H 'X-API-Key: INSERT_YOUR_API_KEY_HERE' \
-F 'image_file=@/path/to/file.jpg' \
-F 'size=auto' \
-f https://api.backgroundremoverpng.com/v1.0/removebg -o no-bg.png
Node.js, with a file:
import fs from "node:fs";
async function removeBg(blob) {
const formData = new FormData();
formData.append("size", "auto");
formData.append("image_file", blob);
const response = await fetch("https://api.backgroundremoverpng.com/v1.0/removebg", {
method: "POST",
headers: { "X-Api-Key": "INSERT_YOUR_API_KEY_HERE" },
body: formData,
});
if (response.ok) {
return await response.arrayBuffer();
} else {
throw new Error(`${response.status}: ${response.statusText}`);
}
}
const inputPath = "/path/to/file.jpg";
const fileBlob = await fs.openAsBlob(inputPath)
const rbgResultData = await removeBg(fileBlob);
fs.writeFileSync("no-bg.png", Buffer.from(rbgResultData));
Python, with a file:
# Requires "requests" to be installed (see python-requests.org)
import requests
response = requests.post(
'https://api.backgroundremoverpng.com/v1.0/removebg',
files={'image_file': open('/path/to/file.jpg', 'rb')},
data={'size': 'auto'},
headers={'X-Api-Key': 'INSERT_YOUR_API_KEY_HERE'},
)
if response.status_code == requests.codes.ok:
with open('no-bg.png', 'wb') as out:
out.write(response.content)
else:
print("Error:", response.status_code, response.text)
With an image URL instead of a file, send image_url (this example uses one of our sample photos):
$ curl -H 'X-API-Key: INSERT_YOUR_API_KEY_HERE' \
-F 'image_url=https://backgroundremoverpng.com/examples/dog-before.jpg' \
-F 'size=auto' \
-f https://api.backgroundremoverpng.com/v1.0/removebg -o no-bg.png
response = requests.post(
'https://api.backgroundremoverpng.com/v1.0/removebg',
data={
'image_url': 'https://backgroundremoverpng.com/examples/dog-before.jpg',
'size': 'auto'
},
headers={'X-Api-Key': 'INSERT_YOUR_API_KEY_HERE'},
)
Requests can be multipart/form-data, application/x-www-form-urlencoded or JSON (image_file_b64 or image_url plus options).
Sizes and credits
| size | Output | Credits |
|---|---|---|
preview (default), small, regular |
Up to 0.25 megapixels | 50 free a month per account, then one credit covers four previews |
medium, hd |
Up to 1.5 or 4 megapixels | 1 |
full, 4k |
Original size, up to 25 megapixels | 1 |
auto |
Full size when your credits cover it, otherwise a preview | As above |
50MP |
Not available | – |
Any result of 0.25 megapixels or less is billed as a preview, whatever size you ask for. The X-Credits-Charged header reports what each call spent. Errors never use credits. Sending the same image again within 24 hours is not charged again, in any format or size up to what was paid for, so an interrupted download can simply be retried. GET /v1.0/account reports your balance.
Parameters
| Parameter | Status | Notes |
|---|---|---|
image_file, image_file_b64, image_url |
Supported | One per request. JPG, PNG or WebP, up to 20 MB, 50 megapixels and 12,000 pixels per side. image_url must be a public https address; up to three redirects are followed and the download must finish within 10 seconds. |
size |
Supported | See the table above. |
format |
Supported | auto, png, jpg, webp, zip. auto gives PNG when the result has transparent areas and JPG otherwise; alpha masks come as PNG. JPG without bg_color goes on white. |
channels |
Supported | rgba (default) or alpha, a grayscale mask. |
bg_color |
Supported | Hex (fff, 81d4fa, 81d4fa77 with alpha) or a color name such as green. |
crop, crop_margin |
Supported | Crops to the subject. The margin takes pixels or a percentage of the subject, with one, two or four values, and is capped at 50% of the subject and 500 pixels per side. |
scale, position |
Supported | scale from 10% to 100% of the image; position is original, center or x% y%. Scaling centers the subject unless you set a position. |
roi |
Supported | Pixels outside the rectangle (x1 y1 x2 y2 in px or %) are removed. The model still looks at the whole photo. |
type |
Accepted | One general model handles every subject, so the value does not change the result. |
semitransparency |
Accepted | Soft and see-through edges are always kept as partial transparency. |
type_level |
none only |
There is no subject classification and no X-Type header. |
add_shadow, shadow_type, shadow_opacity |
Off only | false and none are accepted; shadows are refused. |
bg_image_url, bg_image_file |
Not supported | Use bg_color, or place the transparent result on your own background. |
OAuth (Authorization: Bearer) |
Not supported | Use the X-Api-Key header. |
POST /v1.0/improve |
Not supported | Returns 501. |
Responses and errors
A successful call returns the image with the same headers as remove.bg: X-Width, X-Height, X-Credits-Charged and the subject's position as X-Foreground-Top, X-Foreground-Left, X-Foreground-Width and X-Foreground-Height. Send Accept: application/json to get {"data": {"result_b64": ..., "foreground_top": ...}} instead of raw bytes. A ZIP holds color.jpg and alpha.png, as remove.bg's does.
Errors use remove.bg's format, {"errors": [{"title": ..., "code": ..., "detail": ...}]}, with the same status codes: 400 for a problem with the request or the image (for example missing_source, file_too_large, invalid_file_type or unknown_foreground), 402 when credits run out, 403 for a missing or wrong key, and 429 when the rate limit is reached. A 5xx means the failure was ours; retry later. None of them use credits.
Account and rate limits
GET /v1.0/account returns remove.bg's shape: data.attributes.credits with total, subscription, payg and enterprise, and data.attributes.api.free_calls, the free previews left this month. It also reports prepaid_previews.
Each key can process 300 output megapixels a minute; an image counts as its output size, at least one. Every response carries X-RateLimit-Limit, X-RateLimit-Remaining and X-RateLimit-Reset, and a 429 adds Retry-After in seconds.
Migration checklist for December 1
- Create your key in your account and buy credits on the pricing page. Packs do not expire.
- Change the host in your code from
api.remove.bgtoapi.backgroundremoverpng.comand swap in the new key. - Compare your parameters with the table above. Remove shadow, background image and classification options; everything else can stay.
- Try
size=previewon a handful of your usual images, which is free, and check the edges before switching production traffic. - Keep your existing handling for 402, 429 and
Retry-After; the codes behave the same way. - Switch before 9:00 a.m. CET on December 1, 2026, when remove.bg says its self-service API stops.
What is different from remove.bg
The cutouts come from Cloudflare Images' background segmentation, which runs the open-source BiRefNet model; they are not remove.bg's results, and we have not measured them against remove.bg. Hair, fur, glass and busy backgrounds are the hardest cases for any remover, so test your own images. PNG goes up to 25 megapixels here rather than remove.bg's 10, but uploads stop at 20 MB instead of 22 MB, and there is no 50-megapixel option. See the remove.bg comparison for the website side.
Images sent to the API are processed by Cloudflare and are not stored by us; the privacy policy explains what the API records, and the terms cover keys and usage.
Frequently asked questions
Do I have to rewrite my remove.bg integration?
No, for the supported parameters. Replace https://api.remove.bg with https://api.backgroundremoverpng.com and use a key from your account. The endpoints, form fields, response headers and error format stay the same. Shadows, background images, classification levels and 50MP output are refused with a clear error instead.
What does an API call cost?
The API uses the same image credits as the website. A full-size result above 0.25 megapixels costs one credit. Each account gets 50 free previews a month; after that, one credit covers four previews. Errors never use credits, and the same image again within 24 hours is not charged again.
Do you keep the images I send?
No. Cloudflare processes each image to remove its background and the result goes straight back in the response. We do not store the image, its URL or the result. Billing records hold credit use, not image data.
Is this API run by remove.bg?
No. Background Remover is an independent service. The API accepts remove.bg's request format so that existing integrations can switch before remove.bg's self-service API stops on December 1, 2026.
How fast is it and how many images can I send?
Most images take a few seconds; very large photos take longer because the full-size PNG or JPG is encoded on our server. Each key can process 300 output megapixels a minute. The X-RateLimit headers show what is left, and a 429 response includes Retry-After.