Measure background removal API latency in Python (2027)
Bria.ai

Updated 2026-12-01
Disclosure: Bria wrote this guide and uses the Bria API in its code. The method works for any background removal API that accepts an image and returns a result. The Bria facts come from Bria's documentation, read on 2026-12-02.
TL;DR
Answer: To find which background removal API has the lowest latency, time the same images through each API with
time.perf_counter(), then compare the median (p50) and the 95th percentile (p95).Sample size: Use at least 20 images per API. Fewer runs hide the slow calls that users notice.
Bria setup: The Bria remove background endpoint takes
sync: trueto hold the connection open, which makes one request equal one timed call.Documented times: Bria's docs state under a second for RMBG 2.0, so compare your RMBG 2.0 results with that figure and investigate large gaps.
Limit: Stay under the plan's rate limit while you test, or 429 errors will distort the results.
If you need to know which background removal API has the best performance and lowest latency, none of the five APIs reviewed in the sibling comparison publishes a p50 or p95 for you. This guide gives you a script that produces them.
What should you measure for background removal API latency?
Measure wall-clock time from sending the request to receiving the finished result, for each image, then report p50 and p95.
A single timing is not a result. Image size, network distance and server load change each call, so you need a set.
p50: The median call. Half of the requests finish faster.
p95: The call that 19 of 20 requests beat. It shows what slow requests feel like.
Success and failure counts: How many runs returned status 200 and which statuses the others returned. A fast error is not a fast result.
Image mix: Use your real images, at your real sizes.
How do you time one request to the Bria API?
Send one request with `sync: true` and wrap it in `time.perf_counter()`.
The Bria docs describe sync as follows: false returns a status URL immediately, and true holds the connection open and returns the final image URL. The default is false. For timing, true is simpler, because the response carries the result.
Create an API token and export it as
BRIA_API_TOKEN.Install the one dependency with
pip install requests.Save the script below as
bench.py.Run
python bench.py.
import os
import statistics
import time
import requests
URL = "https://engine.prod.bria-api.com/v2/image/edit/remove_background"
HEADERS = {"api_token": os.environ["BRIA_API_TOKEN"], "Content-Type": "application/json"}
IMAGES = ["https://labs-assets.bria.ai/sandbox-example-inputs/remove_background_example.jpg"] * 20
def time_one(image_url, model):
payload = {"image": image_url, "model": model, "sync": True}
start = time.perf_counter()
response = requests.post(URL, headers=HEADERS, json=payload, timeout=120)
elapsed = time.perf_counter() - start
return response.status_code, elapsed
def percentile(values, p):
ordered = sorted(values)
index = min(len(ordered) - 1, round(p * (len(ordered) - 1)))
return ordered[index]
for model in ("RMBG2", "RMBG3"):
times = []
failures = []
for image_url in IMAGES:
status, elapsed = time_one(image_url, model)
if status == 200:
times.append(elapsed)
else:
failures.append(status)
time.sleep(1.1) # stay under 60 requests per minute
print(model, "ok =", len(times), "failed =", len(failures), failures)
if times:
print(model,
"p50 =", round(statistics.median(times), 2),
"p95 =", round(percentile(times, 0.95), 2))The endpoint, header, and the image, model and sync fields are the ones in Bria's remove background reference. Replace the sample URL with a list of your own public image URLs. The script prints the count of failed calls and their statuses next to p50 and p95, so errors are reported and never dropped. It was syntax-checked but not run against the live API for this guide, so treat the printed numbers as yours to verify. The RMBG3 run holds the connection open for the whole request, because sync is set to true. Bria's docs say to keep the default sync: false for RMBG 3.0, so treat that run as your own measurement, not as a documented figure.
Which models and plan limits matter when you test?
RMBG 2.0 has a documented time, and the plan limit sets how fast you may send requests.
Item: RMBG 2.0 per-image time; Value: Returns in under a second; Source: Bria remove background docs
Item: Free plan limit; Value: 10 requests per minute per endpoint; Source: Bria rate limits docs
Item: Pay-as-you-go limit; Value: 60 requests per minute per endpoint; Source: Bria rate limits docs
Item: Enterprise limit; Value: 1000, customizable; Source: Bria rate limits docs
Source: Bria remove background docs and Bria rate limits and errors, read 2026-12-02. RMBG 2.0 is the default model and RMBG 3.0 is selected with "model": "RMBG3".
On the Free plan, change the sleep in the script to 6.5 seconds, which keeps the run under 10 requests per minute. A request with a prompt takes about 15 to 20 seconds per the docs, and RMBG3 cannot be combined with prompt, and a request with both returns 422, so leave prompt out of a comparison between RMBG2 and RMBG3.
How do you add other APIs to the same test?
Wrap each vendor in a function that returns the status and the elapsed time, then feed all of them the same image list.
Same images: Every API must see the same files, at the same sizes.
Same order: Alternate APIs per image, or shuffle, so a network slow patch does not hit only one.
Same measure: Time until the finished result, not until the first byte.
Own limits: Read each vendor's limits first. Clipdrop states 60 requests per minute per API key by default.
Sync rules: Leonardo.Ai says its sync request may take up to about 27 seconds before it times out.
For a vendor that only offers an async flow, time from submit until the poll returns the finished result. The Bria Python SDK sample uses client.poll(job, interval=2, timeout=120), and a 2 second interval adds up to 2 seconds of measurement error.
How do you read the results?
Compare p50 for typical speed and p95 for worst-case speed, and discard any API that returns errors on your images.
Result pattern: p50 near the documented time; What it means: The API behaves as documented; What to do: Compare p95
Result pattern: p95 several times the p50; What it means: Slow calls are common; What to do: Check image sizes and retries
Result pattern: Many non-200 statuses; What it means: You hit a limit or a format rule; What to do: Lower the rate or fix the input
Result pattern: p50 far above the documented time; What it means: Network or size effect; What to do: Test from your production region
Source: author guidance based on the measurement method above.
Latency is one axis. In Bria's benchmark, RMBG 3.0 ranked first of 6 models with an average rank of 1.51 across 234 hard images (benchmark), so speed and quality belong in the same decision.
What mistakes make latency tests wrong?
The common mistakes are testing one image, ignoring rate limits and mixing sync and async timings.
Running one image and calling it a result.
Sending requests faster than the plan allows, then timing 429 responses.
Comparing a sync call to an async call without adding the polling time.
Testing with tiny images when production uses large ones.
Timing the download of the finished image in one API and not another.





