Remove Background: Basic

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

Step 1 Upload Image
MethodPOST
Endpoint/v3/file-ops/upload/
Content-Typemultipart/form-data
AuthToken YOUR_API_KEY
Bodyfiles (file), upload_path (string)
Returnsfile_paths (array)
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
Returnsoutput_file_paths (array)
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 image (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/result.png"
                # All other fields are optional with sensible defaults:
                # format: "png"
                # max_resolution: 12000000 (12MP)
                # quality: "high"
                # background_color: null (transparent)
                # output_compression: 85
                # autocrop: false
            }
        ]
    },
    timeout=300
)

result.raise_for_status()
output = result.json()
print(output["output_file_paths"][0])
Step 1 Response — Upload Image
{
    "file_paths": ["my-project/photo.jpg"]
}
FieldTypeDescription
file_pathsstring[]Paths of the uploaded files in your space. Pass file_paths[0] as input_file_path to tool endpoints.
Step 2 Response — Process Image
{
    "output_file_paths": ["my-project/result.png"]
}
FieldTypeDescription
output_file_pathsstring[]Ordered list of output file paths in your space, one per variant. Download via GET /v3/files/{path} with your API key.
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
  • Reuse uploads — uploaded files persist in your space. Call /v3/tools/ai/remove-bg/process/ again with the same input_file_path and different variants without re-uploading. See Image Reuse.
  • Download results — fetch output_file_paths[0] via GET /v3/files/{path} with your API key in the header.
  • Supported input formats — JPEG, PNG, WebP, AVIF.