API reference/POST /smart-crop
Auto-crop to subject bounds
Tight bounding box around the subject. Optional padding. Useful for thumbnails, e-commerce tiles, and uniform aspect ratios across product shots.
POSThttps://useknockout--api.modal.run/smart-crop
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.
paddingint8Pixels of padding around the detected subject bounds.
aspectstring—Force a specific output aspect ratio. Examples: 1:1, 4:5, 16:9.
formatstringpngOutput format — png (with alpha) or webp.
Request
curl -X POST "https://useknockout--api.modal.run/smart-crop" \
-H "Authorization: Bearer $TOKEN" \
-F "file=@cat.jpg" \
-F "aspect=1:1" -F "padding=16" \
-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
- If aspect is provided, padding is computed to satisfy the ratio. Subject stays centered.
- Pair with /remove first if you want a transparent crop instead of an opaque one.