Skip to main content

Class: FalBackgroundRemovalProvider

Defined in: packages/agentos/src/io/segmentation/providers/FalBackgroundRemovalProvider.ts:174

Background removal on fal BiRefNet.

Example​

const provider = new FalBackgroundRemovalProvider();
await provider.initialize({ apiKey: process.env.FAL_API_KEY! });
const { image } = await provider.removeBackground({
modelId: '',
imageUrl: 'https://example.com/hero.png',
output: 'url',
format: 'png',
returnMask: false,
timeoutMs: 60_000,
});

Implements​

Constructors​

Constructor​

new FalBackgroundRemovalProvider(): FalBackgroundRemovalProvider

Returns​

FalBackgroundRemovalProvider

Properties​

defaultModelId?​

optional defaultModelId: string

Defined in: packages/agentos/src/io/segmentation/providers/FalBackgroundRemovalProvider.ts:177

Implementation of​

IBackgroundRemovalProvider.defaultModelId


isInitialized​

isInitialized: boolean = false

Defined in: packages/agentos/src/io/segmentation/providers/FalBackgroundRemovalProvider.ts:176

Implementation of​

IBackgroundRemovalProvider.isInitialized


providerId​

readonly providerId: "fal" = 'fal'

Defined in: packages/agentos/src/io/segmentation/providers/FalBackgroundRemovalProvider.ts:175

Implementation of​

IBackgroundRemovalProvider.providerId

Methods​

initialize()​

initialize(config): Promise<void>

Defined in: packages/agentos/src/io/segmentation/providers/FalBackgroundRemovalProvider.ts:187

Parameters​

config​

Record<string, unknown>

apiKey (required; a comma-separated list rotates), baseURL (default https://fal.run), defaultModelId (default fal-ai/birefnet/v2).

Returns​

Promise<void>

Throws​

When apiKey is missing.

Implementation of​

IBackgroundRemovalProvider.initialize


removeBackground()​

removeBackground(request): Promise<BackgroundRemovalResult>

Defined in: packages/agentos/src/io/segmentation/providers/FalBackgroundRemovalProvider.ts:214

Cuts the subject of request.imageUrl out of its background.

Parameters​

request​

BackgroundRemovalRequest

Returns​

Promise<BackgroundRemovalResult>

Throws​

invalid_request for a malformed endpoint id, timeout or maxResponseBytes, or an answer of 400, 413 or 422; provider_failed for any other failed answer, a network failure, an answer without the image (or without the mask returnMask asked for), an inline image that is not base64, or an answer or download past maxResponseBytes; timeout when request.timeoutMs passes first. A failed answer carries its HTTP status.

Throws​

The reason of request.signal when the caller aborts.

Implementation of​

IBackgroundRemovalProvider.removeBackground