Skip to main content

Background Removal and Create mask Endpoint

Overview

This endpoint removes background from image and create mask.

removebg-createmask endpoint result

Request

--request POST 'https://modelslab.com/api/v6/image_editing/removebg_mask' \

Make a POST request to https://modelslab.com/api/v6/image_editing/removebg_mask endpoint and pass the required parameters as a request body to the endpoint.

Body Attributes

ParameterDescriptionValues
keyYour API Key used for request authorizationstring
imageLink or valid base64 data following the format data:image/jpeg;base64,{your_base64_string} for the image you want your generations to resembleURL, base64 string
alpha_mattingWhether to perform alpha matting. It accepts true or false. Default is falseboolean
post_process_maskWhether to post-process the mask image. It accepts true or false. Default is falseboolean
only_maskWhether to return only the mask image. It accepts true or false. Default is falseboolean
seedThe seed used to reproduce results. The same seed will give you the same image again. Pass null for a random number.integral value
alpha_matting_foreground_thresholdThe threshold for alpha matting foreground. The default is 240integer (0 to 240)
alpha_matting_background_thresholdThe threshold for alpha matting background. The default is 20integer (0 to 20)
alpha_matting_erode_sizeThe erode size for alpha matting. The default is 5integer (0 to 5)
webhookProvide a URL to receive a POST API call once the image generation is completeURL
track_idThis ID is returned in the response to the webhook API call and will be used to identify the webhook request.integral value

Example

Body

Body
{
"key":"",
"seed":12345,
"image":"https://pub-3626123a908346a7a8be8d9295f44e26.r2.dev/livewire-tmp/2ILk0g1tgpk7wFFlc72hyAtdmHjxAj-metaZjNkNzVjMWQtMTI1OS00NDA4LTg0YmQtNzA0NTVmMTljZjcwLTAucG5n-.png",
"post_process_mask": false,
"only_mask": false,
"alpha_matting":false,
"webhook": null,
"track_id": null
}

Request

var myHeaders = new Headers();
myHeaders.append("Content-Type", "application/json");

var raw = JSON.stringify({
"key":"",
"seed":12345,
"image":"https://pub-3626123a908346a7a8be8d9295f44e26.r2.dev/livewire-tmp/2ILk0g1tgpk7wFFlc72hyAtdmHjxAj-metaZjNkNzVjMWQtMTI1OS00NDA4LTg0YmQtNzA0NTVmMTljZjcwLTAucG5n-.png",
"post_process_mask": false,
"only_mask": false,
"alpha_matting":false,
"webhook": null,
"track_id": null
});

var requestOptions = {
method: 'POST',
headers: myHeaders,
body: raw,
redirect: 'follow'
};

fetch("https://modelslab.com/api/v6/image_editing/removebg_mask", requestOptions)
.then(response => response.text())
.then(result => console.log(result))
.catch(error => console.log('error', error));

Response

Example Response

{
"status": "success",
"generationTime": 4.713963508605957,
"id": 96708,
"output": [
"https://pub-3626123a908346a7a8be8d9295f44e26.r2.dev/generations/fcc2d175-1272-4ed6-a6b9-02a8f26af08c.png"
],
"proxy_links": [
"https://cdn2.stablediffusionapi.com/generations/fcc2d175-1272-4ed6-a6b9-02a8f26af08c.png"
],
"meta": {
"alpha_matting": "0",
"alpha_matting_background_threshold": 20,
"alpha_matting_erode_size": 5,
"alpha_matting_foreground_threshold": 240,
"base64": "no",
"file_prefix": "fcc2d175-1272-4ed6-a6b9-02a8f26af08c",
"image_url": "https://pub-3626123a908346a7a8be8d9295f44e26.r2.dev/livewire-tmp/2ILk0g1tgpk7wFFlc72hyAtdmHjxAj-metaZjNkNzVjMWQtMTI1OS00NDA4LTg0YmQtNzA0NTVmMTljZjcwLTAucG5n-.png",
"n_samples": 1,
"only_mask": "0",
"outdir": "out",
"post_process_mask": "0",
"seed": 1,
"temp": "no"
}
}