Remove Background
In order to get access to the Remove Background service, please register at https://app.ximilar.com. In the app pick "Image Tools" on the main dashboard and then Remove Background. This service is available in all pricing plans. A public demo is located at demo.ximilar.com.
This page describes API of Remove Background service for images. With this service you can remove backgrounds from images via AI. The API offers two background removal models - a Fast model that provides quick background removal at a lower cost, and a Precise model that produces higher quality results with better edge detection, though at a slightly higher cost.
This service is great for removing background from product photos as well as photos of generic items and people.
The result images with removed background are stored temporarily for 24 hours
in _output_url_mask
, _output_url_whitebg
, and _output_url
fields of json
records. You can download them and use them for your use case.
Endpoints
This service API has two endpoints running at URLs, each of them suitable for different use cases:
https://api.ximilar.com/removebg/precise/removebg (for high-quality background removal)
https://api.ximilar.com/removebg/fast/removebg (for faster background removal)
Model Types
The Remove Background service offers two different models for background removal:
Precise Model
The Precise model provides high-quality background removal with excellent edge detection. It's ideal for product photos, portraits, and images where detail preservation is crucial.
Endpoint: https://api.ximilar.com/removebg/precise/removebg
Best for: Product photos, portraits, high-resolution images
Fast Model
The Fast model provides quicker background removal at a lower cost. It's suitable for batch processing or when speed is more important than perfect edge detection.
Endpoint: https://api.ximilar.com/removebg/fast/removebg
Best for: Batch processing, lower-resolution images, speed-critical applications
Remove Background Request
Given a list of image records, this method removes backgrounds for each of them. The result images with removed background are stored temporarily for 24h in _output_url_mask
, _output_url_whitebg
, and _output_url
fields of json records.
Required attributes
- Name
records
- Type
- dict
- Description
A list of photos to remove background from, each defined by
_url
or_base64
.
Optional attributes
- Name
binary_mask
- Type
- boolean
- Default
- Default:false
- Description
If true,
_output_url_mask
field with url to .jpg image of binary mask will be included in response
- Name
white_background
- Type
- boolean
- Default
- Default:false
- Description
If true,
_output_url_whitebg
field with url to .jpg image with white background will be included in response
- Name
image_format
- Type
- string
- Default
- Default:auto
- Description
If not specified it will convert
_output_url
to png and_output_url_mask
to jpg. Available options arepng
,jpg
,webp
- Name
image_quality
- Type
- integer
- Default
- Default:85
- Description
Default is 85. Only available when submitting image_format
Returns
HTTP error code 2XX, if the method was OK and other HTTP error code, if the method failed. Body of the response is a JSON object (map) with the following fields:
- Name
status
- Type
- dict
- Description
A JSON map with a status of the method processing. It contains these subfields:
code
- a numeric code of the operation status; it follows the concept of HTTP status codes (2XX, 4XX)text
- a text describing the status codeerror_description
- in case of the processing ended with error (codes 4XX), this field contains a detailed description of the error
- Name
statistics
- Type
- dict
- Description
A map of various statistics about the processing. The only statistic included every time is:
processing time
- time of actual processing of the query [in seconds]
- Name
records
- Type
- dict
- Description
JSON array with the input records, each record enriched by field
_output_url_mask
,_output_url_whitebg
, and_output_url
with url path to the corresponding image
Request
curl --request POST \
--url https://api.ximilar.com/removebg/{model}/removebg \
--header 'Authorization: Token __API_TOKEN__' \
--header 'Content-Type: application/json' \
--data '{
"records": [
{
"_url": "__PATH_TO_IMAGE_URL__",
"binary_mask": true,
"white_background": true
}
]
}'
Response
{
"records": [
{
"_status": {
"code": 200,
"text": "OK",
"request_id": "62e777b4-d7ad-458c-8de7-08fb173cfa2e"
},
"_id": "60802523-4cbe-48ca-8597-b0f79829ddfb",
"_width": 1380,
"_height": 868,
"_output_url": "https://s3-eu-west-1.amazonaws.com/ximilar-tmp-images/removebg/94aaae31-98bc-49f5-a4ed-114f8bf0c590.png",
"_output_url_mask": "https://s3-eu-west-1.amazonaws.com/ximilar-tmp-images/removebg/8e4b5af6-3210-4417-b0ef-14c2384904c8.jpg",
"_output_url_whitebg": "https://s3-eu-west-1.amazonaws.com/ximilar-tmp-images/removebg/52598d95-552b-4450-b4a5-6ab752b24f09.jpg"
}
],
"status": {
"code": 200,
"text": "OK",
"request_id": "62e777b4-d7ad-458c-8de7-08fb173cfa2e",
"proc_id": "43b577c7-d392-4bc8-b1cf-cae92b196691"
},
"statistics": {
"processing time": 1.4223403930664062
}
}
Output Formats
The Remove Background service provides several output formats for each processed image:
- Name
_output_url
- Type
- string
- Description
URL to the image with transparent background (PNG format)
- Name
_output_url_mask
- Type
- string
- Description
URL to the binary mask image (JPG format) - only included if binary_mask=true
- Name
_output_url_whitebg
- Type
- string
- Description
URL to the image with white background (JPG format) - only included if white_background=true
All output URLs are valid for 24 hours. After that, you'll need to process the image again to get new URLs.