apyhub
Back
▣ MEDIA KIT

Remove Image Background with Advanced Controls API

What it does

The Background Removal API removes the background from an image and returns the cut-out subject. Send the image in image, as a public URL or base64 data, and get back a transparent PNG, a WebP, a JPEG or JSON metadata.

Set format to json (default), png, webp or jpeg. JSON returns a PNG data URI with the metadata. Set background to transparent (default) or a solid #RRGGBB color. JPEG needs a solid color because it has no transparency. Set crop to true to trim the result to the subject, and add padding (0 to 1000 pixels) to keep space around it. Choose quality as best (default) or fast, and use max_size to limit the output size.

The response includes the format, media_type, width, height, bytes, quality and foreground_ratio, the share of the image covered by the subject. It also returns the subject bbox in the original image, or null when no subject is found.

Teams use the Background Removal API to remove the background from product photos and make profile pictures on a plain color. Online stores use it to prepare listing images and crop catalog shots to the subject.

For a grayscale mask of the subject instead of the cutout, use the Generate Image Foreground Mask API. To read text in the image, use the Image & PDF OCR to Markdown API.

POST
Remove the background
https://api.eu.apyhub.com/callable-labs/background-removal/v1/background/remove

QUICKSTART

GUIDE

Quickstart

Remove the background from an image URL and return the result as JSON metadata.

curl -X POST "https://api.eu.apyhub.com/callable-labs/background-removal/v1/background/remove" \
  -H "apy-token: $APY_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "image": {
      "url": "https://assets.apyhub.com/samples/cat.jpg"
    }
  }'

What you'll get back

Returns a JSON object with format, media_type, width, height, bytes, data_uri, bbox, foreground_ratio, and quality.

  • format (string): encoding of data_uri
  • media_type (string): the output media type
  • width / height (integer): output dimensions in pixels
  • bytes (integer): output size in bytes
  • data_uri (string): a data:<media_type>;base64,… payload
  • bbox (object or null): subject bounding box in the original image
  • foreground_ratio (number): share of the original image covered by the subject
  • quality (string): best or fast
{
  "format": "json",
  "media_type": "image/png",
  "width": 1200,
  "height": 900,
  "bytes": 123456,
  "data_uri": "data:image/png;base64,...",
  "bbox": { "x": 120, "y": 80, "width": 900, "height": 700 },
  "foreground_ratio": 0.42,
  "quality": "best"
}
TRY ITLIVE · 800 ATOMS
Loading your default key…
The full key is used to call the gateway and stays in this tab — never sent to orbit or saved.
RemoveRequest*
Image source. Provide one of `image.url` or `image.base64`.
Image URL*
Public http(s) URL of the image (≤ 20 MB). Private and internal addresses are refused.
Crop the result to the subject's bounding box. Default: `false`.
Output encoding. Allowed values: `json`, `png`, `webp`, `jpeg`. Default: `json`. `json` returns metadata plus a PNG data URI. `png` and `webp` return the image bytes. `jpeg` needs an opaque `background`.
Pixels kept around the subject when `crop` is true. Default: `0`. Minimum: `0`. Maximum: `1000`.

About this endpoint

What it does

Removes the background from an input image and returns result metadata plus the processed image payload. The request accepts either a public image URL or base64-encoded image data, along with optional output and cropping settings.

Request Body

ParameterTypeDescription
imageObjectImage source. Provide one of image.url or image.base64.
image.urlStringPublic http(s) URL of the image (≤ 20 MB). Private and internal addresses are refused.
image.base64StringThe image as base64 (a data: URI is fine), ≤ 20 MB decoded.
cropBooleanCrop the result to the subject's bounding box. Default: false.
formatENUMOutput encoding. Allowed values: json, png, webp, jpeg. Default: json.
json returns metadata plus a PNG data URI.
png and webp return the image bytes.
jpeg needs an opaque background.
paddingIntegerPixels kept around the subject when crop is true. Default: 0. Minimum: 0. Maximum: 1000.
qualityENUMProcessing quality. Allowed values: best, fast. Default: best.
best prioritizes detail.
fast is suitable for previews.
max_sizeIntegerLongest side of the output in pixels. Default: null (original size). Minimum: 64. Maximum: 4096.
backgroundStringBackground color to place the subject on. Default: transparent.
Allowed values: transparent or a hex color in #RRGGBB format.

Response

Returns a JSON object with format, media_type, width, height, bytes, data_uri, bbox, foreground_ratio, and quality fields. bbox is either an object with x, y, width, and height, or null; the other fields describe the generated output and its encoding.

ParameterTypeDescription
bboxObjectSubject bounding box in the original image, or null when nothing was found.
bbox.xIntegerX coordinate of the bounding box.
bbox.yIntegerY coordinate of the bounding box.
bbox.widthIntegerWidth of the bounding box.
bbox.heightIntegerHeight of the bounding box.
bytesIntegerSize of the output in bytes.
widthIntegerOutput width in pixels.
formatStringEncoding of data_uri.
heightIntegerOutput height in pixels.
qualityENUMProcessing quality used in the result. Allowed values: best, fast.
data_uriStringdata:<media_type>;base64,…
media_typeStringMIME type of the returned data.
foreground_ratioNumberShare of the original image covered by the subject, from 0 to 1.
▣ COMMON ERRORS

Errors any endpoint can return

400bad_request

Required parameter missing or malformed body.

401unauthorized

API key missing, revoked, or not authorized for this service.

429rate_limited

Your plan's per-second rate exceeded. Retry with exponential backoff.

503upstream_busy

Backend temporarily unavailable. Try again in a few seconds.