Background Remover
API Documentation
Remove image backgrounds with advanced AI algorithms that preserve small objects, fine details, and edge structures — while cleanly separating the foreground from the background. Choose from multiple processing backends over a simple REST API.
Overview
The Background Remover API removes backgrounds from images using an advanced AI-powered pipeline. Its enhanced object detection algorithm retains small objects (like utensils, jewelry, or fine details) that standard tools miss, then applies final mask cleanup for clean edges. It supports multiple backends — a default advanced AI backend, standard AI removal, and a basic PIL-based approach — so you can pick the engine best suited to your images.
Base URL & Authentication
Base URL
Base URL
https://api.chemhub.com/api/v1
Authentication
Include your API credentials in every request header. The health check endpoint does not require authentication.
Headers
X-API-Key: your_api_key
X-API-Secret: your_secret
Content-Type: application/json
Get API Keys
Follow these steps to obtain your API credentials:
Access Your Profile
Once you log in, click on your profile picture in the top-right corner, then click on "Your profile" from the dropdown menu.
Create API Key
From your profile page, proceed to the "API Keys" section and create a key by filling in a name you prefer.
"Background remover bot" or "Product photo cleaner"
Save Your Credentials
Click on "Create API Key" to generate your credentials, then immediately copy and save both the API Key and Secret.
Your secret key will only be displayed once! Copy it immediately and store it securely. You won't be able to see it again.
Never share your API keys publicly or commit them to version control. Treat them like passwords — regenerate immediately if compromised.
Free tier: 150 requests/day | Pro tier: 1000 requests/day. Check your dashboard for current usage and limits.
Endpoints
GET /img/healthPOST /img/remove-backgroundHealth Check
Health check endpoint to verify the image processing service status and available backends. This endpoint does not require authentication.
Response
Success Response
{
"success": true,
"status": "healthy",
"img_backends": {
"rembg": true,
"pil": true,
"opencv": false,
"bg_remover": true
},
"supported_formats": [".jpg", ".jpeg", ".png", ".webp", ".bmp"],
"max_file_size_mb": 10,
"timestamp": "2026-07-23T12:00:00"
}
Code Examples
Python
import requests
url = "https://api.chemhub.com/api/v1/img/health"
res = requests.get(url)
print(res.json())
cURL
curl -X GET https://api.chemhub.com/api/v1/img/health
JavaScript
fetch('https://api.chemhub.com/api/v1/img/health')
.then(res => res.json())
.then(console.log);
Remove Background
Remove the background from an uploaded image. Upload the file as multipart/form-data.
Form Parameters
| Field | Type | Default | Description |
|---|---|---|---|
file | File | — | Image file (required) — JPG, JPEG, PNG, WebP, or BMP |
backend | string | bg_remover | Processing backend — bg_remover, rembg, pil, opencv |
model | string | u2net | AI model for the rembg backend (currently only u2net is supported) |
format | string | png | Output format — png (transparency supported) |
On success the endpoint returns the processed PNG image bytes directly with Content-Type: image/png and the background made fully transparent. The file is returned as a download named removed_bg_<original_name>.png.
The rembg backend currently only supports the default u2net model. Supplying any other model returns a 400 error.
cURL Example
cURL
curl -X POST "https://api.chemhub.com/api/v1/img/remove-background" \
-H "X-API-Key: your_api_key" \
-H "X-API-Secret: your_secret" \
-F "file=@image.jpg" \
-F "backend=bg_remover" \
--output removed_bg.png
Code Examples
Python
import requests
url = "https://api.chemhub.com/api/v1/img/remove-background"
headers = {
"X-API-Key": "your_api_key",
"X-API-Secret": "your_secret"
}
with open("image.jpg", "rb") as f:
files = {"file": f}
data = {"backend": "bg_remover"}
response = requests.post(url, headers=headers, files=files, data=data)
if response.status_code == 200:
with open("removed_bg.png", "wb") as out:
out.write(response.content)
print("Background removed successfully!")
else:
print(response.json())
JavaScript
const form = new FormData();
form.append('file', fileInput.files[0]);
form.append('backend', 'bg_remover');
fetch('https://api.chemhub.com/api/v1/img/remove-background', {
method: 'POST',
headers: {
'X-API-Key': 'your_api_key',
'X-API-Secret': 'your_secret'
},
body: form
})
.then(async res => {
if (res.ok) {
const blob = await res.blob();
const url = URL.createObjectURL(blob);
console.log('Background removed:', url);
} else {
console.log(await res.json());
}
});
Processing Backends
Select the processing engine that best matches your images using the backend form parameter.
bg_removerdefault
Advanced AI pipeline with enhanced object detection that preserves small objects and fine details while removing the background.
rembg
Standard AI background removal using the u2net model. Simple and reliable for typical photos.
pil
Basic threshold-based removal using PIL image processing. Fast, lightweight, and dependency-free.
opencv
Computer vision based removal. Note: this backend is not yet implemented and returns a 500 error if requested.
Python SDK
Complete Python SDK covering health checks and background removal with all backends.
Complete SDK Class
import requests
import os
BASE_URL = "https://api.chemhub.com/api/v1"
API_KEY = "YOUR_API_KEY"
API_SECRET = "YOUR_API_SECRET"
headers = {
"X-API-Key": API_KEY,
"X-API-Secret": API_SECRET
}
# --- Health Check (no auth required) ---
def check_health():
return requests.get(f"{BASE_URL}/img/health").json()
# --- Remove background ---
def remove_background(image_path, backend="bg_remover", output_dir="."):
with open(image_path, "rb") as image_file:
files = {"file": image_file}
data = {"backend": backend}
response = requests.post(
f"{BASE_URL}/img/remove-background",
headers=headers,
files=files,
data=data
)
if response.status_code == 200:
stem = os.path.splitext(os.path.basename(image_path))[0]
output_path = os.path.join(output_dir, f"removed_bg_{stem}.png")
with open(output_path, "wb") as f:
f.write(response.content)
print(f"Background removed! Saved to: {output_path}")
return output_path
else:
print(f"Error: {response.status_code} - {response.text}")
return None
# --- Test all endpoints ---
if __name__ == "__main__":
image_path = "image1.jpeg"
print("=== BACKGROUND REMOVER API TEST ===")
health = check_health()
print(f"Health: {health.get('status', 'unknown')}")
print(f"Backends: {list(health.get('img_backends', {}).keys())}")
print("\n1. Removing background with default backend:")
remove_background(image_path, backend="bg_remover")
print("\n2. Removing background with rembg backend:")
remove_background(image_path, backend="rembg")
print("\n3. Removing background with pil backend:")
remove_background(image_path, backend="pil")
Errors & Status Codes
Error Response Format
Error Response
{
"success": false,
"error": "Invalid backend",
"message": "Available backends: ['rembg', 'pil', 'opencv', 'bg_remover']"
}
Status Codes
200Success — PNG returned with transparent background400Bad request / invalid parameters / invalid backend / unsupported file format401Invalid or missing API key/secret429Rate limit exceeded500Backend unavailable / processing failed