API
Same contract the UI uses. OpenAPI live docs: https://api.rembg.site/docs
Auth
Send Authorization: Bearer <key>. Long-lived keys live in the API API_KEYS env (comma-separated). The browser UI uses short-lived JWTs from POST /api/token instead.
POST /v1/remove
- multipart field
file— JPEG, PNG, WebP, or HEIC · max 15MB - optional
crop=true— trim transparent bounds - success:
image/pngwith alpha - errors: JSON
{ error, code, hint }
Cold start (free tier)
The Hugging Face Space sleeps when idle. First request can take 1–2 minutes. Set client timeouts to at least 120 seconds. GET /v1/health returns 503 with code=waking while the model loads. CPU inference after wake is typically 10–40s per image.
curl
curl -X POST "https://api.rembg.site/v1/remove" \
-H "Authorization: Bearer YOUR_API_KEY" \
-F "file=@./photo.jpg" \
--max-time 120 \
-o removed.pngfetch
const form = new FormData();
form.append("file", file); // File / Blob
const res = await fetch("https://api.rembg.site/v1/remove", {
method: "POST",
headers: { Authorization: "Bearer YOUR_API_KEY" },
body: form,
// Free tier cold start: allow at least 120s
signal: AbortSignal.timeout(120_000),
});
if (!res.ok) {
const err = await res.json();
throw new Error(err.error + " — " + err.hint);
}
const png = await res.blob(); // image/png with alpha