Remove Background: Basic

Simplest possible example. Upload an image, then process it to remove the background.

Step 1 Upload Image
MethodPOST
Endpoint/v3/remove-bg/upload-image/
Content-Typemultipart/form-data
AuthBearer YOUR_API_KEY
BodyForm field: image (file)
Returnsunique_filename
Step 2 Process Image
MethodPOST
Endpoint/v3/remove-bg/process-image/
Content-Typeapplication/json
AuthBearer YOUR_API_KEY
BodyJSON with unique_filename + output_variants
Returnsoutput_urls, input_url
import requests

API_KEY = "YOUR_API_KEY"
API_BASE = "https://api.backgroundcut.co"
HEADERS = {"Authorization": f"Bearer {API_KEY}"}

# Step 1 — Upload image (multipart/form-data)
with open("photo.jpg", "rb") as f:
    upload_response = requests.post(
        f"{API_BASE}/v3/remove-bg/upload-image/",
        headers=HEADERS,
        files={"image": f},
        timeout=60
    )

upload_response.raise_for_status()
unique_filename = upload_response.json()["unique_filename"]

# Step 2 — Process image (application/json)
result = requests.post(
    f"{API_BASE}/v3/remove-bg/process-image/",
    headers={**HEADERS, "Content-Type": "application/json"},
    json={
        "unique_filename": unique_filename,
        "output_variants": [
            {
                "variant_name": "result"
                # All other fields are optional with sensible defaults:
                # max_resolution: 12000000 (12MP)
                # format: "png"
                # quality: "high"
                # background_color: transparent
                # output_compression: 85
                # autocrop: false
            }
        ]
    },
    timeout=300
)

result.raise_for_status()
output = result.json()
print(output["output_urls"]["result"])

# Download the result
import urllib.request
urllib.request.urlretrieve(output["output_urls"]["result"], "output.png")
Step 1 Response — Upload Image
{
    "unique_filename": "a1b2c3d4-e5f6-7890-abcd-ef1234567890"
}
FieldTypeDescription
unique_filenamestringUnique identifier for the uploaded image. Use this in the process request and to reuse the image later.
Step 2 Response — Process Image
{
    "unique_filename": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
    "input_url": "https://cdn.backgroundcut.co/.../input.jpg",
    "output_urls": {
        "result": "https://cdn.backgroundcut.co/.../result.png"
    }
}
FieldTypeDescription
unique_filenamestringSame identifier from the upload step.
input_urlstringURL to the original uploaded image.
output_urlsobjectMap of variant_name → output image URL. Keys match the variant_name values you specified in output_variants.
Error Response

All errors return JSON with a detail field:

{
    "detail": "Invalid image format. Supported: PNG, JPG, JPEG, WebP"
}
StatusMeaning
400Bad request — missing image, invalid format, or malformed JSON
401Missing or invalid Authorization header
402Insufficient credits
404Image not found — unique_filename does not exist or has expired
429Rate limit exceeded — slow down requests
Tips
  • Save unique_filename — you can call /v3/remove-bg/process-image/ again with the same unique_filename and different output_variants to generate new outputs without re-uploading. See Image Reuse.
  • Output URLs are temporary — download or cache the result images. URLs will expire.
  • Supported input formats — PNG, JPG, JPEG, WebP.