Skip to content
Guides

Migrating from remove.bg

If you're coming from remove.bg's API, this page maps what you have to ZilAPI. The main difference: ZilAPI is asynchronous. You create a job, wait for it (webhook or polling), then download the result. It usually takes under 3 seconds per image, and a small wrapper makes it feel like one call.

Before you start: create an API key in ZILAPI_KEY (dashboard; a free test key returns a sample result). Keys go in Authorization: Bearer …, not in an X-Api-Key header. Keep the key on your server; never put it in a browser or app.

The asynchronous flow

  1. Create a job: POST /v1/image/remove-background with the image (multipart file, or JSON input_url). The answer is immediate: 202 Accepted with a Job, not the image.
  2. Wait: poll GET /v1/jobs/{id} until status is succeeded (or failed, canceled), or pass a webhook_url and we POST a signed job.succeeded event when it is done.
  3. Download: GET /v1/jobs/{id}/output?name=image (or name=mask) returns a signed URL, valid for up to 1 hour. Fetch the PNG from it.
curl -s https://api.zilapi.com/v1/image/remove-background \
  -H "Authorization: Bearer $ZILAPI_KEY" \
  -H "Idempotency-Key: $(uuidgen)" \
  -F "file=@product.jpg;type=image/jpeg" \
  > job.json

JOB_ID=$(jq -r .id job.json)   # job_…, status "waiting_for_file" or "queued"
while :; do
  STATUS=$(curl -s https://api.zilapi.com/v1/jobs/$JOB_ID -H "Authorization: Bearer $ZILAPI_KEY" | jq -r .status)
  case "$STATUS" in waiting_for_file|queued|processing) sleep 1 ;; *) break ;; esac
done
echo "$STATUS"   # succeeded (or failed, canceled)
for NAME in image mask; do
  curl -s "https://api.zilapi.com/v1/jobs/$JOB_ID/output?name=$NAME" -H "Authorization: Bearer $ZILAPI_KEY" > output.json
  curl -s -o "$(jq -r .filename output.json)" "$(jq -r .url output.json)"   # product-cutout.png, product-mask.png
done
No polling? Add a webhook_url to the create call and handle the job.succeeded event instead of step 2. See Webhooks for verifying the signature.

Make it feel like one call

If your code expects one function that takes an image and returns the result, wrap the three steps. These wrappers create the job with an Idempotency-Key, retry a busy answer (429) or a server error with the same key (so a retry never makes a second job or a second charge), poll every second, and return the cut-out's PNG bytes.

# remove_background IMAGE OUT.png: create, wait, download the cut-out (bash + curl + jq)
remove_background() {
  local key job code id status out
  key=$(uuidgen)   # one key per image: a retry never creates a second job
  job=$(mktemp)
  for attempt in 1 2 3 4 5; do   # busy (429) or a server error: wait and retry with the same key
    code=$(curl -s -o "$job" -w '%{http_code}' https://api.zilapi.com/v1/image/remove-background \
      -H "Authorization: Bearer $ZILAPI_KEY" -H "Idempotency-Key: $key" -F "file=@$1")
    case "$code" in 429|5??|000) sleep 5 ;; *) break ;; esac
  done
  [ "$code" = 202 ] || { cat "$job" >&2; rm -f "$job"; return 1; }
  id=$(jq -r .id "$job"); status=$(jq -r .status "$job"); rm -f "$job"
  while [ "$status" = waiting_for_file ] || [ "$status" = queued ] || [ "$status" = processing ]; do
    sleep 1
    status=$(curl -s https://api.zilapi.com/v1/jobs/$id -H "Authorization: Bearer $ZILAPI_KEY" | jq -r .status)
  done
  [ "$status" = succeeded ] || { echo "job $id $status" >&2; return 1; }
  out=$(curl -s "https://api.zilapi.com/v1/jobs/$id/output?name=image" -H "Authorization: Bearer $ZILAPI_KEY")
  curl -s --fail -o "$2" "$(jq -r .url <<<"$out")"
}

remove_background product.jpg product-cutout.png

For many images, call the wrapper from a few workers at once. ZilAPI runs up to 3 of your background removal jobs at the same time and queues the rest, so you do not need to slow down to stay under a concurrency limit (see throughput).

Parameter mapping

