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/sdkQuick 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.
| Parameter | Type | Description |
|---|---|---|
apiKey | string | Your API key from BGBuster dashboard |
options | KoolFetchOptions | Optional 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
});| Parameter | Type | Default | Description |
|---|---|---|---|
input | string | File | Required | Image URL or File object |
output | "url" | "raw" | "url" | Return a temporary URL or raw image data |
format | "png" | "webp" | "png" | Output format |
trim | boolean | false | Trim empty space around the image |
Response
When output is "url" (default):
{ id: string; url: string }When output is "raw":
ArrayBufferExample
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
});| Parameter | Type | Default | Description |
|---|---|---|---|
input | string | File | Required | Image URL or File object |
operations | EditOperation[] | Required | Ordered 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 |
quality | number (1-100) | - | Compression quality. Only applies to jpeg/webp; ignored for other formats |
anim | boolean | false | Preserve 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:
| Key | Value | Description |
|---|---|---|
resize | { width?: number; height?: number; fit?: "contain" | "cover" | "scale-down" | "crop" } | Resize the image. Provide width and/or height (max 10000px each). |
rotate | 90 | 180 | 270 | Rotate the image clockwise by this many degrees. |
flip | "h" | "v" | "hv" | Flip horizontally, vertically, or both. |
blur | number (0-250) | Approximate Gaussian blur radius. 0 = no blur, 250 = maximum. |
brightness | number (≥0) | Brightness multiplier. 1.0 = no change, 0.5 = half brightness, 2.0 = twice as bright. |
contrast | number (≥0) | Contrast multiplier. 1.0 = no change. |
saturation | number (≥0) | Saturation multiplier. 1.0 = no change, 0 = grayscale, 2.0 = high saturation. |
background | string (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"). |
removeBackground | true | AI 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. |
trim | true | Automatically 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":
ArrayBufferExample
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);