LassoCut: remove image backgrounds with Python
The LassoCut API removes the background from an image with a single POST request. This guide covers a tested Python example using requests, useful options, common errors, and how to repoint an existing remove.bg 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. requests is the only dependency.
import os, requests
r = requests.post(
"https://api.lassocut.com/v1.0/removebg",
headers={"X-Api-Key": os.environ["LASSOCUT_API_KEY"]},
files={"image_file": open("photo.jpg", "rb")},
data={"size": "preview"},
)
r.raise_for_status()
open("no-bg.png", "wb").write(r.content)
print("credits charged:", r.headers["X-Credits-Charged"])
Tested against the production API on 27 September 2026 with this exact request; it returned a valid PNG.
Point an existing Python client at LassoCut
Already using the removebg package (PyPI) to call remove.bg? Its request URL is a module-level constant you can override before creating the client:
import os
import removebg.removebg
removebg.removebg.API_ENDPOINT = "https://api.lassocut.com/v1.0/removebg"
from removebg import RemoveBg
RemoveBg(os.environ["LASSOCUT_API_KEY"], "errors.log").remove_background_from_img_file("photo.jpg")
Verified from the package's source on GitHub (brilam/remove-bg), read on 27 September 2026. It is a third-party, community-maintained package: not produced by LassoCut and not affiliated with remove.bg. For any other HTTP client, set its base URL to https://api.lassocut.com/v1.0 and keep the same X-Api-Key header.
Useful options
| Field | Example | Description |
|---|---|---|
size | preview, full, auto | Preview costs 0.25 credit; full and 50MP cost 1 credit; auto picks the largest size your balance allows. |
format | png, jpg, webp | Auto (default) returns PNG when the result has transparency, JPG otherwise. |
type | person, product, car | Selects the model. Auto (default) detects the subject. |
crop, crop_margin | True, "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": "…"}]}. raise_for_status() turns them into an HTTPError; the JSON body is in r.json() before that, or e.response.json() after. Nothing is charged on an error.
| Status | When | code |
|---|---|---|
| 400 | No image, or two sources given | missing_source, multiple_sources |
| 402 | Not enough credits for this size | title Insufficient credits |
| 403 | Missing or wrong X-Api-Key | titles Missing API Key, API Key invalid |
| 429 | Rate limit reached | title 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.