remove.bg request parameters and what to do with each on ZilAPI. Only the inputs map to API fields. These are not ZilAPI API parameters: bg_color, bg_image_url, crop, crop_margin, size, scale, position, roi, format and type. ZilAPI always returns the full-size cut-out plus its mask; do the rest on your side (see Pillow).

remove.bg request → ZilAPI
remove.bgZilAPI
X-Api-Key headerAuthorization: Bearer $ZILAPI_KEY
image_fileMultipart field file (up to 50 MB)
image_urlJSON field input_url (https)
image_file_b64No equivalent: decode the base64 and send the bytes as multipart file
sizeNot an API parameter. The output is always the input's full upright size (up to 50 MP); resize on your side
type, type_levelNot API parameters. The model finds the subject itself
formatNot an API parameter. Outputs are always PNG; convert on your side (for example to JPEG over a background colour)
channels=rgba / channels=alphaDownload ?name=image (RGBA cut-out) or ?name=mask (8-bit greyscale mask). Both come with every job, for one price
crop, crop_marginNot API parameters. Crop to the subject on your side
scale, position, roiNot API parameters. Place or limit the subject on your side
bg_color, bg_image_url, bg_image_fileNot API parameters. Composite the cut-out over a colour or picture on your side
add_shadowNot available
Other differences
TopicOn ZilAPI
Response202 with a Job (JSON), then a download URL. Results are kept for 7 days.
Formats inPNG, JPEG and WebP; no HEIC or animated images
Errorsapplication/problem+json with a stable code (for example invalid_image, image_too_large, file_too_large, rate_limited). See Errors.
What a job cost$0.01 / image. Each job carries a receipt and cost; failed jobs are never charged
Your own idsOptional end_user on each job, to filter GET /v1/jobs per customer

Background colours and crops with Pillow

The cut-out is a PNG with an alpha channel, so colours, background pictures, crops and smaller copies take a few lines of Pillow. This continues from the Python wrapper above.

Client-side Pillow on the RGBA cut-out
# pip install Pillow requests
from io import BytesIO
from PIL import Image

cutout = Image.open(BytesIO(remove_background("product.jpg"))).convert("RGBA")

# A solid background colour (what bg_color did): put the cut-out on a filled canvas.
white = Image.new("RGBA", cutout.size, "#ffffff")
white.alpha_composite(cutout)
white.convert("RGB").save("product-white.jpg", quality=92)

# A background picture (what bg_image_url did): scale it to the cut-out's size first.
scene = Image.open("studio.jpg").convert("RGBA").resize(cutout.size)
scene.alpha_composite(cutout)
scene.convert("RGB").save("product-studio.jpg", quality=92)

# Crop to the subject (what crop did), with a margin in pixels (what crop_margin did).
alpha = cutout.getchannel("A").point(lambda a: 255 if a > 8 else 0)  # ignore near-invisible edge pixels
box = alpha.getbbox()  # None when nothing is left: the whole image was background
if box:
    margin = 20
    left, top, right, bottom = box
    box = (max(left - margin, 0), max(top - margin, 0), min(right + margin, cutout.width), min(bottom + margin, cutout.height))
    cutout.crop(box).save("product-cropped.png")

# A smaller copy (what size=preview did): keep the aspect ratio.
small = cutout.copy()
small.thumbnail((625, 400))
small.save("product-preview.png")

Limits and throughput

  • Usually under 3 seconds per image.
  • The 120 job creates per minute per API key apply to image jobs too (the shared create bucket, see Rate limits).
  • Up to 3 background removal jobs run in parallel per account. More are queued and run as slots free up, within the 24-hour job lifetime: they do not fail because they waited. Send a big batch at your own pace and collect results by webhook or polling.
  • Your account's limit on live jobs at once still applies: 10 jobs before your first top-up; after it, 500 image jobs, counted separately from your audio jobs. Over it, a create answers 429 too_many_active_jobs with Retry-After, and the same Idempotency-Key makes the retry safe. See account limits.
  • Inputs: PNG, JPEG and WebP up to 50 MB, 10,000 px per side and 50 megapixels (WebP, and progressive JPEGs saved without colour subsampling (4:4:4), in CMYK or with unusual colour sampling, up to 20 megapixels). Images and audio are never used for training without your consent.

Everything else about the task (request fields, outputs, errors) is on Background Removal.