logobgbuster
Background Removal API

Remove image backgrounds in Java

OkHttp is the de facto standard for multipart uploads on the JVM and drops straight into a Spring Boot service or any existing Java backend.

Quickstart

Install (Gradle)

shell
implementation("com.squareup.okhttp3:okhttp:4.12.0")

Remove a background

java
OkHttpClient client = new OkHttpClient();

RequestBody body = new MultipartBody.Builder()
    .setType(MultipartBody.FORM)
    .addFormDataPart("input", "photo.jpg",
        RequestBody.create(new File("photo.jpg"), MediaType.parse("image/jpeg")))
    .addFormDataPart("format", "png")
    .build();

Request request = new Request.Builder()
    .url("https://api.bgbuster.com/images/remove-background")
    .header("X-Api-Key", "your-api-key")
    .post(body)
    .build();

try (Response response = client.newCall(request).execute()) {
    System.out.println(response.body().string());
}
How it works

The request is a multipart POST to https://api.bgbuster.com/images/remove-background, authenticated with your API key in the X-Api-Key header. Pass the image as a file (input) or as a public URL string.

By default the response is JSON with a temporary download url. That URL stays valid for 24 hours — download and store the image yourself if you need it longer.

Need more than a plain removal? POST /images/edit takes the same kind of request and chains background removal together with resize, rotate, flip, blur, brightness/contrast/saturation, and trim — in whatever order you list them.

Parameters
FieldTypeRequiredDescription
inputFile or stringYesImage file or a public URL to fetch it from.
output"url" or "raw"NoReturn a temporary download URL, or the transformed image bytes directly. Defaults to "url".
format"png" or "webp"NoOutput image format. Defaults to "png".
trimbooleanNoTrim empty transparent space around the result.
Response

Default (output=url)

json
{
  "id": "image-id",
  "url": "https://..."
}

With output=raw, save the image bytes directly instead of following a URL

java
OkHttpClient client = new OkHttpClient();

RequestBody body = new MultipartBody.Builder()
    .setType(MultipartBody.FORM)
    .addFormDataPart("input", "photo.jpg",
        RequestBody.create(new File("photo.jpg"), MediaType.parse("image/jpeg")))
    .addFormDataPart("format", "png")
    .addFormDataPart("output", "raw")
    .build();

Request request = new Request.Builder()
    .url("https://api.bgbuster.com/images/remove-background")
    .header("X-Api-Key", "your-api-key")
    .post(body)
    .build();

try (Response response = client.newCall(request).execute()) {
    Files.write(Path.of("result.png"), response.body().bytes());
}
Errors
StatusCodeMeaning
400IMAGE_TOO_LARGEThe input image exceeds the size limit.
400IMAGE_DECODE_ERRORThe input file couldn't be decoded as an image.
400INVALID_IMAGE_URLThe URL passed as input didn't return image content.
400UPSTREAM_ERRORThe input URL couldn't be fetched.
401UNAUTHORIZEDThe API key is missing or invalid.
402INSUFFICIENT_BALANCEYour account is out of credits.
403IMAGE_FORBIDDENThe source CDN blocked the request for the input URL.
429TOO_MANY_REQUESTSRate limit exceeded — retry after a short delay.
500IMAGE_TRANSFORMATION_ERRORThe background removal step failed unexpectedly.
Getting an API key
  1. 1

    Create an account

    Sign up with an email or a social login — no credit card required.

  2. 2

    Add credits

    Buy a credit pack. Credits never expire, and you'll need a balance before the API accepts requests.

  3. 3

    Create an API key

    From the dashboard, go to API Keys and click Create API key.

  4. 4

    Authenticate your requests

    Send the key in the X-Api-Key header on every request to api.bgbuster.com.

Try it yourself
No signup required — drop an image in and see the result before you write any code.