Remove Background: Image Reuse

Generate new variants from a previously uploaded image without re-uploading it.

How it works:

  1. First request returns a unique_filename in the response.
  2. Pass unique_filename in subsequent token requests to skip the upload.
  3. Send only the token to the processing API — no image file needed.
import requests
import json

API_KEY = "YOUR_API_KEY"
TOKEN_URL = "https://backgroundcut.co/api/v3/remove-bg/token/"
PROCESS_URL = "https://api.backgroundcut.co/v3/remove-bg/"
HEADERS = {
    "Authorization": f"Bearer {API_KEY}",
    "Content-Type": "application/json"
}

# =============================================
# FIRST REQUEST — upload image
# =============================================
token1 = requests.post(
    TOKEN_URL, headers=HEADERS,
    json={"output_variants": [{"variant_name": "initial", "quality": "low"}]},
    timeout=60
).json()["access_token"]

with open("photo.jpg", "rb") as f:
    result1 = requests.post(
        PROCESS_URL,
        files={"image": f},
        data={"token": token1},
        timeout=300
    ).json()

unique_filename = result1["unique_filename"]
print("Unique filename:", unique_filename)
print("Initial result:", result1["output_urls"]["initial"])

# =============================================
# LATER — new variants, NO upload
# =============================================
token2 = requests.post(
    TOKEN_URL, headers=HEADERS,
    json={
        "unique_filename": unique_filename,
        "output_variants": [
            {
                "variant_name": "high_res",
                "max_resolution": 4000000,
                "quality": "high",
                "autocrop": True
            },
            {
                "variant_name": "red_bg",
                "background_color": "#FF5733",
                "format": "jpg"
            }
        ]
    },
    timeout=60
).json()["access_token"]

# No image file — just the token
result2 = requests.post(
    PROCESS_URL,
    data={"token": token2},
    timeout=300
).json()

print("High res:", result2["output_urls"]["high_res"])
print("Red BG:", result2["output_urls"]["red_bg"])
Use cases
  • E-commerce: Upload once, generate marketplace-specific variants (Amazon, Shopify, eBay) later.
  • A/B testing: Try different background colors or quality settings on the same image.
  • Responsive images: Generate additional sizes on demand.