SDK
Official SDK for removing image backgrounds
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);API Reference
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 |
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 Types
When output is "url" (default):
{ id: string; url: string }When output is "raw":
ArrayBufferExample
With a local file
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);Using trim option
const result = await client.removeBackground({
input: "https://example.com/image.png",
trim: true,
output: "url"
});
console.log("Trimmed result:", result.url);