← API reference

API guide · curl

Remove background from images with curl and the LassoCut API

curl is all you need: one POST per image, the key in a header, the cut-out written to a file. This guide starts with a single tested command, then loops over a whole folder in bash or PowerShell, skipping images already done, and ends with the options and errors that matter in a shell script.

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 a month (up to 10 a day).

curl -H "X-Api-Key: $LASSOCUT_API_KEY" \
     -F "image_file=@photo.jpg" \
     -F "size=preview" \
     -o no-bg.png \
     https://api.lassocut.com/v1.0/removebg

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

Remove the background from a folder of images (bash)

This loop sends every JPG, PNG and WebP file in photos/ and writes out/<name>.png. It skips an image whose result already exists, so you can stop it and run it again: only the missing ones are sent, and paid.

mkdir -p out
for f in photos/*.jpg photos/*.jpeg photos/*.png photos/*.webp; do
  [ -e "$f" ] || continue                    # pattern matched no file
  name=$(basename "$f"); out="out/${name%.*}.png"
  if [ -e "$out" ]; then echo "skip $name"; continue; fi
  if curl -sS --fail-with-body --retry 4 \
       -H "X-Api-Key: $LASSOCUT_API_KEY" \
       -F "image_file=@$f" -F "size=full" -F "format=png" \
       -o "$out.part" https://api.lassocut.com/v1.0/removebg; then
    mv "$out.part" "$out"; echo "ok $name"
  else
    echo "failed $name: $(cat "$out.part" 2>/dev/null)" >&2; rm -f "$out.part"
  fi
done
  • --fail-with-body (curl 7.76 or later) makes curl exit non-zero on an HTTP error while still saving the JSON error, which the loop prints.
  • The result goes to a .part file first and is renamed only on success, so a failed call never leaves a file that the skip test would mistake for a finished one.
  • --retry 4 retries 429 Rate limit exceeded and 503 answers and waits for the Retry-After header the API sends. curl prints a line for each retried attempt; the loop still prints ok once the image succeeds.
  • format=png keeps transparency; PNG output is capped at 10 megapixels. For larger photos on a plain background, add -F "bg_color=ffffff", use format=jpg and give the output a .jpg name.

The loop sends one image at a time. For a few hundred images that is usually fine; for parallel calls from a shell, the LassoCut CLI does the same job with a --concurrency flag.

The same loop in PowerShell (Windows)

Windows 10 and 11 ship curl.exe. Call it by that full name: in Windows PowerShell 5.1, plain curl is an alias for Invoke-WebRequest, which takes different arguments.

New-Item -ItemType Directory -Force out | Out-Null
Get-ChildItem photos -File | Where-Object Extension -In '.jpg', '.jpeg', '.png', '.webp' | ForEach-Object {
  $out = Join-Path 'out' ($_.BaseName + '.png')
  if (Test-Path $out) { "skip $($_.Name)"; return }    # return = next file
  curl.exe -sS --fail-with-body --retry 4 `
    -H "X-Api-Key: $env:LASSOCUT_API_KEY" `
    -F "image_file=@$($_.FullName)" -F 'size=full' -F 'format=png' `
    -o "$out.part" https://api.lassocut.com/v1.0/removebg
  if ($LASTEXITCODE -eq 0) {
    Move-Item "$out.part" $out; "ok $($_.Name)"
  } else {
    Write-Warning "failed $($_.Name): $(Get-Content "$out.part" -Raw -ErrorAction SilentlyContinue)"
    Remove-Item "$out.part" -ErrorAction SilentlyContinue
  }
}

Set the key for the session first with $env:LASSOCUT_API_KEY = "your key". Both loops were run against a local test server that answers 429 with Retry-After before succeeding, to check the retry and skip behaviour.

Point an existing curl command at LassoCut

If you already call the remove.bg API with curl, two things change: the host and the key. Flags, form fields and the response format stay the same.

- curl -H "X-Api-Key: $REMOVE_BG_API_KEY" -F "image_file=@photo.jpg" -o no-bg.png https://api.remove.bg/v1.0/removebg
+ curl -H "X-Api-Key: $LASSOCUT_API_KEY" -F "image_file=@photo.jpg" -o no-bg.png https://api.lassocut.com/v1.0/removebg

For a full parameter-by-parameter comparison, see the migration guide.

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, 30pxCrops the result to the subject, with an optional margin.
bg_color81d4faFills the background with a hex colour, a colour name, or hex with alpha.

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

Marketplace preset and shadow

A marketplace preset frames the cut-out on the canvas, white background and file size that marketplace expects, and shadow_type=cast adds a cast shadow. The response header X-Compliance says whether the result meets the rules LassoCut checks. With a preset, crop, crop_margin, scale and position are ignored. See marketplace presets.

curl --fail-with-body -H "X-Api-Key: $LASSOCUT_API_KEY" \
     -F "image_file=@product.jpg" \
     -F "preset=amazon" \
     -F "shadow_type=cast" -F "shadow_angle=45" \
     -D headers.txt -o amazon.jpg \
     https://api.lassocut.com/v1.0/removebg
grep -i x-compliance headers.txt

Common errors

Errors return JSON: {"errors": [{"code": "…", "title": "…"}]}. 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 a script that already calls remove.bg. No key yet? Create a free account, or try LassoCut on your image first, no key required.