Background Removal

This page describes API of Background Removal service. With this solution, you can remove backgrounds from images in bulk with AI. It offers two background removal models: the Precise model produces high-quality output with improved edge detection, which comes at a slightly higher cost, while the Fast model delivers quick results at a lower cost.

Models & Endpoints

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


POST/removebg/{model}/removebg

Background Removal Request

Quickstart

Given a list of image records, this method removes backgrounds for each of them.

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 instead of _output_url.

  • 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 are png, jpg, and webp.

  • Name
    image_quality
    Type
    integer
    Default
    Default:85
    Max
    Maximum:100
    Description

    Default is 85. Max is 100. Only available when submitting image_format. The higher the value, the more conservative will the JPEG/PNG encoder be when discarding image information. This results in an image that is visually very close to the original.

Returns

HTTP error code 2XX, if the method was OK, and other HTTP error code, if the method failed. The response body 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 code
    • error_description – in case 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

POST
/removebg/{model}/removebg
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 Background Removal service can provide 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.

Was this page helpful?