RemBG బ్యాక్గ్రౌండ్ రిమూవల్ API – డెవలపర్ డాక్స్ & ఇంటిగ్రేషన్ గైడ్
పూర్తి APIని అన్వేషించండి—నిజమైన అభ్యర్థనలను మీ బ్రౌజర్లో అమలు చేయండి
ప్రతి ఎండ్ పాయింట్, పారామీటర్లు మరియు ప్రతిస్పందనలను బ్రౌజ్ చేయండి. మీ API కీతో అభ్యర్థనలను ప్రయత్నించండి, ఆపై ఎప్పుడైనా /api/openapi వద్ద ముడి స్పెక్ను పొందండి.
ఇంటరాక్టివ్ సూచనను ప్రారంభించండిrembg.js యొక్క ఇన్స్టాలేషన్
npm i @remove-background-ai/rembg.js
API Reference for rembg.js
@remove-background-ai/rembg.js is a zero-config Node.js wrapper for the free Rembg API, enabling background removal with simple, customizable parameters.
Parameters for RemBG.js
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
| apiKey | string | Required | – | Your Rembg API key |
| inputImage | string | Buffer | { base64: string } | Required | – | Image file, buffer, or base64 payload |
| onDownloadProgress | (event) => void | Optional | – | Hook for upload progress events |
| onUploadProgress | (event) => void | Optional | – | Hook for download progress events |
| options.format | webp (default) | png | Optional | webp | Specifies the output image format. Either "webp" (default) or "png" |
| options.returnBase64 | boolean | Optional | false | Return Base64 string instead of file |
| options.returnMask | boolean | Optional | false | Return only the alpha mask |
| options.w | number | Optional | – | Target width (maintains aspect ratio) |
| options.h | number | Optional | – | Target height (maintains aspect ratio) |
| options.exact_resize | boolean | Optional | false | Force exact width × height (may distort) |
| options.angle | number | Optional | 0 | Rotation angle in degrees |
| options.expand | boolean | Optional | true | Add padding so rotated images aren’t cropped |
| options.bg_color | string | Optional | - | Optional solid background color in hex (e.g. #FFFFFFFF) or named color (e.g. "red", "blue") |
మీ పర్యావరణాన్ని సెటప్ చేయడం: మీ ప్రాజెక్ట్ రూట్లో మీ API కీని కలిగి ఉన్న .env ఫైల్ ఉందని నిర్ధారించుకోండి.
అవసరమైన మాడ్యూల్లను దిగుమతి చేస్తోంది: @remove-background-ai/rembg.js నుండి rembg ఫంక్షన్ను మరియు ఎన్విరాన్మెంట్ వేరియబుల్లను నిర్వహించడానికి dotenv మాడ్యూల్ను దిగుమతి చేయడం ద్వారా ప్రారంభించండి.
ప్రోగ్రెస్ కాల్బ్యాక్లను కాన్ఫిగర్ చేస్తోంది: ఫైల్ కార్యకలాపాల పురోగతిని ట్రాక్ చేయడానికి లైబ్రరీ ఆన్డౌన్లోడ్ప్రోగ్రెస్ మరియు ఆన్అప్లోడ్ప్రోగ్రెస్ కాల్బ్యాక్లను అందిస్తుంది. అందించిన ఉదాహరణలో, మేము ఈ ఈవెంట్లను నేరుగా కన్సోల్కి లాగిన్ చేస్తున్నాము.
ఇప్పుడు, నమూనా వినియోగాన్ని నిశితంగా పరిశీలిద్దాం:
// script.mjs file
import { rembg } from '@remove-background-ai/rembg.js';
import dotenv from 'dotenv';
// Load environment variables from .env file
dotenv.config();
// API_KEY will be loaded from the .env file
const API_KEY = process.env.API_KEY;
// log upload and download progress
const onDownloadProgress = console.log;
const onUploadProgress = console.log;
rembg({
apiKey: API_KEY,
inputImage: './input.png', //inputImage can be one of these: string | Buffer | { base64: string };
onDownloadProgress,
onUploadProgress
}).then(({ outputImagePath, cleanup }) => {
console.log('✅🎉 background removed and saved under path=', outputImagePath);
// if called, it will cleanup (remove from disk) your removed background image
// cleanup();
});
గుర్తుంచుకోండి, మీరు నేపథ్యాన్ని తీసివేసిన తర్వాత మీ డిస్క్ నుండి ప్రాసెస్ చేయబడిన చిత్రాన్ని తీసివేయాలనుకుంటే క్లీనప్ ఫంక్షన్ని పిలవవచ్చు.
ప్రోగ్రెస్ బార్ని చూపుతోంది
నేపథ్య తొలగింపు సేవను ఏకీకృతం చేస్తున్నప్పుడు, వినియోగదారులకు వారి అప్లోడ్ లేదా డౌన్లోడ్ అభ్యర్థన పురోగతిపై అభిప్రాయాన్ని అందించడం తరచుగా ప్రయోజనకరంగా ఉంటుంది. దీన్ని సులభతరం చేయడానికి, మీరు మీ స్వంత onDownloadProgress మరియు onUploadProgress కాల్బ్యాక్లను నిర్వచించవచ్చు. ఈ రెండు కాల్బ్యాక్లు AxiosProgressEventని ఈవెంట్ పారామీటర్గా అంగీకరిస్తాయి. అభ్యర్థన కొనసాగుతుండగా, ఈ కాల్బ్యాక్లు అనేకసార్లు అమలు చేయబడతాయి, ఉదాహరణకు, ప్రోగ్రెస్ బార్ను ప్రదర్శించడానికి మరియు పురోగతి ఆధారంగా దాని పొడవును సర్దుబాటు చేయడానికి మిమ్మల్ని అనుమతిస్తుంది.
(base) root@DESKTOP-C0Q8KK7:~/rembg.js-test# node index.mjs
{
loaded: 65687,
total: 68474,
progress: 0.9592984198381868, <---- @95% progress
bytes: 65687,
rate: undefined,
estimated: undefined,
upload: true <---- upload progress
}
{
loaded: 68474,
total: 68474,
progress: 1, <---- @100% progress
bytes: 2787,
rate: undefined,
estimated: undefined,
upload: true <---- upload progress
}
{
loaded: 1002,
total: 68824,
progress: 0.014558874811112402, <---- @1% progress
bytes: 1002,
rate: undefined,
estimated: undefined,
download: true <---- download progress
}
{
loaded: 68824,
total: 68824,
progress: 1, <---- @100% progress
bytes: 67822,
rate: undefined,
estimated: undefined,
download: true <---- download progress
}
✅🎉 background removed and saved under path=/tmp/rembg--3339-DBqqeJ2eOs4D-.png
Curl
# Full example: upload an image and remove its background with all optional parameters curl -X POST "https://api.rembg.com/rmbg" -H "x-api-key: YOUR_API_KEY_HERE" # your personal API key -F "image=@/path/to/image.jpg" # input image file -F "format=webp" # output format: webp (default) or png -F "w=800" # target width in pixels (maintains aspect ratio unless exact_resize=true) -F "h=600" # target height in pixels -F "exact_resize=false" # true = force exact w × h, may distort -F "mask=false" # true = return only the alpha mask instead of full image -F "bg_color=#ffffffff" # optional solid background color (RGBA hex) -F "angle=0" # rotate the image by given degrees after processing -F "expand=true" # add padding so rotated images don’t get cropped
HTTP
POST /rmbg HTTP/1.1
Host: api.rembg.com
x-api-key: YOUR_API_KEY_HERE
Content-Type: multipart/form-data; boundary=----BOUNDARY
------BOUNDARY
Content-Disposition: form-data; name="image"; filename="image.jpg"
Content-Type: image/jpeg
<binary data of your image goes here>
------BOUNDARY
Content-Disposition: form-data; name="format"
webp
------BOUNDARY
Content-Disposition: form-data; name="w"
800
------BOUNDARY
Content-Disposition: form-data; name="h"
600
------BOUNDARY
Content-Disposition: form-data; name="exact_resize"
false
------BOUNDARY
Content-Disposition: form-data; name="mask"
false
------BOUNDARY
Content-Disposition: form-data; name="bg_color"
#ffffffff
------BOUNDARY
Content-Disposition: form-data; name="angle"
0
------BOUNDARY
Content-Disposition: form-data; name="expand"
true
------BOUNDARY--
Python Requests
import requests
# Endpoint URL for the background-removal API
url = "https://api.rembg.com/rmbg"
# Required API key header
headers = {
"x-api-key": "YOUR_API_KEY_HERE"
}
# The image file to process (opened in binary mode)
files = {
"image": open("/path/to/image.jpg", "rb")
}
# Optional form fields supported by your backend.
# Adjust values as needed; any of these can be omitted.
data = {
"format": "webp", # Output format: "webp" (default) or "png"
"w": 800, # Target width (maintains aspect ratio unless exact_resize is true)
"h": 600, # Target height
"exact_resize": "false", # "true" forces exact w×h, may distort
"mask": "false", # "true" returns only the alpha mask
"bg_color": "#ffffffff", # Optional solid background color (RGBA hex)
"angle": 0, # Rotation angle in degrees
"expand": "true", # Add padding so rotated images aren’t cropped
}
# Send the POST request with headers, file, and extra form data
response = requests.post(url, headers=headers, files=files, data=data)
# Handle the response
if response.status_code == 200:
# Save the processed image to disk
with open("output.webp", "wb") as f:
f.write(response.content)
print("Background removed successfully → saved as output.webp")
else:
# Print error details if the request failed
print("Error:", response.status_code, response.text)
సభ్యత్వం & క్రెడిట్ల వినియోగం
మీ ప్లాన్ లేబుల్, చేర్చబడిన మరియు ప్రీపెయిడ్ క్రెడిట్ బ్యాలెన్స్లు మరియు వినియోగాన్ని అందిస్తుంది. మీరు UTC క్యాలెండర్ నెల (లెగసీ), గీతతో సమలేఖనం చేయబడిన బిల్లింగ్ వ్యవధి (పునరుద్ధరణ ద్వారా పర్యవేక్షించడం కోసం) ద్వారా లేదా తెలిసిన బిల్లింగ్ వ్యవధిని జాబితా చేయవచ్చు. మీ API కీతో మాత్రమే ప్రమాణీకరించండి.
స్కీమాలు, ఉదాహరణలు మరియు ట్రై-ఇట్ కన్సోల్ కోసం, పూర్తి సూచనలో అదే ముగింపు పాయింట్ని చూడండి: API డాక్స్ తెరవండి
ఎండ్పాయింట్
GET https://www.rembg.com/api/membership-usageప్రమాణీకరణ
మీ API కీని పంపండి: హెడర్ x-api-కీ: YOUR_API_KEY_HERE (rembg.comలో మీ ప్రొఫైల్లో కీలను సృష్టించండి మరియు నిర్వహించండి).
ప్రశ్న పరామితులు
| పరామితి | రకం | వివరణ |
|---|---|---|
| year | number | క్యాలెండర్ సంవత్సరం (1–9999). నెలతో పాటు, Redis కీల వినియోగదారుని చదువుతుంది:{uid}:app_usage:{year}:{month}. విస్మరించబడితే (మరియు periodStartUnix ఉపయోగించబడదు), ప్రస్తుత UTC సంవత్సరానికి డిఫాల్ట్ అవుతుంది. |
| month | number (1–12) | క్యాలెండర్ నెల 1–12 (కీల కోసం UTC కన్వెన్షన్ ఉపయోగించబడుతుంది). విస్మరించబడితే, ప్రస్తుత UTC నెలకు డిఫాల్ట్ అవుతుంది. |
| periodStartUnix | number | సెకన్లలో Unix టైమ్స్టాంప్: బిల్లింగ్ విండో ప్రారంభం. వినియోగదారుని చదువుతుంది:{uid}:app_usage:cycle:{periodStartUnix} మరియు api_usage:cycle:…. సంవత్సరం లేదా నెలతో కలపడం సాధ్యం కాదు. |
| expand | string | కామాతో వేరు చేయబడిన జెండాలు. బిల్లింగ్సైకిల్ ఆబ్జెక్ట్ని జోడించడానికి బిల్లింగ్_సైకిల్ని చేర్చండి: Redisలో బిల్లింగ్_పీరియడ్_* ఉన్న ప్రస్తుత స్ట్రిప్ పీరియడ్, లేకపోతే ప్రస్తుత UTC క్యాలెండర్ నెల. నిర్దిష్ట విండో కోసం periodStartUnixతో కూడా పని చేస్తుంది. |
| includeBillingCycle | 1 / true | బిల్లింగ్_సైకిల్ని కలిగి ఉన్న విస్తరణకు సమానం: బిల్లింగ్సైకిల్ ఆబ్జెక్ట్ని చేర్చడానికి 1కి లేదా ఒప్పుకు సెట్ చేయబడింది. |
| listBillingCycles | 1 / true | అంకితమైన మోడ్: listBillingCycles=1 లేదా నిజమైన రిటర్న్లు మాత్రమే {billingCycles: [...] }. ఈ వినియోగదారు కోసం సైకిల్ కీల కోసం Redisని స్కాన్ చేస్తుంది; ఈ అభ్యర్థనపై ఇతర ప్రశ్న పారామితులు విస్మరించబడ్డాయి. |
సంవత్సరం లేదా నెలతో పాటు StartUnix వ్యవధిని పాస్ చేయవద్దు - API 400ని అందిస్తుంది. జాబితాబిల్లింగ్సైకిల్స్ మోడ్ వేరుగా ఉంటుంది మరియు ఇతర పారామ్లను విస్మరిస్తుంది.
జాబితా బిల్లింగ్ వ్యవధి
గత మరియు ప్రస్తుత సబ్స్క్రిప్షన్ విండోల డ్రాప్డౌన్ను పూరించడానికి దీన్ని ఉపయోగించండి (ప్రతి ఎంట్రీ పీరియడ్స్టార్ట్యూనిక్స్ మీరు పీరియడ్స్టార్ట్యూనిక్స్=…తో తిరిగి పాస్ చేయవచ్చు). పీరియడ్ ముగింపు సమయాలు ఊహించబడ్డాయి (తదుపరి పీరియడ్ ప్రారంభం - 1, లేదా యాక్టివ్ పీరియడ్ కోసం స్ట్రిప్ కరెంట్_పీరియడ్_ఎండ్).
curl --location 'https://www.rembg.com/api/membership-usage?listBillingCycles=1' \ --header 'x-api-key: YOUR_API_KEY_HERE'
ఉదాహరణ ప్రతిస్పందన
{
"billingCycles": [
{
"periodStartUnix": 1774268612,
"periodEndUnix": 1776947012,
"appUsage": 120,
"apiUsage": 880
}
]
}ముందుగా సరికొత్త వ్యవధి క్రమబద్ధీకరించబడింది. సైకిల్ యూసేజ్ కీ ఉన్నట్లయితే లేదా అది స్ట్రైప్ వెబ్హూక్స్ నుండి ప్రస్తుత బిల్లింగ్_పీరియడ్_స్టార్ట్ అయితే పిరియడ్ కనిపిస్తుంది.
బిల్లింగ్ సైకిల్ ఆబ్జెక్ట్
బిల్లింగ్_సైకిల్ను విస్తరించినప్పుడు లేదా బిల్లింగ్సైకిల్ని చేర్చినప్పుడు ప్రదర్శించండి. డాష్బోర్డ్ల కోసం దీన్ని ఉపయోగించండి: పునరుద్ధరణ సరిహద్దు, విండోలో వినియోగం మరియు మిగిలిన క్రెడిట్లు.
| ఫీల్డ్ | వివరణ |
|---|---|
| periodStartUnix | బిల్లింగ్ విండో ప్రారంభం (యూనిక్స్ సెకన్లు). ఖాతా సమకాలీకరించబడినప్పుడు గీత కరెంట్_పీరియడ్_స్టార్ట్తో సరిపోలుతుంది. |
| periodEndUnix | ప్రస్తుత విండో ముగింపు (యూనిక్స్ సెకన్లు), అంటే తదుపరి పునరుద్ధరణకు ముందు — సమకాలీకరించబడినప్పుడు స్ట్రిప్ current_period_end. చందా రద్దు తేదీకి సమానం కాదు. |
| appUsage / apiUsage | ఈ విండోలో చేర్చబడిన క్రెడిట్ వినియోగం లెక్కించబడుతుంది: web/editor (app) vs API కీ (api). ఉపయోగించినIncludedCredits వాటి మొత్తానికి సమానం. |
| includedCredits | Redisలో నిల్వ చేయబడిన మీ చేర్చబడిన (ప్లాన్) క్రెడిట్ భత్యం (అత్యున్నత స్థాయి క్రెడిట్ల మాదిరిగానే). |
| prepaidCredits | ప్రీపెయిడ్ (కొనుగోలు) బ్యాలెన్స్; ప్రతి బిల్లింగ్ వ్యవధిని రీసెట్ చేయదు. |
| usedIncludedCredits | విండోలో మొత్తం చేర్చబడిన వినియోగం (యాప్ + API). ప్రీపెయిడ్ వినియోగం ఇక్కడ జోడించబడలేదు. |
| remainingIncludedCredits | గరిష్టం(0, చేర్చబడిన క్రెడిట్లు − ఉపయోగించబడినవి. |
| stripeBillingSynced | Redis స్ట్రైప్ నుండి బిల్లింగ్_period_start/end ఉన్నప్పుడు నిజం కాబట్టి విండో మీ సభ్యత్వానికి సరిపోలుతుంది; తప్పు అంటే ఈ బ్లాక్ కోసం API UTC క్యాలెండర్ నెలకు తిరిగి వచ్చింది. |
స్ట్రైప్ వెబ్హూక్స్ వినియోగదారు కోసం బిల్లింగ్ వ్యవధిని వ్రాసే వరకు, స్ట్రిప్బిల్లింగ్సింక్డ్ తప్పు కావచ్చు మరియు బిల్లింగ్సైకిల్ విండో UTC క్యాలెండర్ నెలను అనుసరిస్తుంది. సమకాలీకరణ తర్వాత, ఇమేజ్ APIలో వినియోగ పరిమితులు అదే సైకిల్ కీలతో సమలేఖనం చేయబడతాయి.
“తదుపరి పునరుద్ధరణకు ముందు ఉపయోగించిన క్రెడిట్ల” కోసం, Expand=billing_cycleతో కాల్ చేసి, billingCycle.periodEndUnixని పునరుద్ధరణ సరిహద్దుగా ఉపయోగించండి, billingCycle.usedIncludedCredits (లేదా appUsage + apiUsage), మరియు billingCycle.remainingIncludedCredits. మీకు మొత్తం డిస్పోజబుల్ బ్యాలెన్స్ కావాలంటే ప్రీపెయిడ్ క్రెడిట్లను జోడించండి.
ఉదాహరణలు (cURL)
నిర్దిష్ట UTC క్యాలెండర్ నెల కోసం వినియోగం
curl --location 'https://www.rembg.com/api/membership-usage?year=2026&month=3' \ --header 'x-api-key: YOUR_API_KEY_HERE'
ప్రస్తుత బిల్లింగ్ సైకిల్ + పూర్తి బిల్లింగ్ సైకిల్ బ్లాక్ (సమకాలీకరించినప్పుడు పునరుద్ధరణ-సమలేఖనం చేయబడింది)
# Current subscription window + usage (renewal-aligned when Stripe is synced) curl --location 'https://www.rembg.com/api/membership-usage?expand=billing_cycle' \ --header 'x-api-key: YOUR_API_KEY_HERE'
పిరియడ్ ప్రారంభం వారీగా ఒక చారిత్రక బిల్లింగ్ విండో (జాబితా బిల్లింగ్ సైకిల్స్ లేదా స్ట్రిప్ నుండి)
# Specific billing period by Stripe period start (unix seconds) curl --location 'https://www.rembg.com/api/membership-usage?periodStartUnix=1774268612&expand=billing_cycle' \ --header 'x-api-key: YOUR_API_KEY_HERE'
ఉదాహరణ JSON (బిల్లింగ్ సైకిల్తో)
అత్యున్నత స్థాయి యాప్_ఉపయోగం మరియు api_usage ఎల్లప్పుడూ అభ్యర్థించిన క్యాలెండర్ నెల లేదా, periodStartUnix సెట్ చేయబడినప్పుడు, ఆ సైకిల్ కౌంటర్లను ప్రతిబింబిస్తాయి. Expand=billing_cycle విస్మరించబడినప్పుడు, billingCycle ఉండదు.
{
"membership": "Premium-20000",
"credits": 18500,
"prepaidCredits": 2000,
"app_usage": 8500,
"api_usage": 10000,
"billingCycle": {
"periodStartUnix": 1740441600,
"periodEndUnix": 1743033599,
"appUsage": 4200,
"apiUsage": 5100,
"includedCredits": 18500,
"prepaidCredits": 2000,
"usedIncludedCredits": 9300,
"remainingIncludedCredits": 9200,
"stripeBillingSynced": true
}
}స్ట్రైప్బిల్లింగ్సింక్డ్ నిజమైతే, బిల్లింగ్సైకిల్ బ్యాక్గ్రౌండ్-రిమూవల్ APIలో ఎన్ఫోర్స్మెంట్తో సరిపోలుతుంది. తప్పు అయితే, క్యాలెండర్ నెల ఫీల్డ్లపై ఆధారపడండి లేదా వెబ్హూక్స్ Redisలో బిల్లింగ్_పీరియడ్_*ని నింపే వరకు వేచి ఉండండి.
Error Responses
All error responses return a JSON body with a status field matching the HTTP status code.
Multiple Validation Errors Response
HTTP/1.1 400 Bad Request
HTTP/1.1 400 Bad Request
Content-Type: application/json
{
"error": "Multiple validation errors",
"details": [
{ "field": "w", "message": "'w' must be an integer, got: 'abc'" },
{ "field": "angle", "message": "'angle' must be between -360 and 360 degrees, got: 500.0" }
],
"status": 400
}Error Reference
| Scenario | Status | Error Message |
|---|---|---|
| No image provided | 400 | No image file provided. Please include an 'image' field in your form data. |
| No file selected | 400 | No file selected. Please choose an image file to upload. |
| Unsupported file type | 400 | File type '.exe' is not supported. Allowed formats: webp, bmp, png, jpg, jpeg |
| Corrupt image | 400 | File does not appear to be a valid image (invalid file signature) |
| Empty file (0 bytes) | 400 | Uploaded file is empty (0 bytes). |
| File too large | 400 | File size (55.2 MB) exceeds the maximum allowed size of 50 MB. |
| Image too wide | 400 | Image width (12000px) exceeds the maximum allowed width of 10000px. |
| Image too tall | 400 | Image height (15000px) exceeds the maximum allowed height of 10000px. |
| Bad w or h value | 400 | 'w' must be an integer, got: 'abc' |
| w or h out of range | 400 | 'w' must be at least 1, got: -5 |
| w or h above max | 400 | 'w' must be at most 10000, got: 15000 |
| Bad angle | 400 | 'angle' must be a number, got: 'ninety' |
| Angle out of range | 400 | 'angle' must be between -360 and 360 degrees, got: 500.0 |
| Bad output format | 400 | Invalid format 'gif'. Allowed formats: PNG, JPEG, WEBP, BMP |
| Bad bg_color | 400 | Invalid color format '#12345'. Use hex format: #RGB, #RGBA, #RRGGBB, or #RRGGBBAA |
| mask + bg_color conflict | 400 | Cannot use 'mask=true' together with 'bg_color'. Choose one or the other. |
| Email not verified | 403 | Email address not verified – please check your inbox |
| Invalid API key | 401 | invalid api key |
| Both API key and user token sent | 400 | This is a mistake: Cannot use both API key and user token |
| Rate limit exceeded (short-term) | 429 | You're making requests too quickly, Please Upgrade or slow down. |
| Rate limit exceeded (daily, anonymous) | 429 | You've reached your daily limit. Please sign up for more access. |
| Rate limit exceeded (monthly, authenticated) | 429 | You've reached your monthly limit. Consider purchasing more credits. |
Error Handling Guidelines
- Check HTTP status code 400 to identify validation errors
- Parse the
errorfield for the error message - Check for the
detailsarray when handling multiple validation errors - Use the
fieldproperty to map errors to specific request parameters