Remove Background API
The Remove Background API cuts the subject out of a photo: people, products, animals, cars and other objects. Send an image, as an upload or a link, and get back the subject on a transparent background as a PNG or WebP, or on a color you choose.
Fine detail such as hair, fur and thin edges is kept, and the old background's color is removed from semi-transparent edges, so the cut-out looks natural on any new background. Results keep the photo's full resolution.
Use it for e-commerce product photos, marketplace listings, profile pictures, ID photos, stickers and design tools. Set crop=true to trim the result to the subject, or output=mask to get a mask for your own editing.
Each image counts as 1 API call, up to your plan's monthly background removals: Free 30 (low-resolution previews), Developer 5,000, Business 20,000, Professional 50,000. Your dashboard shows how many you've used this month. See pricing.
More image APIs: the Object Detection API finds and labels the objects in an image, the Face Detect API finds faces, and the Image to Text API reads the text in an image.
Available endpoint:
- /v1/removebackground - Remove the background from an image
At a Glance
| Input | JPEG, PNG or WebP: upload, raw body, or image_url (up to 25 megapixels) |
|---|---|
| Output | PNG or WebP with transparency, or JPG, as base64 in JSON or as an image file |
| Resolution | Full size (Free plan: previews up to 0.25 megapixels) |
| Plan usage | 1 API call per image |
| Background removals per month | Free 30, Developer 5,000, Business 20,000, Professional 50,000 |
Example


