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 தொகுதி.
முன்னேற்ற அழைப்புகளை உள்ளமைத்தல்: கோப்பு செயல்பாடுகளின் முன்னேற்றத்தைக் கண்காணிக்க நூலகம் 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
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-key: YOUR_API_KEY_HERE (rembg.com இல் உங்கள் சுயவிவரத்தில் விசைகளை உருவாக்கி நிர்வகிக்கவும்).
வினவல் அளவுருக்கள்
| அளவுரு | வகை | விளக்கம் |
|---|---|---|
| year | number | காலண்டர் ஆண்டு (1–9999). மாதத்துடன், Redis கீஸ் பயனர்:{uid}:app_usage:{year}:{month} படிக்கிறது. தவிர்க்கப்பட்டால் (மற்றும் பீரியட்ஸ்டார்ட்யூனிக்ஸ் பயன்படுத்தப்படவில்லை), தற்போதைய UTC ஆண்டிற்கு இயல்புநிலையாக இருக்கும். |
| month | number (1–12) | காலண்டர் மாதம் 1–12 (UTC மாநாடு விசைகளுக்குப் பயன்படுத்தப்படுகிறது). தவிர்க்கப்பட்டால், தற்போதைய UTC மாதத்திற்கு இயல்புநிலையாக இருக்கும். |
| periodStartUnix | number | யுனிக்ஸ் நேர முத்திரை வினாடிகளில்: பில்லிங் சாளரத்தின் தொடக்கம். பயனர்:{uid}:app_usage:cycle:{periodStartUnix} மற்றும் api_usage:cycle:…. ஆண்டு அல்லது மாதத்துடன் இணைக்க முடியாது. |
| expand | string | கமாவால் பிரிக்கப்பட்ட கொடிகள். billingCycle ஆப்ஜெக்ட்டைச் சேர்க்க, billing_cycleஐச் சேர்க்கவும்: Redis இல் billing_period_* இருக்கும் தற்போதைய ஸ்ட்ரைப் காலம், இல்லையெனில் தற்போதைய UTC காலண்டர் மாதம். ஒரு குறிப்பிட்ட சாளரத்திற்கு பீரியட்ஸ்டார்ட்யூனிக்ஸ் உடன் வேலை செய்கிறது. |
| includeBillingCycle | 1 / true | பில்லிங்_சைக்கிள் கொண்டிருக்கும் விரிவாக்கம்: பில்லிங்சைக்கிள் பொருளைச் சேர்க்க 1 அல்லது சரி என அமைக்கவும். |
| listBillingCycles | 1 / true | அர்ப்பணிக்கப்பட்ட பயன்முறை: listBillingCycles=1 அல்லது உண்மையான வருமானம் மட்டும் {bilingCycles: [...] }. இந்தப் பயனருக்கான சுழற்சி விசைகளுக்கு Redis ஐ ஸ்கேன் செய்கிறது; இந்த கோரிக்கையில் மற்ற வினவல் அளவுருக்கள் புறக்கணிக்கப்படுகின்றன. |
ஆண்டு அல்லது மாதத்துடன் பீரியட்ஸ்டார்ட்யூனிக்ஸைக் கடக்க வேண்டாம் - ஏபிஐ 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 key (api). பயன்படுத்தப்பட்டIncludedCredits அவற்றின் கூட்டுத்தொகைக்கு சமம். |
| includedCredits | Redis இல் சேமிக்கப்பட்டுள்ள உங்களின் சேர்க்கப்பட்ட (திட்டம்) கிரெடிட் அலவன்ஸ் (உயர்நிலை கிரெடிட்களின் அதே யோசனை). |
| prepaidCredits | ப்ரீபெய்ட் (வாங்கிய) இருப்பு; ஒவ்வொரு பில்லிங் காலத்தையும் மீட்டமைக்காது. |
| usedIncludedCredits | சாளரத்தில் சேர்க்கப்பட்ட மொத்த பயன்பாடு (பயன்பாடு + API). ப்ரீபெய்டு நுகர்வு இங்கே சேர்க்கப்படவில்லை. |
| remainingIncludedCredits | அதிகபட்சம்(0, சேர்க்கப்பட்ட கடன்கள் - பயன்படுத்தப்பட்டவை உள்ளிட்டவை). |
| stripeBillingSynced | Redis இல் ஸ்டிரைப்பில் இருந்து billing_period_start/end இருந்தால் சரி, அதனால் சாளரம் உங்கள் சந்தாவுடன் பொருந்தும்; தப்பு என்பது இந்த தொகுதிக்கான UTC காலண்டர் மாதத்திற்கு API ஆனது. |
ஸ்ட்ரைப் வெப்ஹூக்குகள் பயனருக்கான பில்லிங் காலங்களை எழுதும் வரை, ஸ்ட்ரைப் பில்லிங் சிங்க்ட் தவறானதாக இருக்கலாம் மற்றும் பில்லிங்சைக்கிள் சாளரம் யுடிசி காலண்டர் மாதத்தைப் பின்பற்றும். ஒத்திசைத்த பிறகு, பட APIயின் பயன்பாட்டு வரம்புகள் அதே சுழற்சி விசைகளுடன் சீரமைக்கப்படும்.
“அடுத்த புதுப்பித்தலுக்கு முன் பயன்படுத்தப்படும் கிரெடிட்டுகளுக்கு”, Expand=billing_cycle உடன் அழைத்து, billingCycle.periodEndUnixஐ புதுப்பித்தல் எல்லையாகப் பயன்படுத்தவும், billingCycle.usedIncludedCredits (அல்லது appUsage + apiUsage) மற்றும் billingCycle.remainingIncludedCredits. ப்ரீபெய்ட் கிரெடிட்களைச் சேர்க்கவும்.
எடுத்துக்காட்டுகள் (சுருட்டை)
குறிப்பிட்ட 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 (பில்லிங் சுழற்சியுடன்)
உயர்நிலை app_usage மற்றும் api_usage ஆகியவை எப்போதும் கோரப்பட்ட காலண்டர் மாதத்தை அல்லது பீரியட்ஸ்டார்ட்யூனிக்ஸ் அமைக்கப்படும் போது, அந்த சுழற்சியின் கவுண்டர்களை பிரதிபலிக்கும். 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 இல் billing_period_*ஐ நிரப்பும் வரை காத்திருக்கவும்.
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