← API reference

API guide · Node.js

LassoCut: remove image backgrounds with Node.js

The LassoCut API removes the background from an image with a single POST request. This guide covers a tested Node.js example using the built-in fetch, useful options, common errors, and how to repoint an existing HTTP client.

Quickstart

Every request needs your key in the X-Api-Key header and exactly one image source. This example uses size=preview, which is covered by your account's 50 free previews per month. Node.js 18 or later has fetch and FormData built in, no packages to install.

import { readFile, writeFile } from "node:fs/promises";

const form = new FormData();
form.append("image_file", new Blob([await readFile("photo.jpg")]), "photo.jpg");
form.append("size", "preview");

const res = await fetch("https://api.lassocut.com/v1.0/removebg", {
  method: "POST",
  headers: { "X-Api-Key": process.env.LASSOCUT_API_KEY },
  body: form,
});
if (!res.ok) throw new Error(JSON.stringify(await res.json()));
console.log("credits charged:", res.headers.get("x-credits-charged"));
await writeFile("no-bg.png", Buffer.from(await res.arrayBuffer()));

Tested against the production API on 27 September 2026 with this exact request; it returned a valid PNG.

Point an existing Node.js client at LassoCut

Most Node.js remove.bg wrappers hardcode api.remove.bg internally and don't expose a base URL to change, so there is often nothing to reconfigure. The fetch example above is usually the fastest way to switch: it is a dozen lines with no dependency to audit.

If you use a generic HTTP client library that already sends this header and this multipart body to remove.bg (axios, undici, node-fetch), point its base URL at https://api.lassocut.com/v1.0 and keep the same X-Api-Key header; no other code changes are needed.

Useful options

FieldExampleDescription
sizepreview, full, autoPreview costs 0.25 credit; full and 50MP cost 1 credit; auto picks the largest size your balance allows.
formatpng, jpg, webpAuto (default) returns PNG when the result has transparency, JPG otherwise.
typeperson, product, carSelects the model. Auto (default) detects the subject.
crop, crop_margintrue, "30px"Crops the result to the subject, with an optional margin.
bg_color"81d4fa"Fills the background with a hex colour, a colour name, or hex with alpha.

Full list, including framing, shadows and background images: API reference.

Common errors

Errors return JSON: {"errors": [{"code": "…", "title": "…"}]}, available from await res.json() when res.ok is false. Nothing is charged on an error.

StatusWhencode
400No image, or two sources givenmissing_source, multiple_sources
402Not enough credits for this sizetitle Insufficient credits
403Missing or wrong X-Api-Keytitles Missing API Key, API Key invalid
429Rate limit reachedtitle Rate limit exceeded, with Retry-After

Full list: API reference.

Next steps

Read the full API reference for every parameter and header, or the migration guide if you're moving code that already calls remove.bg. No key yet? Create a free account, or try LassoCut on your image first, no key required.