BackgroundCut API

Auto remove background from your images via API


$ curl -H 'Authorization: Token YOUR_API_KEY'
       -F '[email protected]/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 '[email protected]/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));

Output Formats

You can request one of three formats via the format parameter:

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. Support only PNG, JPG, JPEG
  • formatOutput image format. Default value 'png'. Otherwise 'jpg' for JPG format and 'png' for PNG format. 'png' format support alpha transparency.
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.