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.
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
- Create a job:
POST /v1/image/remove-backgroundwith the image (multipartfile, or JSONinput_url). The answer is immediate:202 Acceptedwith a Job, not the image. - Wait: poll
GET /v1/jobs/{id}untilstatusissucceeded(orfailed,canceled), or pass awebhook_urland we POST a signedjob.succeededevent when it is done. - Download:
GET /v1/jobs/{id}/output?name=image(orname=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
donewebhook_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.pngFor 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 | ZilAPI |
|---|---|
| X-Api-Key header | Authorization: Bearer $ZILAPI_KEY |
| image_file | Multipart field file (up to 50 MB) |
| image_url | JSON field input_url (https) |
| image_file_b64 | No equivalent: decode the base64 and send the bytes as multipart file |
| size | Not an API parameter. The output is always the input's full upright size (up to 50 MP); resize on your side |
| type, type_level | Not API parameters. The model finds the subject itself |
| format | Not an API parameter. Outputs are always PNG; convert on your side (for example to JPEG over a background colour) |
| channels=rgba / channels=alpha | Download ?name=image (RGBA cut-out) or ?name=mask (8-bit greyscale mask). Both come with every job, for one price |
| crop, crop_margin | Not API parameters. Crop to the subject on your side |
| scale, position, roi | Not API parameters. Place or limit the subject on your side |
| bg_color, bg_image_url, bg_image_file | Not API parameters. Composite the cut-out over a colour or picture on your side |
| add_shadow | Not available |
| Topic | On ZilAPI |
|---|---|
| Response | 202 with a Job (JSON), then a download URL. Results are kept for 7 days. |
| Formats in | PNG, JPEG and WebP; no HEIC or animated images |
| Errors | application/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 ids | Optional 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.
# 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_jobswithRetry-After, and the sameIdempotency-Keymakes 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.