Remove Background: Multiple Variants

Generate multiple output versions from a single image in one processing request.

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 array
Returnsoutput_urls keyed by variant_name

This example generates 3 variants in one call:

variant_nameResolutionFormatBackgroundNotes
full12MPPNGTransparentHigh quality, full resolution
thumbnail0.25MPWebPTransparentAuto-cropped to object bounds
white_bg12MPJPG#ffffffWhite background, compressed
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 with multiple output variants (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": "full",
                "max_resolution": 12000000,
                "format": "png",
                "quality": "high"
                # transparent background (default)
            },
            {
                "variant_name": "thumbnail",
                "max_resolution": 250000,
                "format": "webp",
                "quality": "medium",
                "autocrop": True
                # crops tightly to object bounds
            },
            {
                "variant_name": "white_bg",
                "max_resolution": 12000000,
                "format": "jpg",
                "background_color": "#ffffff",
                "output_compression": 85
            }
        ]
    },
    timeout=300
)

result.raise_for_status()
output = result.json()

print("Full PNG:  ", output["output_urls"]["full"])
print("Thumbnail: ", output["output_urls"]["thumbnail"])
print("White BG:  ", output["output_urls"]["white_bg"])
Response
{
    "unique_filename": "abc123-def456-...",
    "input_url": "https://cdn.backgroundcut.co/.../input.jpg",
    "output_urls": {
        "full": "https://cdn.backgroundcut.co/.../full.png",
        "thumbnail": "https://cdn.backgroundcut.co/.../thumbnail.webp",
        "white_bg": "https://cdn.backgroundcut.co/.../white_bg.jpg"
    }
}
FieldTypeDescription
unique_filenamestringSame identifier from the upload step. Reuse to generate more variants without re-uploading.
input_urlstringURL to the original uploaded image.
output_urlsobjectMap of variant_name → output image URL. Contains one entry per variant requested.
Output Variant Fields
FieldTypeDefaultDescription
variant_namestringRequired. Your identifier for this output. Used as the key in output_urls. Must be unique within the request.
max_resolutioninteger12000000Maximum output pixel count (width × height). Output is scaled down proportionally if the original exceeds this. 12MP = 12,000,000.
formatstring"png"Output format. Options: png, jpg, webp. Use jpg or webp when background_color is set (no alpha needed, smaller files).
qualitystring"high"Processing quality. Options: high, medium, low. Affects edge detail and mask precision.
background_colorstringnullFill color for removed background. Hex string (e.g. "#ffffff"). Omit or set to null for transparent.
output_compressioninteger85Compression level for JPG and WebP outputs. Range: 1–100. Higher = larger file, better quality. Has no effect on PNG.
autocropbooleanfalseCrop the output to the bounding box of the foreground subject. Adds 0.5 credits per variant. Useful for thumbnails.
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, duplicate variant_name, 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
  • Variant names must be unique within a request. Using the same variant_name twice in one call will return a 400 error.
  • Use JPG or WebP for solid backgrounds. PNG supports transparency but produces larger files when a solid color background is set.
  • Reuse the image. The unique_filename stays valid after processing. Call /v3/remove-bg/process-image/ again with new variants without re-uploading. See Image Reuse.
  • Output URLs are temporary — download or cache results. URLs will expire.