API reference/POST /remove
Remove background
Upload an image and get back a transparent PNG or WebP. Edges are cleaned via closed-form foreground matting: no halos, no fringing.
POSThttps://useknockout--api.modal.run/remove
Parameters
Send as multipart/form-data unless noted otherwise.
FieldTypeDefaultDescription
filerequiredfile–Image to process. JPG, PNG, WebP, HEIC. Up to 10 MB and 4096×4096.
formatstringpngOutput format: png (with alpha) or webp.
qualityint 1-10092JPEG/WebP quality. Ignored for PNG.
mattingstringclosed-formEdge cleanup algorithm. Options: closed-form, none.
max_dimint–Clamp the longest output edge to N pixels (downscale only). Aspect preserved.
widthint–Resize output to an exact width in pixels. Use with height, or alone to scale by aspect.
heightint–Resize output to an exact height in pixels.
despillbooleanfalseRemove colored edge spill (green/blue fringing) bled onto the subject from the old background. Knockout Plus only.
watermarkstring–URL of a watermark image (PNG with alpha) to overlay on the output. Knockout Plus only.
watermark_opacityfloat 0-11.0Watermark opacity. Only applies when watermark is set. Knockout Plus only.
presetstring–Apply a saved preset by id (see /presets). Explicit params override the preset's stored values.
Request
curl -X POST "https://useknockout--api.modal.run/remove" \
-H "Authorization: Bearer $TOKEN" \
-F "file=@cat.jpg" \
-F "format=png" \
-o out.pngResponse
HTTP/1.1 200 OK
content-type: image/png
content-length: 254312
x-knockout-latency: 184
x-knockout-model: BiRefNet
x-ratelimit-limit: 60
x-ratelimit-remaining: 59Errors
FieldTypeDefaultDescription
401unauthorized–Missing or invalid token.
402payment_required–Free tier exhausted. Add a card to continue.
413payload_too_large–Image exceeds 10 MB or 4096×4096.
422no_subject_detected–Foreground could not be isolated from background.
429rate_limit_exceeded–Slow down. Retry-After header tells you when.
500internal_error–Something broke on our side. Include request_id when reporting.
Every error response also includes a
request_id in the JSON body. Quote it when reporting issues.Notes
- Send all params as multipart form fields (-F), not query-string params, same as /replace-bg and /studio-shot. Affects format, quality, max_dim, width, height, despill, watermark, watermark_opacity, and preset.
- Transparent output, so format is png or webp only; jpg can't carry alpha. Use /studio-shot or /replace-bg for a jpg.
- The model runs on a Modal L4 GPU. Warm calls are ~200ms. First request after a cold container is 60–90s while weights load. Modal autoscales to zero, that's the trade-off for $0 idle cost. Pin `keep_warm=1` to eliminate cold starts.
- Images are processed in-memory and discarded after the response is returned.
- EXIF orientation is auto-corrected on every endpoint. Phone photos come back upright, not sideways.
- For batch workflows, fan out with Promise.all in Node or asyncio.gather in Python, or use /remove-batch.