DEV Community

Cover image for Test Your New Background Removal API Before Dec 1: Five Photos, Three Checks
Oleg Tagobitsky for API4AI

Posted on

Test Your New Background Removal API Before Dec 1: Five Photos, Three Checks

remove.bg's self-serve API closes on December 1, 2026, at 9:00 CET, and unused credits expire the same day. If you've already picked a replacement, the switch itself may be one line. The part worth an hour this week is the test: your own photos, before your code depends on the new service.

This is the short version of that test. It uses our remove.bg-compatible endpoint (we make the API4AI Background Removal API), but the five photos and the three checks work for any replacement.

The switch, in two lines

Our endpoint takes remove.bg's requests: the same paths, almost all of its parameters, and the same response and error format. New URL and key, same code:

  • URL: https://api.remove.bg/v1.0/removebg → https://api4ai.cloud/img-bg-removal/v1/rbg/v1.0/removebg (and /v1.0/account the same way).
  • Key: an API4AI key from the developer portal, in the same X-Api-Key header.

What it costs per image, the same for every size: $0.005 for general background removal (type=auto included), $0.015 with type=person, $0.03 with type=car. For people and cars, set the type: that's what gives the best results.

Five photos

Don't test with the photo from the docs. Take five of your own, the ones your users actually upload:

  1. Your most common photo. A product on a table, a seller's phone shot: whatever makes up most of your volume.
  2. Hair or fur. A person or a pet. For people, send type=person.
  3. White on white. A light product on a light background, where the edge is hardest to find.
  4. Something see-through. A glass bottle, a veil, or a car: for car photos send type=car, and the new background shows through the windows.
  5. Your biggest file. The largest image your users send. Outputs go up to 4096×4096.

A small script for the run

If your code already calls remove.bg, the quickest test is your own code with the new URL and key. If you'd rather run the five photos separately, this prints what the three checks below need: the status, the type, the charge and the output size.

"""Run a few of your own photos through the new endpoint.

    pip install requests pillow
    export API4AI_KEY=...      # from portal.api4.ai
    python check_switch.py auto photos/products/*.jpg
    python check_switch.py car photos/cars/*.jpg
"""
import io
import os
import sys

import requests
from PIL import Image

BASE = "https://api4ai.cloud/img-bg-removal/v1/rbg"   # was https://api.remove.bg
HEADERS = {"X-Api-Key": os.environ["API4AI_KEY"]}

photo_type, paths = sys.argv[1], sys.argv[2:]    # auto, person or car

for path in paths:
    # Send the parameters your code sends today, plus the type.
    data = {"size": "auto", "type": photo_type}
    with open(path, "rb") as f:
        r = requests.post(f"{BASE}/v1.0/removebg", headers=HEADERS,
                          files={"image_file": f}, data=data, timeout=120)
    if r.status_code != 200:
        print(f"{path}: HTTP {r.status_code} {r.text[:120]}")   # same error format as remove.bg
        continue
    out = Image.open(io.BytesIO(r.content))
    print(f"{path}: {out.size[0]}x{out.size[1]} {out.mode}, "
          f"X-Type {r.headers.get('X-Type')}, charged ${r.headers.get('X-Credits-Charged')}")
    out.save(os.path.splitext(path)[0] + "-no-bg.png")

account = requests.get(f"{BASE}/v1.0/account", headers=HEADERS, timeout=30).json()
print("balance:", account)
Enter fullscreen mode Exit fullscreen mode

A run on three test photos looks like this:

car.jpg: 2000x2000 RGBA, X-Type car, charged $0.03
person-1.jpg: 1500x1000 RGBA, X-Type person, charged $0.015
product-1.jpg: 1500x1000 RGBA, X-Type other, charged $0.005
Enter fullscreen mode Exit fullscreen mode

Check 1: errors still reach your error handling

Most remove.bg code checks the HTTP status and reads errors[0].title when something goes wrong. The endpoint answers in the same format, so that code keeps working. Try two failures on purpose:

  • A wrong key: HTTP 403, {"errors":[{"title":"Passed API key is not allowed to access this API service."}]}.
  • No image: HTTP 400 with "code":"missing_source", the same code remove.bg uses.

One more: if your code sends shadow_type=3D, you'll get a 400 (unsupported_shadow_type). 3D shadows aren't supported, so find that call now rather than on Dec 1.

Check 2: the cost is in dollars, not credits

remove.bg counts credits; we count US dollars. The same headers and fields are there, with dollar amounts in them:

  • X-Credits-Charged on each response is what that image cost: 0.005, 0.015 or 0.03.
  • GET /v1.0/account returns your balance in remove.bg's shape, with the amount in dollars in credits.total.

If any of your code turns credits into a budget, a warning or an invoice line, change the unit there. And look at the type: the same code costs $0.005 an image for general background removal and $0.03 for type=car, so a car marketplace's bill is six times a shop's.

Check 3: open every result

Numbers don't tell you whether a cut-out is good. Put each result on a dark and a light background and look at:

  • The edges: hair, fur, lace, the white-on-white photo.
  • Anything see-through: glass, a veil, car windows (the new background should show through them).
  • The size: what came back against what your pages need. In our test runs, size=auto returned the input's own size.

Keep your originals. If a photo comes out wrong, you still have it, and so does whoever reviews it.

What's different from remove.bg

The migration page lists it in full. The ones most likely to matter: amounts in dollars instead of credits; outputs up to 4096×4096; no 3D shadows; API keys only, no OAuth; X-Type is only person, car or other; no rate-limit headers.

Before Dec 1

  1. Get a key on the API4AI developer portal: no credit card, $5 of free credit, enough for these five photos many times over. Pay as you go after that, no subscription, and the balance never expires.
  2. Run the five photos and the three checks.
  3. Change the URL and the key in your code, and run a day's photos through it before your remove.bg credits expire.

Samples in cURL, Python and Node, and the full list of what is and isn't supported, are on our moving from remove.bg page. Commercial use of the results is covered in our Terms of Use.

Which of the five photos is the hardest one in your set?

Top comments (1)

Collapse
 
aifliproom profile image
AI Flip Room •

The hardest in our set are interior shots with a bright window. The edges are easy. The trouble is what sits in front of glass or a mirror, which tends to get read as background. Hair and fur turned out simpler than glass for us. Checking each result on both a dark and a light background is a good habit, a halo hides on one of them.