BackgroundCut API

Auto remove background from your images via API


$ curl -H 'Authorization: Token YOUR_API_KEY'
       -F 'file=@/your/image/file.jpg'
       -f https://backgroundcut.co/api/v1/cut/
  

Sample Code

Remove background from image file

$ curl -H 'Authorization: Token YOUR_API_KEY'           \
        -F 'file=@/your/image/file.jpg'                 \
        -f https://backgroundcut.co/api/v1/cut/ 
import requests

URL = "https://backgroundcut.co/api/v1/cut/"
PATH = "YOUR_IMAGE_PATH"

image_file = {'file': open(PATH, 'rb')}
headers = {'Authorization': 'Token YOUR_API_KEY'}
response = requests.post(URL, files=image_file, headers=headers)

print(response.json())


// use Guzzle
// https://docs.guzzlephp.org/en/stable/

post("https://backgroundcut.co/api/v1/cut/", [
    'multipart' => [
        [
            'name' => 'file',
            'contents' => fopen('SOURCE_IMAGE_FILE_PATH', 'r')
        ]
    ],
    'headers' => [
        'Authorization' => 'Token YOUR_API_KEY'
    ]
]);

$res_body = $res->getBody()->getContents();
echo $res_body;
?>


                                
const axios = require('axios');
const fs = require('fs');
const FormData = require('form-data');

const imagePath = 'YOUR_IMAGE_PATH'

const settings = {
    "endpointPath": "https://backgroundcut.co/api/v1/cut/",
    "Authorization": "Token YOUR_API_KEY"
}

function endpointHeader(apiKey, formdata){
    return {
        headers: {
            'Content-Type':'multipart/form-data; boundary=' + formdata.getBoundary(),
            'Authorization': 'Token YOUR_API_KEY'
        }
    }
}

const formdata = new FormData;
formdata.append('file', fs.createReadStream(imagePath));

axios.post(
    settings.endpointPath, formdata, endpointHeader(settings.apiKey, formdata)
)
.then(response => console.log(response.data))
.catch(errors => console.log(errors.response.data));
$ curl -H 'Authorization: Token YOUR_API_KEY'  \
        -F 'file_url=https://www.example.com/example.jpg'  \
        -f https://backgroundcut.co/api/v1/cut/ 
import requests

URL = "https://backgroundcut.co/api/v1/cut/"

data={
    'file_url': 'https://www.example.com/example.jpg',
}

headers = {'Authorization': 'Token YOUR_API_KEY'}
response = requests.post(URL, data=data, headers=headers)

print(response.json())

// use Guzzle
// https://docs.guzzlephp.org/en/stable/

post("https://slazzer.com/api/v1/remove_image_background", [
'multipart' => [
[
    'name' => 'source_image_file',
    'contents' => fopen('SOURCE_IMAGE_FILE_PATH', 'r')
]
],
'headers' => [
'API-KEY' => 'YOUR_API_KEY'
]
]);

$res_body = $res->getBody()->getContents();
echo $res_body;
?>

const axios = require('axios');
const fs = require('fs');
const FormData = require('form-data');

const imagePath = 'YOUR_IMAGE_PATH'

const settings = {
"endpointPath": "https://slazzer.com/api/v1/remove_image_background",
"apiKey": "YOUR_API_KEY"
}

function endpointHeader(apiKey, formdata){
return {
headers: {
    'Content-Type':'multipart/form-data; boundary=' + formdata.getBoundary(),
    'API-KEY': apiKey
}
}
}

const formdata = new FormData;
formdata.append('source_image_file', fs.createReadStream(imagePath));

axios.post(
settings.endpointPath, formdata, endpointHeader(settings.apiKey, formdata)
)
.then(response => console.log(response.data))
.catch(errors => console.log(errors.response.data));

Output Formats

Output Image is provided in 'PNG' format via URL:

Format Resolution
PNG Up to 12 Megapixels
JPG Up to 12 Megapixels

API Reference

  • API Endpointhttps://backgroundcut.co/api/v1/cut/
  • MethodPOST
  • Request Bodymultipart/form-data
Authorization
  • Authorization (string)Token YOUR_API_KEY
Parameters
  • fileSource image file. Supports only PNG, JPG, JPEG
  • file_urlSource image URL. Support only PNG, JPG, JPEG
  • max_resolutionMaximum output resolution (specified in pixels). Upto 12000000, i.e 12MP. For eg, 4000000 outputs image of maximum resolution of 4MP.
  • quality'High', 'Medium'(default), 'Low'. 'High' quality takes the most time while 'Low' takes the least time to process.
Response
  • Code : 200Successfully removed image background
  • Code: 400Error: Invalid parameters or unable to process input image file (No credit deducted)
  • Code: 401Error: API-KEY missing or invalid API-KEY (No credit deducted)
  • Code: 402Error: No credits remaining (No credit deducted)
  • Code: 429Error: API rate limit crossed (No credit deducted)
API Rate Limit
  • During Beta, API is rate limited to a maximum of 20 request/minute. Much higher rate limits are coming soon.