Background removal is one of those tasks every developer hits eventually. Product photos for an e-commerce store, headshots for a team page, isolating objects for computer vision pipelines โ you either spend time in Photoshop or hack together something with OpenCV that sort of works on simple images.
Agent Media Tools has a free background removal API powered by BiRefNet (Bilateral Reference Network) that handles complex edges โ hair, fur, transparent objects โ and returns a clean PNG with transparency. One HTTP call, no signup required for basic use.
In this guide you'll learn:
curlBiRefNet is a state-of-the-art background removal model trained on massive datasets of foreground/background pairs. Unlike older chroma-key or threshold-based approaches, BiRefNet works on arbitrary images:
The output is always a PNG with an alpha channel. Transparent pixels where the background was, opaque where the subject is, and partial transparency along soft edges.
The API is a simple POST endpoint. Provide a public image URL and get back a PNG data URL with the background removed:
curl -s https://agentmediatools.com/api/tools/remove-background \
-H "Content-Type: application/json" \
-d '{"image_url": "https://example.com/photos/product.jpg"}' \
| jq -r '.data' > product-nobg.png
If you don't have jq installed, pipe through Python's base64 decoder instead:
curl -s https://agentmediatools.com/api/tools/remove-background \
-H "Content-Type: application/json" \
-d '{"image_url": "https://example.com/photos/product.jpg"}' \
| python3 -c "
import sys, json, base64
data = json.load(sys.stdin)
with open('output.png', 'wb') as f:
f.write(base64.b64decode(data['data'].split(',')[1]))
print('Saved output.png')
"
The response is a JSON object with a data field containing a base64-encoded PNG data URL. Save it to a file, embed it in an <img> tag, or pass it to the next step in your pipeline.
Here's a reusable Python function with error handling:
import requests
import base64
import json
from pathlib import Path
API_URL = "https://agentmediatools.com/api/tools/remove-background"
def remove_background(image_url: str, output_path: str = "output.png") -> Path:
"""Remove background from an image URL and save the result."""
resp = requests.post(API_URL, json={"image_url": image_url})
resp.raise_for_status()
data = resp.json()
if "data" not in data:
raise RuntimeError(f"API error: {data.get('error', 'unknown')}")
# data comes back as a data URL: "data:image/png;base64,..."
b64 = data["data"].split(",", 1)[1]
png_bytes = base64.b64decode(b64)
path = Path(output_path)
path.write_bytes(png_bytes)
return path
# One call
result = remove_background(
"https://images.unsplash.com/photo-1507003211169-0a1dd7228f2d",
"headshot-nobg.png"
)
print(f"Saved to {result}")
Processing a directory of product photos? Run them all in parallel with concurrent.futures:
import concurrent.futures
from pathlib import Path
INPUT_DIR = Path("product_photos")
OUTPUT_DIR = Path("product_nobg")
OUTPUT_DIR.mkdir(exist_ok=True)
def process_one(img_path: Path) -> str:
# Upload to a temporary host or use a public URL
# (For local files, you'd need a public URL first)
public_url = f"https://example.com/photos/{img_path.name}"
out_path = OUTPUT_DIR / f"{img_path.stem}_nobg.png"
remove_background(public_url, str(out_path))
return f"{img_path.name} โ {out_path.name}"
image_files = list(INPUT_DIR.glob("*.jpg")) + list(INPUT_DIR.glob("*.png"))
with concurrent.futures.ThreadPoolExecutor(max_workers=5) as pool:
results = list(pool.map(process_one, image_files))
for r in results:
print(r)
The API accepts a public URL. For local images, you can upload them to any file host (or use the free artifact storage API to host them first), then pass the returned URL to the background removal endpoint.
If your AI agent runs with Agent Media Tools' MCP server, background removal is available as a first-class tool. Here's what a conversation looks like in Claude, Cursor, or any MCP-compatible client:
"Remove the background from this product photo and save it as a transparent PNG."
The agent calls the remove_background MCP tool, gets back the PNG, and writes it to disk โ no curl, no Python, no code at all. This makes it trivial to include in multi-step agent workflows:
All of that in a single conversational exchange with an AI agent that has the MCP toolset loaded.
Remove distracting backgrounds from product shots and replace with clean white or brand colors. Batch-process an entire catalog in minutes.
Extract headshots for employee directories, conference badges, or team pages. Consistent transparent-background photos look professional and uniform.
Chain background removal with image generation, resizing, and format conversion. For example: generate a product image with AI โ remove background โ resize to 800ร800 โ convert to WebP โ deliver via webhook.
Isolate subjects from any image for compositing into new designs, social media graphics, or presentation slides.
| Endpoint | POST /api/tools/remove-background |
| Content-Type | application/json |
| Body | {"image_url": "..."} |
| Response | {"data": "data:image/png;base64,..."} |
| Auth | Free tier: no auth. Higher rate limits: free API key. |
Max input file size: 20 MB. Supported input formats: JPEG, PNG, WebP, AVIF, TIFF, GIF.
You don't need an account, an API key, or even a browser extension. Paste this into your terminal:
curl -s https://agentmediatools.com/api/tools/remove-background \
-H "Content-Type: application/json" \
-d '{"image_url": "https://upload.wikimedia.org/wikipedia/commons/4/47/PNG_transparency_demonstration_1.png"}' \
| python3 -c "
import sys, json, base64
data = json.load(sys.stdin)
with open('demo.png', 'wb') as f:
f.write(base64.b64decode(data['data'].split(',')[1]))
print('Background removed! Saved as demo.png')
"
That test image is the classic PNG transparency demo โ a chessboard pattern with partial transparency in the glass. BiRefNet handles it cleanly.
Ready to use it in your project?
No signup needed for basic use. Get an API key for higher rate limits and MCP access.
Try Agent Media Tools โ