API Documentation

Everything you need to integrate ClearBG AI background removal into your product.

Overview

The ClearBG AI API provides a simple, powerful way to remove backgrounds from images. Our RESTful interface accepts an image file and returns a high-quality PNG with a transparent background. It's designed for scalability, ease of use, and seamless integration into any workflow.

The basic flow is: Send Image → AI Processing → Receive PNG.

Authentication

Authenticate your API requests by including your secret API key in the X-API-Key header. You can manage your API keys in your account dashboard.

curl https://api.clearbg.ai/v1/removebg \
  -H "X-API-Key: YOUR_API_KEY"

Single Image Processing

To process a single image, make a POST request to the /removebg endpoint.

Request Body (form-data)

  • image (file): The image file to process (e.g., JPG, PNG, WEBP).
  • size (string, optional): Max output resolution, e.g., '1080p', '4k'. Defaults to original.
  • format (string, optional): 'png' (default) or 'jpg'.
  • bg_color (string, optional): Hex code for a solid background color, e.g., '#FFFFFF'.
curl -X POST https://api.clearbg.ai/v1/removebg \
  -H "X-API-Key: YOUR_API_KEY" \
  -F "image=@/path/to/your/image.jpg" \
  -o result.png

Bulk Processing

Process up to 50 images in a single request via the /bulk endpoint. This is an asynchronous endpoint that returns a job ID.

{
  "job_id": "job_12345abcde",
  "status": "processing",
  "image_count": 42
}

Error Codes

The API uses conventional HTTP status codes to indicate the success or failure of a request.

  • 400 - Bad Request (e.g., invalid image format).
  • 401 - Unauthorized (invalid or missing API key).
  • 429 - Too Many Requests (rate limit exceeded).
  • 500 - Internal Server Error (something went wrong on our end).

SDK & Examples

While official SDKs are under development, you can easily integrate with any language using a standard HTTP client.

JavaScript (Node.js)

import fetch from 'node-fetch';
import fs from 'fs';

const formData = new FormData();
formData.append('image', fs.createReadStream('input.jpg'));

const response = await fetch('https://api.clearbg.ai/v1/removebg', {
  method: 'POST',
  headers: { 'X-API-Key': process.env.CLEARBG_API_KEY },
  body: formData
});

const imageBlob = await response.blob();

Python

import requests

with open('input.jpg', 'rb') as f:
    response = requests.post(
        'https://api.clearbg.ai/v1/removebg',
        headers={'X-API-Key': 'YOUR_API_KEY'},
        files={'image': f}
    )

with open('output.png', 'wb') as f:
    f.write(response.content)