Background Removal
Removes the background from an image, returning the cutout in the requested encoding.#
/lmkit/v1/image-background-removalTwo lanes, reported in the response's 'mode'. The exact lane estimates the background color from the image border and flood-fills every border-connected pixel within the tolerance - the classic product-shot / logo / scan cutout, no AI model involved. When the border is not uniform enough (a photographic background), the segmentation lane runs the configured image-segmentation model and cuts out the salient subject instead. 'mode' selects the policy: 'auto' (default) tries exact-first-then-model; 'uniform_color' and 'segmentation' force one lane. The cutout is always produced as a 32bpp RGBA bitmap; 'output_format' decides the bytes - 'png' (default) and 'webp' keep the alpha, 'jpeg' is flattened over opaque white ('output_quality' drives the lossy encoders). When no requested lane can isolate a background the request is refused with 422 and error 'no_uniform_background' instead of guessing. If processing exceeds the configured timeout, returns 202 Accepted with a job_id. Poll GET /lmkit/v1/jobs/ for status and results.
Request body
application/json ·
| Property | Type | Description |
|---|---|---|
inputrequired | string | The input image. When input_format is 'Base64EncodedFile', provide a base64-encoded image payload. When 'FileIdentifier', provide the file ID previously returned by the lmkit/v1/files/upload endpoint. |
input_format | How the input is provided. Accepted values: 'Base64EncodedFile' or 'FileIdentifier'. Defaults to 'Base64EncodedFile'. | |
mode | Which lane to take. 'auto' (default) tries the exact uniform-color flood fill first and falls back to the segmentation model on a photographic background; 'uniform_color' forces the exact lane; 'segmentation' forces the model lane. | |
model | string | Optional segmentation model identifier. Defaults to the server's configured image-segmentation model. Ignored when 'mode' is 'uniform_color'. |
output_format | Encoding of the returned cutout. 'png' (default, lossless) and 'webp' (lossy) keep the alpha channel; 'jpeg' cannot hold transparency and is flattened over opaque white. | |
output_quality | object (int32) | Quality (1-100) for the lossy encodings ('webp', 'jpeg'); ignored for 'png'. Default: 80. |
tolerance | object (int32) | Uniform lane: per-channel distance (0-255) a pixel may sit from the detected background color and still be removed. Default: 24. |
min_accuracy | object (float) | Uniform lane: minimum fraction (0-1) of border pixels that must agree on one background color. Below the bar the request falls back to segmentation ('auto'), or is refused with 422 'no_uniform_background' ('uniform_color'). Default: 0.85. |
Responses
| Status | Type | Description |
|---|---|---|
| 200 | OK | |
| 202 | Accepted | |
| 400 | Bad Request | |
| 422 | Unprocessable Entity | |
| 500 | application/json | Internal Server Error |
curl -X POST "$LMKIT_ONE_URL/lmkit/v1/image-background-removal" \
-H "Authorization: Bearer $LMKIT_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"input": "",
"input_format": "Base64EncodedFile",
"mode": "auto",
"model": "",
"output_format": "png"
}'