https://api.api-ninjas.com/v1/removebackground
Removes the background from a photo and returns the subject on a transparent background, or on a color you choose. Returns the image as base64 in JSON, or as an image file.
Parameters
Send the photo as an image upload (multipart form data), as the raw request body, or as an image_url link. The other parameters are query parameters.
imagerequired, unless image_url is setThe photo, a JPEG, PNG or WebP file up to 4 MB, as a multipart form field named
image. You can also send the file as the raw request body with itsContent-Type, e.g.image/jpeg.image_urloptionalA public
httporhttpslink to the image, instead of uploading it. Up to 20 MB (4 MB on the Free plan).formatoptionalFile format of the result:
png(default),webporjpg. PNG and WebP keep the transparent background, and WebP files are several times smaller. JPG has no transparency, so the background becomesbg_color, or white.bg_coloroptionalFill the background with this color instead of making it transparent: a hex color code without the
#, e.g.fffffffor white orf2f2f2for light gray.cropoptionalSet to
trueto trim the result to the subject, with no empty margins. By default the result is the same size as the photo.outputoptionalimage(default) returns the cut-out.maskreturns a grayscale mask the size of the photo instead: white for the subject, black for the background, and gray for semi-transparent edges such as hair.
Headers
X-Api-KeyrequiredAPI Key associated with your account.
Acceptoptionalimage/png,image/webp,image/jpegorimage/*returns the image file itself instead of JSON.Content-TypeoptionalThe image type, e.g.
image/jpegorimage/png, when the request body is the image itself. Multipart uploads set their own content type.
Response
The /v1/removebackground endpoint returns a JSON object with the following fields, or an error if the request is unsuccessful (see errors).
imageThe result image, base64-encoded.
content_typeimage/png,image/webporimage/jpeg.widthWidth of the result in pixels: the photo's width, unless
crop=trueor the result is a preview.heightHeight of the result in pixels.
foreground_boxWhere the subject is in the result, in pixels:
left,top,widthandheight. Use it to center or place the subject.previewtruewhen the result is a low-resolution preview (Free plan).image_urlFor results over about 4.4 MB (for example large PNGs), a link to download the result, valid for 1 hour, instead of
image.expires_in(seconds) andsize_bytescome with it.
With an image Accept header, the response body is the image file itself, and the same details come as the X-Foreground-Left, X-Foreground-Top, X-Foreground-Width, X-Foreground-Height and X-Preview headers. Results over about 4.4 MB are always JSON with image_url.
Limits
- JPEG, PNG or WebP images up to 25 megapixels, with each side at least 16 pixels.
- Uploads up to 4 MB; images from
image_urlup to 20 MB (4 MB on the Free plan). - Results keep the photo's full resolution. Free plan results are previews of up to 0.25 megapixels, e.g. 612 × 408.
- One image per request. Most photos take 3 to 8 seconds, so set your HTTP client's timeout to 30 seconds or more.
Background removals
Each image counts as 1 API call. Plans also include a monthly number of background removals: Free 30, Developer 5,000, Business 20,000 and Professional 50,000. The count resets on the 1st of each month (UTC), and requests that fail are not counted. Your dashboard shows how many you've used this month, and Professional and Enterprise plans can also read the count from the Analytics API.
Live Demo

Get a free API key to get started — no credit card required.

Download the result (800 × 999 px, subject 753 × 953 at 33, 46)
No API key is needed to try it. Without a key, the demo returns low-resolution previews, as on the Free plan.
Code Examples
# Remove the background and save the result as a WebP image with transparency.
# (Results over about 4.4 MB come back as JSON with a download link in image_url.)
curl -X POST "https://api.api-ninjas.com/v1/removebackground?format=webp" \
-H "X-Api-Key: YOUR_API_KEY" \
-H "Accept: image/webp" \
-F "image=@photo.jpg" \
--output photo-no-bg.webpErrors
An invalid request returns HTTP 400 with a JSON body holding a readable error message. If too many images are being processed at once, the API returns HTTP 503: retry after a few seconds. Requests that fail are not counted. Authentication and quota errors use the standard format described in error codes.
| Cause | Example error |
|---|---|
| No image in the request | Missing image. Send the file in a form field named image, or pass image_url. |
| A file that is not a JPEG, PNG or WebP image | Unsupported image format. Send a JPEG, PNG or WebP file. |
| An upload over 4 MB | Image is larger than 4 MB. |
| An image over 25 megapixels | Image is too large. The maximum is 25 megapixels. |
| An image under 16 pixels on a side | Image is too small. Each side must be at least 16 pixels. |
| No subject found, e.g. a blank wall | No foreground subject was found in the image. |
An image_url on a private network | image_url must point to a public internet address. |
An image_url that could not be downloaded | Could not download image_url (HTTP 404). |
A format other than png, webp or jpg | format must be png, webp or jpg. |
A bg_color that is not a hex color | bg_color must be a hex color such as ffffff or 000000. |
An output other than image or mask | output must be image or mask. |
A crop other than true or false | crop must be true or false. |
| All of this month's background removals used | Your Developer plan includes 5,000 background removals a month and they have all been used. The count resets on the 1st of the month (UTC). Upgrade at https://api-ninjas.com/pricing for more. |
| Free plan: all 30 background removals used | The Free plan includes 30 background removals a month, at preview size. Upgrade at https://api-ninjas.com/pricing for more images and full resolution. |
Frequently Asked Questions
Can I use the Remove Background API for commercial purposes?
Yes, but you must have a premium subscription. Commercial use of the Remove Background API is not permitted on the free tier. See our pricing page to choose a plan that fits your needs.How do I get an API key and start using the Remove Background API?
Sign up for a free account to instantly get your API key, then pass it in theX-Api-Keyheader on every request. The documentation above includes ready-to-run examples in cURL, Python, JavaScript, Node.js, and more.What happens if I exceed my quota for the month?
Your API requests will simply be denied once you hit your monthly quota — you will never be charged more than the plan you signed up for. To increase your quota, you can upgrade your plan any time on our pricing page.What happens if a request to the Remove Background API fails?
The API responds with a standard HTTP status code and a JSON error message describing the problem. See our error codes reference for the full list of codes and how to resolve each one, or contact support if you need help.How do I remove the background from an image with an API?
POST the photo to/v1/removebackgroundas a multipart upload namedimage, e.g.curl -X POST "https://api.api-ninjas.com/v1/removebackground?format=webp" -H "X-Api-Key: YOUR_API_KEY" -H "Accept: image/webp" -F "image=@photo.jpg" --output photo-no-bg.webp. Without theAcceptheader the response is JSON with the image base64-encoded inimage. A photo that is already online can be passed asimage_urlinstead.Which output formats can I get?
png(the default) andwebpkeep the transparent background; WebP files are several times smaller.jpghas no transparency, so the background is filled withbg_color, or white. Setbg_color(e.g.ffffff) with any format to put the subject on a solid color,crop=trueto trim the result to the subject, andoutput=maskfor a grayscale mask instead of the cut-out.Does it work on hair, fur and products?
Yes. It cuts out people, products, animals, cars and other objects, and keeps fine detail such as hair and fur as semi-transparent edges. The old background's color is removed from those edges, so the cut-out looks natural on a new background. Results keep the photo's full resolution, up to 25 megapixels.How much of my plan does background removal use?
Each image counts as 1 API call. Plans also include a monthly number of background removals: Free 30, Developer 5,000, Business 20,000 and Professional 50,000. The count resets on the 1st of each month (UTC), requests that fail are not counted, and your dashboard shows how many you've used this month (Professional and Enterprise plans can also read it from the Analytics API). See pricing.Can I remove backgrounds on the Free plan?
Yes: the Free plan includes 30 background removals a month, as low-resolution previews of up to 0.25 megapixels (for example 612 × 408), marked withpreview: true. Paid plans return the full resolution. See pricing.
Explore API integration use cases for recommended APIs and workflow examples.