โ† Back to blog

Remove Image Backgrounds with One API Call โ€” Free AI Background Removal for Agents

July 22, 2026 ยท Eric ยท 5 min read

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:

What is BiRefNet?

BiRefNet 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.

Quickstart: curl

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')
"
What you get back

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.

Python: Download & Process

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}")

Batch Processing

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)
โš ๏ธ Local files

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.

Using from an AI Agent (MCP)

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:

Agent prompt

"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:

  1. Take a screenshot of a webpage
  2. Remove the background from the screenshot
  3. Overlay it onto a template
  4. Compress the result to WebP
  5. Upload via the artifact storage API

All of that in a single conversational exchange with an AI agent that has the MCP toolset loaded.

Use Cases

๐Ÿ›๏ธ E-commerce Product Photography

Remove distracting backgrounds from product shots and replace with clean white or brand colors. Batch-process an entire catalog in minutes.

๐Ÿ‘ค Profile Photo Cleanup

Extract headshots for employee directories, conference badges, or team pages. Consistent transparent-background photos look professional and uniform.

๐Ÿค– AI Agent Pipelines

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.

๐Ÿ–ผ๏ธ Meme & Content Creation

Isolate subjects from any image for compositing into new designs, social media graphics, or presentation slides.

API Details

EndpointPOST /api/tools/remove-background
Content-Typeapplication/json
Body{"image_url": "..."}
Response{"data": "data:image/png;base64,..."}
AuthFree tier: no auth. Higher rate limits: free API key.

Limits & Pricing

Max input file size: 20 MB. Supported input formats: JPEG, PNG, WebP, AVIF, TIFF, GIF.

Try It Now

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 โ†’

Next Steps