Background removal, one HTTP call away.
Send an image, get a clean transparent PNG back. The same model that powers bgclear.ai — free previews, 1 credit per full-resolution image, async jobs for big files, batches of 50.
Overview
Base URL https://www.bgclear.ai/api/v1. All endpoints are versioned under /api/v1 and will never break — new fields are only ever added. Requests and responses are JSON unless you upload a file (multipart) or download a result (binary image).
- Sync —
POST /removereturns the finished image in one call (up to 4 MP, 30 s). - Async —
POST /jobsfor larger images or callbacks; pollGET /jobs/{id}. - Batch —
POST /jobs/batchqueues up to 50 images at once. - Credits — previews are free; a full-resolution result costs 1 credit, charged only on success.
Authentication
Create a key on your API dashboard and send it as a Bearer token. Keys look like bgc_live_… (or bgc_test_…). They are shown once at creation and stored hashed — if you lose one, revoke it and create another.
Authorization: Bearer bgc_live_YOUR_KEYYour first key comes with 10 free credits. Buy more on the pricing page; they never expire.
Quick start
Remove the background from a local file and save the transparent PNG:
curl -X POST https://www.bgclear.ai/api/v1/remove \
-H "Authorization: Bearer bgc_live_YOUR_KEY" \
-F "[email protected]" \
-F "size=full" \
-o result.pngThat's it. size=full returns native resolution and costs 1 credit; drop it (or use size=preview) for a free 800 px preview while you build.
Remove a background (sync)
POST/api/v1/remove
Accepts multipart/form-data or application/json. Provide exactly one image source: image_file (binary upload), image_url (public URL) or image_file_b64 (base64). Returns the image bytes by default; send Accept: application/json to get metadata and a download URL instead.
JSON body + JSON response
curl -X POST https://www.bgclear.ai/api/v1/remove \
-H "Authorization: Bearer bgc_live_YOUR_KEY" \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-d '{"image_url": "https://example.com/photo.jpg", "size": "full", "format": "webp", "bg_color": "ffffff"}'{
"id": "0b2e5f1c-9a3d-4f2e-b8c1-6d7e8f9a0b1c",
"url": "https://www.bgclear.ai/api/v1/results/0b2e5f1c-9a3d-4f2e-b8c1-6d7e8f9a0b1c",
"width": 1600,
"height": 1067,
"credits_charged": 1,
"credits_remaining": 499,
"processing_ms": 1840
}Idempotent retries
Send an Idempotency-Key header (any unique string, e.g. a UUID). Retrying with the same key within 24 hours returns the cached result and never charges twice.
Images over 4 MP at size=full are rejected with invalid_request — use async jobs for those. See parameters for the full list.
Async jobs
POST/api/v1/jobs
Same inputs and parameters as /remove, but the image is queued and processed by a GPU worker. Use it for images over 4 MP, when you don't want to hold a connection open, or when you want a callback. Returns 202 with a job_id. Add an X-Callback-Url header to be notified on completion.
curl -X POST https://www.bgclear.ai/api/v1/jobs \
-H "Authorization: Bearer bgc_live_YOUR_KEY" \
-H "X-Callback-Url: https://yourapp.com/hooks/bgclear" \
-F "[email protected]" \
-F "size=full"If the queue is saturated you get 503 gpu_unavailable with a Retry-After header instead of an unbounded wait.
Job status
GET/api/v1/jobs/{job_id}
status is one of queued, processing, done or failed. When done, the response includes url (the result image), credits_charged and credits_remaining. When failed, it includes error and nothing was charged.
curl https://www.bgclear.ai/api/v1/jobs/JOB_ID \
-H "Authorization: Bearer bgc_live_YOUR_KEY"Batch jobs
POST/api/v1/jobs/batch
JSON only. Pass up to 50 images in images (each with image_url or image_file_b64). Top-level parameters like size or format apply to every image; per-image keys override them. One job is created per image and you get all the ids back.
curl -X POST https://www.bgclear.ai/api/v1/jobs/batch \
-H "Authorization: Bearer bgc_live_YOUR_KEY" \
-H "Content-Type: application/json" \
-d '{
"size": "full",
"format": "png",
"images": [
{"image_url": "https://example.com/a.jpg"},
{"image_url": "https://example.com/b.jpg"},
{"image_file_b64": "<base64 data>"}
]
}'Callbacks (webhooks)
When a job finishes, we POST the result to your X-Callback-Url. Delivery is retried 3 times with exponential backoff on network errors or 5xx responses. Respond with any 2xx.
POST https://yourapp.com/hooks/bgclear
Content-Type: application/json
X-Bgclear-Signature: sha256=<hex HMAC-SHA256 of the raw body>
{
"job_id": "0b2e5f1c-9a3d-4f2e-b8c1-6d7e8f9a0b1c",
"status": "done",
"url": "https://www.bgclear.ai/api/v1/results/0b2e5f1c-9a3d-4f2e-b8c1-6d7e8f9a0b1c",
"credits_charged": 1,
"credits_remaining": 498
}The X-Bgclear-Signature header carries an HMAC-SHA256 of the raw body. Per-key signing secrets are on the roadmap; until then treat the callback as a hint and confirm with GET /jobs/{id} before acting on it.
Account
GET/api/v1/account
Your current credit balance, plan and credits used this calendar month.
curl https://www.bgclear.ai/api/v1/account -H "Authorization: Bearer bgc_live_YOUR_KEY"Usage
GET/api/v1/usage
Credits used per day for the last 30 days, newest first.
curl https://www.bgclear.ai/api/v1/usage -H "Authorization: Bearer bgc_live_YOUR_KEY"Parameters
Shared by /remove, /jobs and /jobs/batch. Send them as form fields or JSON keys.
| Parameter | Values | Notes |
|---|---|---|
image_file | binary (multipart) | The image. Exactly one of image_file, image_url, image_file_b64 is required. |
image_url | string | Publicly reachable http(s) URL. Private and link-local addresses are blocked. |
image_file_b64 | string | Base64-encoded image bytes. |
size | preview · full · auto | Default preview. preview = free, longest side ≤ 800 px. full = native resolution, 1 credit. auto = full when ≤ 4 MP, otherwise preview. |
format | png · webp · jpg | Default png. jpg has no alpha — combine it with bg_color. |
bg_color | transparent · hex | Default transparent. A hex color (ffffff or #ffffff) flattens the cutout onto that background. |
crop | true · false | Default false. Crops the result to the subject’s bounding box. |
type | auto · person · product | Optional hint, accepted for remove.bg compatibility. The model detects the subject automatically. |
Headers
Request
| Header | Notes |
|---|---|
Authorization | Bearer <api key>. Required on every call. |
Accept | application/json on /remove to receive JSON metadata + URL instead of image bytes. |
Idempotency-Key | Any unique string. Same key within 24 h → cached response, no second charge. |
X-Callback-Url | On /jobs and /jobs/batch: URL to POST the result to when done. |
Response
| Header | Notes |
|---|---|
X-Credits-Charged | Credits deducted by this call (0 or 1). |
X-Credits-Remaining | Your balance after this call. |
X-RateLimit-Limit | Requests allowed per minute for this key. |
X-RateLimit-Remaining | Requests left in the current window. |
X-RateLimit-Reset | Unix timestamp when the window resets. |
X-Job-Id | On /remove: the id of this removal (also usable with the download URL). |
Retry-After | On 429 / 503: seconds to wait before retrying. |
Errors
Every non-2xx response has the same shape, so one error handler covers the whole API:
HTTP/1.1 402 Payment Required
Content-Type: application/json
{
"error": {
"code": "insufficient_credits",
"message": "Insufficient credits. Buy credits at https://www.bgclear.ai/api-pricing/",
"docs": "https://www.bgclear.ai/api-docs/"
}
}| Code | HTTP | Meaning |
|---|---|---|
invalid_api_key | 401 | Missing, malformed, unknown or revoked key. |
insufficient_credits | 402 | Balance is 0 and size=full was requested. Previews still work. |
rate_limited | 429 | Over the per-key limit. Back off for Retry-After seconds. |
invalid_request | 400 / 422 | Bad or missing parameter, more than one image source, blocked URL, >4 MP at size=full. |
unsupported_format | 400 | The bytes are not a decodable image (JPEG, PNG, WebP, GIF, BMP, TIFF). |
image_too_large | 400 | Over 25 MB or 50 megapixels. |
no_subject_detected | 422 | The model could not find a foreground subject. |
processing_failed | 500 / 504 | Model error or the 30 s sync timeout. Nothing was charged. |
gpu_unavailable | 503 | Queue is full. Retry after Retry-After seconds. |
Limits & rate limits
- Max upload 25 MB, max 50 megapixels.
- Sync
/remove: up to 4 MP atsize=full; hard timeout 30 s. Larger →/jobs. - Batch: 50 images per request.
- Rate limit: 60 requests / minute per key (sliding window). Need more? Ask via the feedback form in the footer.
- Result URLs (
/api/v1/results/{id}, no auth needed) stay valid for 24 hours — keep your own copy.
Migrating from remove.bg
Field names match remove.bg so most integrations only need a new base URL and key: image_file, image_url, image_file_b64, size, bg_color, crop, type, format.
| Difference | bgclear | Why |
|---|---|---|
| Auth header | Authorization: Bearer … instead of X-Api-Key | Standard bearer auth works with every HTTP client and proxy out of the box. |
| size values | preview · full · auto | Two clear price points (free / 1 credit) rather than five resolution tiers. |
| format | png · webp · jpg (no auto) | You always know which bytes you get back; add bg_color for jpg. |
| Not supported | channels, roi, scale, position, bg_image_url | Rarely used; compositing is easier to do client-side with the transparent PNG. |
| JSON response | via Accept: application/json | One endpoint, two response styles — no separate URL to remember. |
Questions or a feature you need? Use the feedback form in the footer — it goes straight to the people who built this.