Background Remover API: A Developer's Guide
Everything you need to integrate the background removal API: authentication, the request and response format, synchronous waits versus polling, rate limits, credits and production best practices.

If background removal is part of your product — a marketplace, a print-on-demand store, a photo app or an internal content pipeline — doing it by hand doesn't scale. This guide covers everything you need to integrate the BG Removal AI background removal API: authentication, the request and response format, waiting versus polling, rate limits, credits, error handling and production best practices, with working examples in curl, Node.js and Python.
Overview
The API is a small REST interface:
| Method | Endpoint | Purpose |
|---|---|---|
POST | /api/v1/background/remove | Submit an image file or URL for background removal. |
GET | /api/v1/background/jobs/{id} | Check the status of a job. |
GET | /api/v1/background/jobs/{id}/result | Redirect to the finished transparent PNG. |
GET | /api/v1/account | Your plan, remaining credits, credit cost per call and rate limit. |
All responses are JSON. Successful responses wrap their payload in a data object; errors return an error object with a machine-readable code, a human-readable message and a request_id you can quote to support. The full reference lives in the API documentation.
Authentication
Create an API key in your dashboard under API keys. API access is included in plans that list it on the pricing page. A key is shown only once when you create it — store it in your secrets manager or environment variables straight away. Only a hash is stored on our side, so a lost key can't be recovered, only replaced.
Send the key with every request, either as a bearer token or in the X-API-Key header:
Authorization: Bearer YOUR_API_KEY
# or
X-API-Key: YOUR_API_KEY
Never call the API from browser or mobile app code. Anyone can read a key embedded in front-end code. Call the API from your server or a serverless function, then pass the result URL or file to your client.
You can create several keys — for example one per environment or per integration — give each a name and an optional expiry date, and revoke any key instantly from the dashboard.
Submitting an image
Send a multipart/form-data request with either:
image— the image file (JPG, PNG, WebP or GIF), orimage_url— a publichttp(s)URL to fetch the image from.
Images are validated by their actual content, not by their file name or declared type, and URLs are fetched server-side with protections that block private and internal network addresses.
Waiting for the result in the same request
Add ?wait=N to wait up to N seconds (maximum 25) for the job to finish. If it finishes in time, you get 200 OK with the finished job and a result_url. If not, you get 202 Accepted with the job's current state and a Location header pointing at the job endpoint, and you continue by polling.
Example: curl
curl -X POST "https://bgremovalai.co/api/v1/background/remove?wait=20" \
-H "Authorization: Bearer $API_KEY" \
-F "image=@product.jpg"
A successful response looks like this:
{
"data": {
"id": "6d1f0c9e-…",
"image_id": "0b7a43d2-…",
"status": "succeeded",
"progress": 100,
"width": 3024,
"height": 4032,
"result_url": "https://bgremovalai.co/api/v1/files/…",
"error_code": "",
"error_message": "",
"credits_charged": 1,
"created_at": "2026-11-14T09:12:03Z",
"finished_at": "2026-11-14T09:12:06Z"
}
}
The status is one of queued, processing, succeeded or failed. The result_url is a signed link to a full-resolution transparent PNG and is valid for 15 minutes — download the file promptly, or request the job again to get a fresh link.
Polling for long jobs
Large images or busy periods may take longer than your wait window. Poll the job endpoint until the status is final:
GET /api/v1/background/jobs/{id}
A polling interval of one to three seconds is plenty. Use the /result endpoint if you'd rather receive a redirect straight to the PNG once the job has succeeded; before that, it returns 409 with the code not_ready.
Example: Node.js (18+)
import { readFile, writeFile } from "node:fs/promises";
const API = "https://bgremovalai.co/api/v1";
const headers = { Authorization: `Bearer ${process.env.API_KEY}` };
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
export async function removeBackground(inputPath, outputPath) {
const form = new FormData();
form.append("image", new Blob([await readFile(inputPath)]), "input.jpg");
let res = await fetch(`${API}/background/remove?wait=20`, { method: "POST", headers, body: form });
let body = await res.json();
if (!res.ok) throw new Error(`${body.error.code}: ${body.error.message}`);
let job = body.data;
while (job.status === "queued" || job.status === "processing") {
await sleep(2000);
res = await fetch(`${API}/background/jobs/${job.id}`, { headers });
job = (await res.json()).data;
}
if (job.status !== "succeeded") throw new Error(`${job.error_code}: ${job.error_message}`);
const png = await fetch(job.result_url);
await writeFile(outputPath, Buffer.from(await png.arrayBuffer()));
}
Example: Python
import os, time, requests
API = "https://bgremovalai.co/api/v1"
HEADERS = {"Authorization": f"Bearer {os.environ['API_KEY']}"}
def remove_background(input_path, output_path):
with open(input_path, "rb") as f:
r = requests.post(f"{API}/background/remove", params={"wait": 20},
headers=HEADERS, files={"image": f}, timeout=60)
if not r.ok:
err = r.json()["error"]
raise RuntimeError(f"{err['code']}: {err['message']}")
job = r.json()["data"]
while job["status"] in ("queued", "processing"):
time.sleep(2)
job = requests.get(f"{API}/background/jobs/{job['id']}",
headers=HEADERS, timeout=30).json()["data"]
if job["status"] != "succeeded":
raise RuntimeError(f"{job['error_code']}: {job['error_message']}")
png = requests.get(job["result_url"], timeout=60)
png.raise_for_status()
with open(output_path, "wb") as out:
out.write(png.content)
Processing an image by URL
curl -X POST "https://bgremovalai.co/api/v1/background/remove?wait=20" \
-H "Authorization: Bearer $API_KEY" \
-F "image_url=https://cdn.example.com/products/mug-blue.jpg"
Credits
Each API call uses credits; GET /api/v1/account tells you the current cost per call and your remaining balance, and every response to a remove request includes an X-Credits-Remaining header. API results are always full resolution. If a job ultimately fails, the credits charged for it are refunded automatically, so you only pay for successful cutouts. When you run out of credits, requests fail with 402 and the code insufficient_credits; top up with a plan upgrade or a credit pack.
Rate limits
Requests are rate-limited per key. Every response includes X-RateLimit-Limit and X-RateLimit-Remaining headers. When you exceed the limit you receive 429 Too Many Requests with the code rate_limited and a Retry-After header in seconds. Your plan sets the default per-minute limit; you can check it with GET /api/v1/account.
Error handling
| Status | Meaning | What to do |
|---|---|---|
| 400 / 415 / 422 | Invalid request or unsupported image | Fix the input; don't retry unchanged. |
| 401 | Missing, invalid, expired or revoked key | Check the key and header. |
| 402 | Not enough credits | Top up with a credit pack or upgrade. |
| 403 | The account's plan no longer includes API access | Upgrade the plan. |
| 409 | Result requested before the job finished | Keep polling. |
| 413 | File too large | Resize before uploading. |
| 429 | Rate limit exceeded | Wait for Retry-After, then retry. |
| 5xx / 503 | Temporary server problem or maintenance | Retry with exponential backoff. |
A job can also finish with status: "failed" — for example if an image can't be decoded. Its error_code and error_message explain why. Transient processing problems are retried automatically on our side before a job is marked as failed.
Production best practices
- Keep keys server-side and rotate them periodically. Use separate keys per environment so you can revoke one without affecting others.
- Retry with backoff on
429and5xx, respectingRetry-After. Don't retry4xxvalidation errors unchanged. - Control concurrency. Process large backlogs with a small worker pool rather than firing thousands of requests at once; stay under your per-minute limit.
- Store results yourself. Result links are short-lived by design. Download the PNG and store it in your own storage or CDN.
- Keep the originals. You may want to re-process them later or create different variants.
- Log request IDs. Error responses include a
request_id; logging it makes support requests quick to resolve. - Resize sensibly. Sending images far larger than you need costs upload time without improving results. Images are processed up to your plan's maximum resolution.
- Monitor usage. The dashboard shows API requests, errors and credits per day for your account.
Testing your integration
- Check your account first. A quick call confirms the key works and shows your balance and limits:
curl "https://bgremovalai.co/api/v1/account" -H "Authorization: Bearer $API_KEY" - Use a small, varied test set — a portrait, a product with a shadow, something with fine detail — and confirm the PNGs have real transparency by placing them on a dark background.
- Test the slow path. Call without
waitto make sure your polling code works, not just the fast path. - Test failure handling with a corrupted file and a URL that returns 404, and check that your code surfaces the
error_code. - Use a separate key for testing so you can revoke it independently, and watch credit usage in the dashboard while you develop.
Typical integrations
- E-commerce: process product photos when they're uploaded to your store, then generate marketplace variants (white background, square canvas) in your own image pipeline.
- Print-on-demand: cut out customer photos before placing them on products.
- Content and marketing tools: offer "remove background" as a feature in your own app — called from your backend.
- Digital asset management: create transparent versions of every new asset automatically.
Privacy and data handling
Images processed through the API are private to your account and deleted automatically after the retention period. They aren't used to train AI models. If you process personal data such as photos of people, make sure your own privacy policy covers sending images to a processing service. See our privacy policy for details.
Summary
Create a key, keep it on your server, and send images to POST /api/v1/background/remove with wait=20 to receive most results in a single request. Poll the job endpoint for anything that takes longer, download the full-resolution PNG from the short-lived result_url, and handle 429 and 5xx responses with backoff. Failed jobs are refunded automatically. The complete reference is in the API documentation.


