Remove Background: Custom Background
Replace the background with a solid color. Generate transparent and colored variants in one call.
Set
background_color to any hex color (e.g. #ffffff, #1A01FF, #FF5733). Omit it or set to transparent for no background. Use jpg format for colored backgrounds (smaller file size, no alpha channel needed).import requests
API_KEY = "YOUR_API_KEY"
# Replace background with a solid color
token_response = requests.post(
"https://backgroundcut.co/api/v3/remove-bg/token/",
headers={
"Authorization": f"Bearer {API_KEY}",
"Content-Type": "application/json"
},
json={
"output_variants": [
{
"variant_name": "blue_bg",
"background_color": "#1A01FF",
"max_resolution": 1000000,
"quality": "low"
},
{
"variant_name": "white_bg",
"background_color": "#ffffff",
"format": "jpg",
"output_compression": 90
},
{
"variant_name": "transparent",
"format": "png"
# background_color defaults to transparent
}
]
},
timeout=60
)
token_response.raise_for_status()
access_token = token_response.json()["access_token"]
with open("photo.jpg", "rb") as f:
result = requests.post(
"https://api.backgroundcut.co/v3/remove-bg/",
files={"image": f},
data={"token": access_token},
timeout=300
)
result.raise_for_status()
output = result.json()
print("Blue:", output["output_urls"]["blue_bg"])
print("White:", output["output_urls"]["white_bg"])
print("Transparent:", output["output_urls"]["transparent"])