Background Removal API
High quality results, with affordable rates
Designed for cost-effectiveness and high-quality results, delivers superior image cutouts, giving you more value for less.
Example Outputs
Evaluate the quality in various categories.
Pricing Plans
We provide comfortable rates. Go as you pay.
Package | Credits | Price | Price per Credit | Validity |
---|---|---|---|---|
Free trial | 50 | € 0 | € 0.00 | 30 days |
Package XS | 100 | € 10 | € 0.10 | 30 days |
Package S | 500 | € 40 | € 0.08 20% off | 30 days |
Package M | 1,000 | € 70 | € 0.07 30% off | 90 days |
Package L | 5,000 | € 300 | € 0.06 40% off | 180 days |
Package XL | 10,000 | € 500 | € 0.05 50% off | 360 days |
Easy Integration
Our API is easy to integrate into your existing workflows. Here are some examples in various languages.
import requests
def remove_background_from_file(file_path, api_key):
url = "https://api.withoutbg.com/v1.0/image-without-background"
headers = {'X-API-Key': api_key}
files = {'file': open(file_path, 'rb')}
try:
response = requests.post(url, headers=headers, files=files)
if response.status_code == 200:
# To save the output as a file
with open("output-image.png", "wb") as out_file:
out_file.write(response.content)
return "Image saved as output-image.png"
# Alternatively, return the binary content
# return response.content
else:
raise ConnectionError(f"API request failed with status code {response.status_code}: {response.text}")
except requests.RequestException as e:
raise SystemError(f"An error occurred while making the API request: {e}")
finally:
files['file'].close()
# Example usage
api_key = "YOUR_API_KEY"
file_path = "input-image.jpg" # Replace with your image file path
try:
result = remove_background_from_file(file_path, api_key)
print(result)
except Exception as e:
print(f"An error occurred: {e}")
import java.io.*;
import java.net.*;
import javax.net.ssl.HttpsURLConnection;
public class ImageBackgroundRemover {
public static void removeBackgroundFromFile(String filePath, String apiKey) throws IOException {
String url = "https://api.withoutbg.com/v1.0/image-without-background";
String boundary = Long.toHexString(System.currentTimeMillis()); // Unique boundary
URL apiUrl = new URL(url);
HttpsURLConnection connection = (HttpsURLConnection) apiUrl.openConnection();
connection.setDoOutput(true);
connection.setRequestMethod("POST");
connection.setRequestProperty("Content-Type", "multipart/form-data; boundary=" + boundary);
connection.setRequestProperty("X-API-Key", apiKey);
OutputStream output = connection.getOutputStream();
PrintWriter writer = new PrintWriter(new OutputStreamWriter(output, "UTF-8"), true);
// Sending file data
File file = new File(filePath);
writer.append("--" + boundary).append("\r\n");
writer.append("Content-Disposition: form-data; name=\"file\"; filename=\"" + file.getName() + "\"").append("\r\n");
writer.append("Content-Type: " + URLConnection.guessContentTypeFromName(file.getName())).append("\r\n");
writer.append("\r\n").flush();
Files.copy(file.toPath(), output);
output.flush(); // Important before continuing with writer!
writer.append("\r\n").flush(); // CRLF is important! It indicates end of boundary.
// End of multipart/form-data.
writer.append("--" + boundary + "--").append("\r\n").flush();
// Reading the response
int responseCode = connection.getResponseCode();
if (responseCode == HttpsURLConnection.HTTP_OK) {
try (InputStream in = connection.getInputStream();
FileOutputStream fos = new FileOutputStream("output-image.png")) {
byte[] buffer = new byte[4096];
int len;
while ((len = in.read(buffer)) > 0) {
fos.write(buffer, 0, len);
}
System.out.println("Image saved as output-image.png");
}
} else {
System.out.println("API request failed with status code " + responseCode);
}
connection.disconnect();
}
public static void main(String[] args) {
String apiKey = "YOUR_API_KEY";
String filePath = "input-image.jpg"; // Replace with your image file path
try {
removeBackgroundFromFile(filePath, apiKey);
} catch (IOException e) {
e.printStackTrace();
System.out.println("An error occurred: " + e.getMessage());
}
}
}
<?php
function removeBackgroundFromFile($filePath, $apiKey) {
$url = "https://api.withoutbg.com/v1.0/image-without-background";
// Initialize a cURL session
$ch = curl_init($url);
// Set cURL options
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('X-API-Key: ' . $apiKey));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// Add the file to the request
$cFile = curl_file_create($filePath);
$data = array('file' => $cFile);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
// Execute the cURL request and get the response
$response = curl_exec($ch);
$status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if ($status == 200) {
// Save the output as a file
file_put_contents("output-image.png", $response);
return "Image saved as output-image.png";
} else {
// Handle errors
return "API request failed with status code $status: $response";
}
// Close the cURL session
curl_close($ch);
}
// Example usage
$apiKey = "YOUR_API_KEY";
$filePath = "input-image.jpg"; // Replace with your image file path
try {
$result = removeBackgroundFromFile($filePath, $apiKey);
echo $result;
} catch (Exception $e) {
echo "An error occurred: " . $e->getMessage();
}
?>
use reqwest::Client;
use std::fs::File;
use std::io::Write;
use reqwest::multipart;
use tokio;
#[tokio::main]
async fn main() {
let api_key = "YOUR_API_KEY";
let file_path = "input-image.jpg"; // Replace with your image file path
match remove_background_from_file(file_path, api_key).await {
Ok(_) => println!("Image saved as output-image.png"),
Err(e) => eprintln!("An error occurred: {}", e),
}
}
async fn remove_background_from_file(file_path: &str, api_key: &str) -> Result<(), reqwest::Error> {
let url = "https://api.withoutbg.com/v1.0/image-without-background";
let client = Client::new();
let form = multipart::Form::new()
.file("file", file_path)?;
let response = client.post(url)
.header("X-API-Key", api_key)
.multipart(form)
.send()
.await?;
if response.status().is_success() {
let mut file = File::create("output-image.png")?;
let content = response.bytes().await?;
file.write_all(&content)?;
Ok(())
} else {
Err(reqwest::Error::new(reqwest::StatusCode::from_u16(response.status().as_u16()).unwrap(), false))
}
}
const axios = require('axios');
const FormData = require('form-data');
const fs = require('fs');
async function removeBackgroundFromFile(filePath, apiKey) {
const url = "https://api.withoutbg.com/v1.0/image-without-background";
const formData = new FormData();
formData.append('file', fs.createReadStream(filePath));
const headers = {
'X-API-Key': apiKey,
...formData.getHeaders()
};
try {
const response = await axios.post(url, formData, { headers });
if (response.status === 200) {
// To save the output as a file
fs.writeFileSync("output-image.png", response.data);
return "Image saved as output-image.png";
// Alternatively, you can handle the binary content differently
} else {
throw new Error(`API request failed with status code ${response.status}: ${response.statusText}`);
}
} catch (error) {
throw new Error(`An error occurred while making the API request: ${error.message}`);
}
}
// Example usage
const apiKey = "YOUR_API_KEY";
const filePath = "input-image.jpg"; // Replace with your image file path
removeBackgroundFromFile(filePath, apiKey)
.then(result => console.log(result))
.catch(error => console.error(`An error occurred: ${error.message}`));
package main
import (
"bytes"
"fmt"
"io"
"mime/multipart"
"net/http"
"os"
)
func removeBackgroundFromFile(filePath, apiKey string) error {
url := "https://api.withoutbg.com/v1.0/image-without-background"
// Prepare the file to be uploaded
file, err := os.Open(filePath)
if err != nil {
return err
}
defer file.Close()
// Create a buffer to write our multipart form
var buffer bytes.Buffer
writer := multipart.NewWriter(&buffer)
// Create form file
part, err := writer.CreateFormFile("file", filePath)
if err != nil {
return err
}
_, err = io.Copy(part, file)
if err != nil {
return err
}
writer.Close()
// Create and make the request
request, err := http.NewRequest("POST", url, &buffer)
if err != nil {
return err
}
request.Header.Set("Content-Type", writer.FormDataContentType())
request.Header.Set("X-API-Key", apiKey)
client := &http.Client{}
response, err := client.Do(request)
if err != nil {
return err
}
defer response.Body.Close()
// Check the response
if response.StatusCode != http.StatusOK {
return fmt.Errorf("API request failed with status code %d", response.StatusCode)
}
// Save the output as a file
output, err := os.Create("output-image.png")
if err != nil {
return err
}
defer output.Close()
_, err = io.Copy(output, response.Body)
if err != nil {
return err
}
fmt.Println("Image saved as output-image.png")
return nil
}
func main() {
apiKey := "YOUR_API_KEY"
filePath := "input-image.jpg" // Replace with your image file path
err := removeBackgroundFromFile(filePath, apiKey)
if err != nil {
fmt.Printf("An error occurred: %s\n", err)
}
}
curl -X 'POST' \
https://api.withoutbg.com/v1.0/image-without-background \
-H 'X-API-Key: YOUR_API_KEY' \
-F 'file=@input-image.jpg' \
-o output-image.png
using System;
using System.Net.Http;
using System.IO;
using System.Threading.Tasks;
class ImageBackgroundRemover
{
static readonly HttpClient client = new HttpClient();
public static async Task RemoveBackgroundFromFileAsync(string filePath, string apiKey)
{
string url = "https://api.withoutbg.com/v1.0/image-without-background";
try
{
using (var formData = new MultipartFormDataContent())
{
client.DefaultRequestHeaders.Add("X-API-Key", apiKey);
// Add file content to the form data
var fileContent = new ByteArrayContent(File.ReadAllBytes(filePath));
fileContent.Headers.ContentDisposition = new System.Net.Http.Headers.ContentDispositionHeaderValue("form-data")
{
Name = "file",
FileName = Path.GetFileName(filePath)
};
formData.Add(fileContent);
// Make the request
var response = await client.PostAsync(url, formData);
if (response.IsSuccessStatusCode)
{
// Save the output as a file
var outputData = await response.Content.ReadAsByteArrayAsync();
File.WriteAllBytes("output-image.png", outputData);
Console.WriteLine("Image saved as output-image.png");
}
else
{
Console.WriteLine($"API request failed with status code {response.StatusCode}: {await response.Content.ReadAsStringAsync()}");
}
}
}
catch (Exception ex)
{
Console.WriteLine($"An error occurred: {ex.Message}");
}
}
static async Task Main(string[] args)
{
string apiKey = "YOUR_API_KEY";
string filePath = "input-image.jpg"; // Replace with your image file path
await RemoveBackgroundFromFileAsync(filePath, apiKey);
}
}
FAQ
API
You can use any programming language. You can find several examples on the documentation page.
Yes. 7 requests / minute.
Technology
It is a supervised machine learning algorithm, meaning that it is learning from the examples we provide.
Our image background removal model is designed to handle complex backgrounds, including those with gradients or textures. In most cases, our model is able to successfully remove the background while preserving the foreground object. However, for the best results, we recommend using the service with images that have smooth and solid backgrounds, if possible. This can help to ensure that the image background removal is as accurate and seamless as possible and that the final output meets your expectations.
While your service aims to preserve the original quality of the foreground object as much as possible, it is important to note that there may still be some minor loss of detail or resolution in certain cases. If you prefer, you may request only the alpha channel, and process it on your side.
Pricing
Yes. When you sign up, you get 50 free credits.
We provide an endpoint for getting available credits and expiration dates. Every processing costs 1 credit.
When you run out of credits or exceed your monthly credit limit, the API will respond with a 403 Forbidden
status code along with a JSON payload specifying an Insufficient Credit
error. To continue using the service, you can purchase additional credits on your account dashboard.
Privacy
We process your images in memory. We do not store them.
No tracking code on our website. Your browsing habits are not tracked.
Company
Frankfurt, Germany
Privacy by Design
We truly care about your privacy. Here is how: