Remove Background
Remove Background API
To remove the background of your pictures, the remove background API is available at https://clipdrop-api.co/remove-background/v1
.
The request must be an http POST
and its body must be a multipart/form-data
that has one image file:
- a required
image_file
file field with the original image to process.- The original image should be a PNG, a JPG or a WEBP file, with a maximum resolution of 25 megapixels and a max file size of 30 Mb.
- an optional
transparency_handling
text enum field with valid values:- 'return_input_if_non_opaque' (default): returns the input image if the image has an alpha layer with some transparency (not fully opaque). Useful if some of your images may already have their background removed.
- 'discard_alpha_layer': discards the alpha (transparency) layer if the image is RGBa, ie removing all transparency information before removing the background.
In case of success:
the response mime-type will be either
image/png
,image/webp
orimage/jpeg
, and the response image will be an image matching the accept header if provided, a PNG otherwise, with the same dimensions as theimage_file
.the response headers will include a
x-remaining-credits
property to tell you how many credits you have left and ax-credits-consumed
property to tell you how many credits were consumed by your request.
In case of an error:
- the response mime-type is
application/json
, error type is indicated by the response status code and details are in the json body, ie
{ "error": "No api key provided" }
Authentication
Requests are authenticated with an API key. If you need one, please contact us at contact@clipdrop.co.
If your key has leaked, you can revoke it and request a new one in your account page.
Formats
Our API follows the accept header convention.
For example, if you want a webp output rather than a PNG (our default), you can add a accept: image/webp
header to your request and you will receive a response with content-type: image/webp
and a webp binary image.
As of today, the API supports image/png
, image/webp
and image/jpg
accept headers.
Credits
1 successful background removal API call = 1 credit.
Once logged in, you can claim 100 free Clipdrop APIs credits that you can use for development and debugging purposes. Once the 100 images have been consumed, further calls will be rejected.
If you need more credits, you can purchase more credits via the following link.
Quota / Rate limiting
By default, each API key has a limit of 60 requests per minute for the remove background API. Please let us know if you'd like higher values.
Examples
- CURL
- JavaScript
- Python
- Swift
- Kotlin
curl -X POST https://clipdrop-api.co/remove-background/v1 \
-H 'x-api-key: YOUR_API_KEY' \
-F 'image_file=@car.jpg' \
-o result.png
const form = new FormData()
form.append('image_file', photo)
fetch('https://clipdrop-api.co/remove-background/v1', {
method: 'POST',
headers: {
'x-api-key': YOUR_API_KEY,
},
body: form,
})
.then(response => response.arrayBuffer())
.then(buffer => {
// buffer here is a binary representation of the returned image
})
import requests
r = requests.post('https://clipdrop-api.co/remove-background/v1',
files = {
'image_file': ('car.jpg', image_file_object, 'image/jpeg'),
},
headers = { 'x-api-key': 'YOUR_API_KEY'}
)
if (r.ok):
# r.content contains the bytes of the returned image
else:
r.raise_for_status()
import Alamofire;
let imageData = try Data(contentsOf: inputPath)
let headers: HTTPHeaders = [
"x-api-key": "YOUR_API_KEY"
]
AF.upload(
multipartFormData: { multipartFormData in
multipartFormData.append(
imageData,
withName: "image_file",
fileName: "car.jpg",
mimeType: "image/jpeg"
)
},
to: "https://clipdrop-api.co/remove-background/v1",
headers: headers
)
.responseData(queue: .global()) { response in
switch response.result {
case .success: do {
// response.data here is an in memory byte buffer of the returned image
}
case let .failure(error): print(error)
}
// this example uses the OkHttp library
// https://square.github.io/okhttp/
val client = OkHttpClient()
val requestBody =
MultipartBody.Builder()
.setType(MultipartBody.FORM)
.addFormDataPart(
"image_file",
"car.jpg",
File("docs/images/car.jpg").asRequestBody("image/jpeg".toMediaType())
)
.build()
val request =
Request.Builder()
.header("x-api-key", "YOUR_API_KEY")
.url("https://clipdrop-api.co/remove-background/v1")
.post(requestBody)
.build()
client.newCall(request).execute().use { response ->
if (!response.isSuccessful) throw IOException("Unexpected code $response")
// response.body().bytes() here is a byte array of the returned image
}
Responses
- 200
- 400
- 401
- 402
- 403
- 406
- 429
- 500
The result image, e.g.
Request is malformed or incomplete, non exhaustive causes can be:
- Missing image_file in request
- Input image format is not valid
- Image resolution is too big
Missing api key.
Your account has no remaining credits, you can buy more in your account page.
Invalid or revocated api key.
Accept header not acceptable.
Too many requests, blocked by the rate limiter.
You should space out your requests in time or contact us to increase your quota.
This may be a bug on our side.
Please contact us at contact@clipdrop.co so that we can investigate.
Examples of input and outputs
image_file
result
Sample integrations
Support
Any question ? Contact us at contact@clipdrop.co or join the Slack community.