Remove Background: Multiple Variants

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

Step 1 Upload Image
MethodPOST
Endpoint/v3/file-ops/upload/
Content-Typemultipart/form-data
AuthToken YOUR_API_KEY
Bodyfiles + upload_path
Returnsfile_paths
Step 2 Process Image
MethodPOST
Endpoint/v3/tools/ai/remove-bg/process/
Content-Typeapplication/json
AuthToken YOUR_API_KEY
BodyJSON with input_file_path + output_variants array
Returnsoutput_file_paths

This example generates 3 variants in one call:

output_file_pathResolutionFormatBackgroundNotes
my-project/full.png12MPPNGTransparentHigh quality, full resolution
my-project/thumb.webp0.25MPWebPTransparentAuto-cropped to object bounds
my-project/white-bg.jpg12MPJPEG#ffffffWhite background, compressed
import requests

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

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

upload_response.raise_for_status()
input_file_path = upload_response.json()["file_paths"][0]

# Step 2 — Process with multiple output variants (application/json)
result = requests.post(
    f"{API_BASE}/v3/tools/ai/remove-bg/process/",
    headers={**HEADERS, "Content-Type": "application/json"},
    json={
        "input_file_path": input_file_path,
        "output_variants": [
            {
                "output_file_path": "my-project/full.png",
                "format": "png",
                "max_resolution": 12000000,
                "quality": "high"
                # transparent background (default)
            },
            {
                "output_file_path": "my-project/thumb.webp",
                "format": "webp",
                "max_resolution": 250000,
                "quality": "medium",
                "autocrop": True
                # crops tightly to object bounds
            },
            {
                "output_file_path": "my-project/white-bg.jpg",
                "format": "jpeg",
                "max_resolution": 12000000,
                "background_color": "#ffffff",
                "output_compression": 85
            }
        ]
    },
    timeout=300
)

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

full_path, thumb_path, white_bg_path = output["output_file_paths"]
print("Full PNG:  ", full_path)
print("Thumbnail: ", thumb_path)
print("White BG:  ", white_bg_path)
Response
{
    "output_file_paths": [
        "my-project/full.png",
        "my-project/thumb.webp",
        "my-project/white-bg.jpg"
    ]
}
FieldTypeDescription
output_file_pathsstring[]Ordered list of output file paths in your space, one per variant in the same order as output_variants.
Output Variant Fields
FieldTypeDefaultDescription
output_file_pathstringrequired Destination path in your space (e.g. my-project/result.png).
formatstring"png"Output format: png, jpeg, jpg, webp, avif. Use JPEG/WebP for solid color backgrounds.
max_resolutioninteger12000000Maximum pixel count (width × height). Range: 4096–25,000,000.
qualitystring"high"Processing quality: high, medium, low. Affects edge detail and mask precision.
background_colorstringnullFill color (e.g. "#ffffff"). Omit or set to null for transparent.
output_compressioninteger85Compression level for JPEG/WebP/AVIF outputs (1–100). No effect on PNG.
autocropbooleanfalseCrop the output to the bounding box of the foreground subject. Useful for thumbnails.
Error Response

All errors return JSON with a detail field:

{
    "detail": "Invalid image format. Supported: JPEG, PNG, WebP, AVIF"
}
StatusMeaning
400Bad request — missing fields, invalid format, or malformed JSON
401Missing or invalid Authorization header
402Insufficient credits
404File not found — input_file_path does not exist
429Rate limit exceeded — slow down requests
Tips
  • Use JPEG or WebP for solid backgrounds. PNG supports transparency but produces larger files when a solid color background is set.
  • Reuse the image. The file persists in your space after upload. Call /v3/tools/ai/remove-bg/process/ again with the same input_file_path and new variants without re-uploading. See Image Reuse.
  • Paths are ordered. Entries in output_file_paths correspond to variants in the same order as output_variants.