Browser-first background removal SDK with two ergonomic APIs:
removeBackground(input, options?)createClient(config?)npm install @unbg/browser-sdk
import { removeBackground, canvasToBlobUrl, revokeBlobUrl } from '@unbg/browser-sdk';
const result = await removeBackground('https://example.com/photo.jpg');
const blobUrl = await canvasToBlobUrl(result.canvas, 'image/png');
// Use blob URL in download links or img tags.
// Revoke when finished to avoid leaking memory.
revokeBlobUrl(blobUrl);
import { createClient } from '@unbg/browser-sdk';
const client = createClient({
preset: 'quality-desktop'
});
await client.load({
onProgress(progress) {
console.log(progress.progress);
}
});
const result = await client.remove('https://example.com/photo.jpg', {
background: '#ffffff'
});
client.dispose();
createClient() uses default settings.createClient({ preset: 'fast-mobile' | 'quality-desktop' }) applies tuned defaults.model, runtime, or performance values override preset/default values via deep merge.const client = createClient({
preset: 'fast-mobile',
performance: {
alphaApplyChunkRows: 192 // deep override
}
});
removeBackground(input, options?, config?)Use this for the easiest path. Internally reuses a singleton client for performance.
Companion one-liner helpers:
load(options?, config?) (alias of loadModel)loadModel(options?, config?) (supports old loadModel(onProgress, config) shape)removeMany(inputs, options?, config?, batchOptions?)dispose() (alias of disposeDefaultClient)createClient(config?)Creates a dedicated client instance with explicit lifecycle (load, remove, removeMany, dispose).
string (URL)Blob / FileHTMLImageElementImageBitmapHTMLCanvasElementClientConfigpreset: fast-mobile |
quality-desktop |
model.modelId: defaults to briaai/RMBG-1.4model.revision: defaults to mainmodel.strategy: auto |
webgpu-fp16 |
wasm-q8 |
model.candidates: explicit candidate override listruntime: transformers.js runtime knobs (cache, local/remote model behavior)
https://huggingface.co)/{model}/resolve/{revision}/performance: resize thresholds and alpha-apply chunk sizehooks:
beforeProcess(input, options?)afterProcess(result, context)telemetry(event)Override runtime if you want self-hosted/proxied model assets:
const client = createClient({
runtime: {
remoteHost: 'https://my-cdn.example.com',
remotePathTemplate: '/models/{model}/resolve/{revision}/'
}
});
RemoveOptionsbackground: 'transparent' or CSS color stringoutput: output metadata options (type/quality)createWorkerClient({ mode, workerFactory, config }) supports automatic fallback:
Worker and OffscreenCanvas are available and workerFactory is provided, operations run through the worker client.This SDK is licensed under MIT, but its default model (briaai/RMBG-1.4) is
licensed separately under bria-rmbg-1.4.
THIRD_PARTY_NOTICES.md for attribution and licensing context.If you use the default model, you must comply with BRIA’s model terms, including any commercial licensing requirements.
Public error classes:
ModelLoadErrorUnsupportedInputErrorInferenceErrormobileMaxInferencePixels in performance.dispose() when a long-lived client is idle, app teardown begins, or you switch to a new config/preset.revokeBlobUrl() for URLs produced by canvasToBlobUrl() after your image/download consumer is done.npm run test
npm run test:browser