Skip to main content
The official TypeScript SDK for Poof works in Node.js, Deno, Bun and the browser, with full type definitions. It ships as both ESM and CommonJS.

Installation

Requirements: Node.js 18+ (or Deno/Bun/browser)

Quick Start

Authentication

apiKey is required. The SDK does not read an environment variable for you, so pass it in yourself:
Never ship your API key in browser code. Call the SDK from your server (see the framework examples below).

Usage Examples

removeBackground(input, options?) accepts a File, Blob, ArrayBuffer, Buffer, Uint8Array, or a string file path (Node.js only).

From File Path (Node.js)

From Buffer

From File or Blob (browser / server upload)

From URL

Download the image first, then pass the bytes:

With Options

channels: 'alpha', padding, aspect-ratio crop, the matte metadata fields and the width / height / fit output-size options need @poof-bg/js 1.1.0 or later; video needs 1.2.0 or later.
Every successful image call costs 1 credit regardless of options. Failed calls are not billed. Video costs 5 credits per started second of source video (10 above 30 fps), charged when the job is accepted and refunded if it fails. Animated GIF input is billed at 5 credits per second whatever its frame rate. See Video.

Result and Metadata

removeBackground() resolves to a RemoveBackgroundResult:

Flagging Results for Review

matteConfidence (0–1) is how decisive the alpha mask is; matteAmbiguousRatio (0–1) is the fraction of pixels with alpha between 0.1 and 0.9. Both are heuristics, not calibrated probabilities. The dashboard playground flags a result for review when the ambiguous ratio is above 0.15:

Parallel Processing

Account Info

me() returns the /me response. It is free and not rate limited.

Error Handling

All errors extend PoofError, which exposes .code, .status, .requestId, .details and .message. Subclasses are chosen by the API error code:

Retry with Backoff

Configuration

TypeScript Types

Full type definitions are included:

Framework Examples

Express.js

Next.js API Route

Video

removeBackground() accepts video too (@poof-bg/js 1.2.0 or later). Poof detects the media type from the bytes: an image resolves to a RemoveBackgroundResult as above, a video is accepted as an asynchronous job and the call resolves to a Job instead. Use the isJob() type guard to tell them apart, wait for the job, then download its resultUrl.
An animated GIF works as input too, and format: 'gif' returns a looping transparent GIF (1-bit transparency, no audio, capped at 1280 px on the longest side, 720p for widescreen, and 50 fps) for stickers and chat. Pass wait: true to resolve with the finished job in one call:
Large files (up to 500 MB) can be fetched by Poof from a public https URL instead of uploading them, and a job can be looked up by id at any time:
In the browser, pass the File from an <input type="file"> exactly as for images; the result URL can be set straight on a <video> element.

Video options

crop, padding, width, height and fit are image-only; sending one with a video rejects with a PoofError of code validation_error.

Job fields

waitForJob(jobOrId, { pollIntervalMs = 3000, timeoutMs = 600000, onProgress }) polls GET /jobs/{id} (free, not rate limited) and rejects with a PoofError of code job_failed if the job fails, or timeout after timeoutMs. The full job lifecycle is described in the Jobs reference.