Remove a product photo background
Create a transparent PNG cutout, save the image correctly and inspect the edges before publishing.
This guide describes production API usage. The website demo has a separate, smaller anonymous allowance. Subscribe to an available listing before running the scripts.
Choose your marketplace
The complete scripts below target RapidAPI. Use the provider tabs for the matching base URL and authentication pattern; ApyHub capabilities may be split across listings and remain unavailable until published. Never use a pending listing as a production endpoint.
Replace the base64 placeholder with your file. See the tutorial for an upload example.
import os
import httpx
base_url = "https://background-removal-api-cutouts-masks.p.rapidapi.com"
headers = {
"X-RapidAPI-Key": os.environ["RAPIDAPI_KEY"],
"X-RapidAPI-Host": "background-removal-api-cutouts-masks.p.rapidapi.com",
}
payload = {
"format": "png",
"max_size": 900,
"image": {
"base64": "BASE64_IMAGE",
},
}
response = httpx.post(
base_url + "/v1/background/remove",
headers=headers, json=payload, timeout=120
)
response.raise_for_status()
with open("result.png", "wb") as output:
output.write(response.content)Make a transparent image in one request and save it as PNG or WebP.
Prerequisites
Subscribe on RapidAPI, set RAPIDAPI_KEY, and keep it on your server. Python examples require Python 3.10+ and requests (python -m pip install requests); file examples also require the local input named in the code. Follow your plan's per-minute limit.
Try the endpoint with cURL
export RAPIDAPI_KEY='your-key-from-rapidapi'
export RAPIDAPI_HOST='background-removal-api-cutouts-masks.p.rapidapi.com'
curl --fail-with-body --request POST \
--url "https://${RAPIDAPI_HOST}/v1/background/remove" \
--header 'content-type: application/json' \
--header "x-rapidapi-host: ${RAPIDAPI_HOST}" \
--header "x-rapidapi-key: ${RAPIDAPI_KEY}" \
--data '{"image":{"url":"https://upload.wikimedia.org/wikipedia/commons/3/3a/Cat03.jpg"},"format":"png"}' \
--output result.png
Check the HTTP status before opening result.png; an error body is not a successful output.
Complete application example
import os
from pathlib import Path
import requests
HOST = "background-removal-api-cutouts-masks.p.rapidapi.com"
HEADERS = {"x-rapidapi-host": HOST, "x-rapidapi-key": os.environ["RAPIDAPI_KEY"]}
response = requests.post(f"https://{HOST}/v1/background/remove", headers=HEADERS,
json={"image": {"url": "https://upload.wikimedia.org/wikipedia/commons/3/3a/Cat03.jpg"}, "format": "png"}, timeout=90)
response.raise_for_status()
if not response.headers.get("content-type", "").startswith("image/png"):
raise RuntimeError("expected PNG output")
Path("cutout.png").write_bytes(response.content)
print("saved cutout.png")
Expected output and important limits
The public cat photo above produced an actual HTTP 200 PNG with RGBA colour mode and dimensions 1600 x 1598. A WebP request also returned RGBA at 1600 x 1598. The cover is an illustration; open your downloaded output to inspect the real cutout.
Open cutout.png in an editor that displays transparency. Change format to webp and save cutout.webp for WebP. JPEG cannot contain transparency and requires a solid background colour. Review the subject's edges before publishing.
Every API call and retry may consume your allowance, including repeated inputs and failed requests. Fix 422 input errors rather than retrying. Honor Retry-After for temporary 429/503 responses and use bounded backoff; a monthly quota error needs a renewed allowance or another plan. Do not upload material you are not authorized to process. See the Developer guide's limits and Privacy Notice before handling sensitive files.
Make it part of your application.
Get credentials and a production allowance from an available marketplace.