apyhub
Back

Remove Image Background with Advanced Controls API

What it does

Remove Image Background with Advanced Controls API removes the background from an image and returns the cut-out subject in the format you request. Send an image by public URL or base64, and choose whether you want JSON metadata, PNG, WebP, or JPEG output.

Use crop to trim the result to the subject's bounding box, and padding to keep extra pixels around it when cropping. You can also set quality to best or fast, limit the output with max_size, and place the subject on a transparent background or a solid #RRGGBB color. JPEG output requires an opaque background, while json returns metadata plus a PNG data URI.

The response includes the output format, media_type, width, height, bytes, data_uri, quality, and foreground_ratio. It also returns the subject bbox in the original image when one is found, or null when nothing is detected.

Use it for product photos, profile images, marketplace listings, and any workflow that needs a clean foreground subject without manual editing.

POST
Remove the background
https://api.eu.apyhub.com/callable-labs/new-service-3/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/new-service-3/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

ParameterTypeMandatoryDescription
imageObjectYesImage source. Provide one of image.url or image.base64.
image.urlStringNoPublic http(s) URL of the image (≤ 20 MB). Private and internal addresses are refused.
image.base64StringNoThe image as base64 (a data: URI is fine), ≤ 20 MB decoded.
cropBooleanNoCrop the result to the subject's bounding box. Default: false.
formatENUMNoOutput 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.
paddingIntegerNoPixels kept around the subject when crop is true. Default: 0. Minimum: 0. Maximum: 1000.
qualityENUMNoProcessing quality. Allowed values: best, fast. Default: best.
best prioritizes detail.
fast is suitable for previews.
max_sizeIntegerNoLongest side of the output in pixels. Default: null (original size). Minimum: 64. Maximum: 4096.
backgroundStringNoBackground 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.

ParameterTypeMandatoryDescription
bboxObjectYesSubject bounding box in the original image, or null when nothing was found.
bbox.xIntegerYesX coordinate of the bounding box.
bbox.yIntegerYesY coordinate of the bounding box.
bbox.widthIntegerYesWidth of the bounding box.
bbox.heightIntegerYesHeight of the bounding box.
bytesIntegerYesSize of the output in bytes.
widthIntegerYesOutput width in pixels.
formatStringYesEncoding of data_uri.
heightIntegerYesOutput height in pixels.
qualityENUMYesProcessing quality used in the result. Allowed values: best, fast.
data_uriStringYesdata:<media_type>;base64,…
media_typeStringYesMIME type of the returned data.
foreground_ratioNumberYesShare 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.