RemBG बैकग्राउंड रिमूवल एपीआई - डेवलपर डॉक्स और इंटीग्रेशन गाइड






OpenAPI · लाइव खेल का मैदान

संपूर्ण एपीआई का अन्वेषण करें—अपने ब्राउज़र में वास्तविक अनुरोध चलाएं

प्रत्येक समापन बिंदु, पैरामीटर और प्रतिक्रियाएँ ब्राउज़ करें। अपनी एपीआई कुंजी के साथ अनुरोधों का प्रयास करें, फिर किसी भी समय /api/openapi पर कच्ची विशिष्टता प्राप्त करें।

इंटरैक्टिव संदर्भ लॉन्च करें

rembg.js की स्थापना

latest npm versionGitHub starsnpm downloadslicenseGitHub issues

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
ParameterTypeRequiredDefaultDescription
apiKeystring
Required

Your Rembg API key
inputImagestring | 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.formatwebp (default) | png
Optional
webp
Specifies the output image format. Either "webp" (default) or "png"
options.returnBase64boolean
Optional
false
Return Base64 string instead of file
options.returnMaskboolean
Optional
false
Return only the alpha mask
options.wnumber
Optional

Target width (maintains aspect ratio)
options.hnumber
Optional

Target height (maintains aspect ratio)
options.exact_resizeboolean
Optional
false
Force exact width × height (may distort)
options.anglenumber
Optional
0
Rotation angle in degrees
options.expandboolean
Optional
true
Add padding so rotated images aren’t cropped
options.bg_colorstring
Optional
-
Optional solid background color in hex (e.g. #FFFFFFFF) or named color (e.g. "red", "blue")
  • अपना परिवेश स्थापित करना: सुनिश्चित करें कि आपके प्रोजेक्ट रूट में एक .env फ़ाइल है जिसमें आपकी एपीआई कुंजी है।

  • आवश्यक मॉड्यूल आयात करना: पर्यावरण चर को संभालने के लिए @remove-background-ai/rembg.js और dotenv मॉड्यूल से rembg फ़ंक्शन आयात करके प्रारंभ करें।

  • प्रगति कॉलबैक कॉन्फ़िगर करना: लाइब्रेरी फ़ाइल संचालन की प्रगति को ट्रैक करने के लिए onDownloadProgress और onUploadProgress कॉलबैक प्रदान करती है। दिए गए उदाहरण में, हम इन ईवेंट को सीधे कंसोल पर लॉग कर रहे हैं।

अब, आइए नमूना उपयोग पर करीब से नज़र डालें:


// 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
					

सदस्यता और क्रेडिट उपयोग

आपके प्लान का लेबल, सम्मिलित और प्रीपेड क्रेडिट शेष और उपयोग लौटाता है। आप यूटीसी कैलेंडर माह (विरासत), स्ट्राइप-संरेखित बिलिंग अवधि (नवीनीकरण के माध्यम से निगरानी के लिए), या ज्ञात बिलिंग अवधियों की सूची के आधार पर क्वेरी कर सकते हैं। केवल अपनी एपीआई कुंजी से प्रमाणित करें।

स्कीमा, उदाहरण और ट्राई-इट कंसोल के लिए, पूर्ण संदर्भ में समान समापन बिंदु देखें: API दस्तावेज़ खोलें

समापन बिंदु
GET https://www.rembg.com/api/membership-usage
प्रमाणीकरण

अपनी एपीआई कुंजी भेजें: हेडर x-api-key: YOUR_API_KEY_HERE (rembg.com पर अपनी प्रोफ़ाइल में कुंजी बनाएं और प्रबंधित करें)।

क्वेरी पैरामीटर
पैरामीटरटाइप करेंविवरण
yearnumberकैलेंडर वर्ष (1-9999)। महीने के साथ, Redis कुंजी उपयोगकर्ता:{uid}:app_usage:{year}:{month} पढ़ता है। यदि छोड़ दिया जाता है (और periodStartUnix का उपयोग नहीं किया जाता है), तो वर्तमान UTC वर्ष डिफ़ॉल्ट हो जाता है।
monthnumber (1–12)कैलेंडर माह 1-12 (कुंजियों के लिए यूटीसी कन्वेंशन का उपयोग किया जाता है)। यदि छोड़ दिया जाए, तो वर्तमान यूटीसी माह डिफ़ॉल्ट हो जाता है।
periodStartUnixnumberसेकंड में यूनिक्स टाइमस्टैम्प: बिलिंग विंडो की शुरुआत। उपयोगकर्ता पढ़ता है:{uid}:app_usage:cycle:{periodStartUnix} और api_usage:cycle:…। साल या महीने के साथ नहीं जोड़ा जा सकता.
expandstringअल्पविराम से अलग किए गए झंडे. बिलिंगसाइकल ऑब्जेक्ट जोड़ने के लिए बिलिंग_साइकिल शामिल करें: वर्तमान स्ट्राइप अवधि जब बिलिंग_पीरियड_* रेडिस में मौजूद है, अन्यथा वर्तमान यूटीसी कैलेंडर माह। एक विशिष्ट विंडो के लिए periodStartUnix के साथ भी काम करता है।
includeBillingCycle1 / trueबिलिंग_साइकिल वाले विस्तार के समान: बिलिंगसाइकिल ऑब्जेक्ट को शामिल करने के लिए 1 या सत्य पर सेट करें।
listBillingCycles1 / trueसमर्पित मोड: listBillingCycles=1 या केवल सच्चा रिटर्न { billingCycles: [...] }। इस उपयोगकर्ता के लिए साइकिल कुंजियों के लिए रेडिस को स्कैन करता है; इस अनुरोध पर अन्य क्वेरी पैरामीटरों को अनदेखा कर दिया गया है।

periodStartUnix को वर्ष या महीने के साथ पास न करें - एपीआई 400 लौटाता है। listBillingCycles मोड अलग है और अन्य पैरामीटरों को अनदेखा करता है।

बिलिंग अवधियों की सूची बनाएं

अतीत और वर्तमान सदस्यता विंडो के ड्रॉपडाउन को पॉप्युलेट करने के लिए इसका उपयोग करें (प्रत्येक प्रविष्टि एक periodStartUnix है जिसे आप periodStartUnix=… के साथ वापस पास कर सकते हैं)। अवधि समाप्ति समय का अनुमान लगाया जाता है (अगली अवधि प्रारंभ - 1, या सक्रिय अवधि के लिए स्ट्राइप current_period_end)।

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बिलिंग विंडो की शुरुआत (यूनिक्स सेकंड)। खाता सिंक होने पर स्ट्राइप current_period_start से मेल खाता है।
periodEndUnixवर्तमान विंडो का अंत (यूनिक्स सेकंड), यानी अगले नवीनीकरण से ठीक पहले - सिंक होने पर स्ट्राइप current_period_end। सदस्यता रद्दीकरण तिथि के समान नहीं।
appUsage / apiUsageशामिल-क्रेडिट उपयोग इस विंडो में गिना जाता है: वेब/संपादक (ऐप) बनाम एपीआई कुंजी (एपीआई)। प्रयुक्त शामिल क्रेडिट उनके योग के बराबर है।
includedCreditsआपका शामिल (योजना) क्रेडिट भत्ता रेडिस में संग्रहीत है (शीर्ष-स्तरीय क्रेडिट के समान विचार)।
prepaidCreditsप्रीपेड (खरीदी गई) शेष राशि; प्रत्येक बिलिंग अवधि को रीसेट नहीं करता.
usedIncludedCreditsविंडो में कुल सम्मिलित उपयोग (ऐप + एपीआई)। यहां प्रीपेड खपत नहीं जोड़ी गई है.
remainingIncludedCreditsअधिकतम(0, includeCredits - प्रयुक्तIncludedCredits)।
stripeBillingSyncedसत्य है जब रेडिस में स्ट्राइप से बिलिंग_पीरियड_स्टार्ट/एंड है, इसलिए विंडो आपकी सदस्यता से मेल खाती है; गलत का मतलब है कि एपीआई इस ब्लॉक के लिए यूटीसी कैलेंडर माह पर वापस आ गया है।

जब तक स्ट्राइप वेबहुक ने उपयोगकर्ता के लिए बिलिंग अवधि नहीं लिखी है, तब तक स्ट्राइपबिलिंगसिंक गलत हो सकता है और बिलिंगसाइकल विंडो यूटीसी कैलेंडर माह का अनुसरण करती है। सिंक के बाद, छवि एपीआई पर उपयोग की सीमाएं समान चक्र कुंजियों के साथ संरेखित होती हैं।

"अगले नवीनीकरण से पहले उपयोग किए गए क्रेडिट" के लिए, एक्सपैंड=बिलिंग_साइकल के साथ कॉल करें और नवीनीकरण सीमा के रूप में billingCycle.periodEndUnix, billingCycle.usedIncludedCredits (या ऐपUsage + 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 (बिलिंग चक्र के साथ)

शीर्ष-स्तरीय ऐप_उपयोग और एपीआई_उपयोग हमेशा या तो अनुरोधित कैलेंडर माह को प्रतिबिंबित करते हैं, या, जब periodStartUnix सेट किया जाता है, तो उस चक्र के काउंटर। जब explored=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
  }
}

जब StripeBillingSynced सत्य होता है, तो billingCycle बैकग्राउंड-रिमूवल एपीआई पर प्रवर्तन से मेल खाता है। गलत होने पर, कैलेंडर माह फ़ील्ड पर भरोसा करें या तब तक प्रतीक्षा करें जब तक वेबहुक Redis में billing_period_* को पॉप्युलेट न कर दे।

Error Responses

All error responses return a JSON body with a status field matching the HTTP status code.

Single Error Response

HTTP/1.1 400 Bad Request

HTTP/1.1 400 Bad Request
Content-Type: application/json

{
  "error": "Image width (12000px) exceeds the maximum allowed width of 10000px.",
  "field": "image",
  "status": 400
}

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
ScenarioStatusError 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 error field for the error message
  • Check for the details array when handling multiple validation errors
  • Use the field property to map errors to specific request parameters