browser-sdk

@unbg/browser-sdk

Browser-first background removal SDK with two ergonomic APIs:

Install

npm install @unbg/browser-sdk

30-Second Quick Start

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);

Advanced Client API

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();

Progressive Config Model

const client = createClient({
	preset: 'fast-mobile',
	performance: {
		alphaApplyChunkRows: 192 // deep override
	}
});

API

removeBackground(input, options?, config?)

Use this for the easiest path. Internally reuses a singleton client for performance.

Companion one-liner helpers:

createClient(config?)

Creates a dedicated client instance with explicit lifecycle (load, remove, removeMany, dispose).

Inputs

ClientConfig

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}/'
	}
});

RemoveOptions

Worker / Off-main-thread Mode

createWorkerClient({ mode, workerFactory, config }) supports automatic fallback:

Browser Compatibility & Performance

Model Licensing

This SDK is licensed under MIT, but its default model (briaai/RMBG-1.4) is licensed separately under bria-rmbg-1.4.

If you use the default model, you must comply with BRIA’s model terms, including any commercial licensing requirements.

Error Handling

Public error classes:

Troubleshooting

Testing

npm run test
npm run test:browser

Semver Policy