BGBuster

SDK

Official SDK for removing image backgrounds and applying edits

The @bgbuster/sdk package provides a convenient way to interact with the BGBuster API from your JavaScript/TypeScript applications.

Installation

npm install @bgbuster/sdk

Quick Start

import { createClient } from "@bgbuster/sdk";

const client = createClient("your-api-key");

const result = await client.removeBackground({
  input: "https://example.com/image.jpg",
  output: "url",
  format: "png"
});

console.log(result.url);

createClient(apiKey, options?)

Creates a BGBuster API client instance.

ParameterTypeDescription
apiKeystringYour API key from BGBuster dashboard
optionsKoolFetchOptionsOptional configuration for the fetch client

Returns a client with removeBackground and edit methods.

client.removeBackground(options)

Removes the background from an image.

const result = await client.removeBackground({
  input: string | File,
  output?: "url" | "raw",
  format?: "png" | "webp",
  trim?: boolean
});
ParameterTypeDefaultDescription
inputstring | FileRequiredImage URL or File object
output"url" | "raw""url"Return a temporary URL or raw image data
format"png" | "webp""png"Output format
trimbooleanfalseTrim empty space around the image

Response

When output is "url" (default):

{ id: string; url: string }

When output is "raw":

ArrayBuffer

Example

import { createClient } from "@bgbuster/sdk";
import { readFileSync } from "node:fs";

const client = createClient(process.env.BGBUSTER_API_KEY!);

const imageFile = readFileSync("./photo.jpg");

const result = await client.removeBackground({
  input: new File([imageFile], "photo.jpg", { type: "image/jpeg" }),
  output: "url",
  format: "png"
});

console.log("Background removed:", result.url);
// Trim empty space around the result
const result = await client.removeBackground({
  input: "https://example.com/image.png",
  trim: true,
  output: "url"
});

console.log("Trimmed result:", result.url);

client.edit(options)

Applies an ordered list of editing operations to an image — resize, rotate, flip, adjust blur/brightness/contrast/saturation, fill transparent areas with a color, remove the background, and trim — in a single request.

const result = await client.edit({
  input: string | File,
  operations: EditOperation[],
  output?: "url" | "raw",
  format?: "png" | "webp" | "jpeg" | "gif" | "avif",
  quality?: number,
  anim?: boolean
});
ParameterTypeDefaultDescription
inputstring | FileRequiredImage URL or File object
operationsEditOperation[]RequiredOrdered list of edit operations, 1-20 entries. Execution order follows array order, including where removeBackground falls relative to the others.
output"url" | "raw""url"Return a temporary URL or raw image data
format"png" | "webp" | "jpeg" | "gif" | "avif""png"Output format
qualitynumber (1-100)-Compression quality. Only applies to jpeg/webp; ignored for other formats
animbooleanfalsePreserve all frames of an animated gif/webp input. When false, only the first frame is used

The EditOperation type

Each entry in operations is an object with exactly one of the following keys:

KeyValueDescription
resize{ width?: number; height?: number; fit?: "contain" | "cover" | "scale-down" | "crop" }Resize the image. Provide width and/or height (max 10000px each).
rotate90 | 180 | 270Rotate the image clockwise by this many degrees.
flip"h" | "v" | "hv"Flip horizontally, vertically, or both.
blurnumber (0-250)Approximate Gaussian blur radius. 0 = no blur, 250 = maximum.
brightnessnumber (≥0)Brightness multiplier. 1.0 = no change, 0.5 = half brightness, 2.0 = twice as bright.
contrastnumber (≥0)Contrast multiplier. 1.0 = no change.
saturationnumber (≥0)Saturation multiplier. 1.0 = no change, 0 = grayscale, 2.0 = high saturation.
backgroundstring (CSS color)Fills transparent areas of the image at this point in the pipeline. Accepts hex, rgb()/rgba(), hsl()/hsla(), hwb(), or a named color (e.g. "red", "transparent").
removeBackgroundtrueAI background removal, at this point in the pipeline. Skipped automatically if the image is already transparent. At most one removeBackground entry is allowed per request.
trimtrueAutomatically detects and trims a uniform-color border around the image, at this point in the pipeline.

Response

When output is "url" (default):

{ id: string; url: string }

When output is "raw":

ArrayBuffer

Example

import { createClient } from "@bgbuster/sdk";

const client = createClient("your-api-key");

const result = await client.edit({
  input: "https://example.com/photo.jpg",
  output: "url",
  operations: [
    { resize: { width: 800 } },
    { removeBackground: true },
    { background: "white" }
  ]
});

console.log("Edited:", result.url);
// Rotate and convert to jpeg with custom quality
const result = await client.edit({
  input: "https://example.com/photo.jpg",
  operations: [{ rotate: 90 }],
  format: "jpeg",
  quality: 80
});

console.log("Rotated:", result.url);

On this page