Background Removal API
Remove image backgrounds programmatically via API.
Overview
The Background Removal API uses advanced AI algorithms to automatically detect and remove image backgrounds, outputting transparent PNG format images. Supports various image types including people, products, and animals with hair-level precision.
Endpoint
POST https://api.aluo.ai/api/remove-bgRequest Parameters
Submit using multipart/form-data format. Two input methods supported (choose one):
| Parameter | Type | Required | Description |
|---|---|---|---|
file | File | Either | Image file (JPG/PNG/WebP) |
imageUrl | string | Either | Image URL |
uploadToCDN | boolean | Optional | Upload to CDN (default: true) |
Note: Maximum file size: 4096x4096 pixels. Supported formats: JPG, PNG, WebP.
Response Format
Success Response
{
"code": 0,
"success": true,
"data": {
"url": "https://cdn.aluo.ai/...",
"originalFileName": "image.png",
"processedFileName": "processed_image.png",
"fileSize": 123456,
"contentType": "image/png",
"width": 1024,
"height": 1024
},
"credits_deducted": 8,
"credits_remaining": 42
}Error Response
{
"code": -1,
"success": false,
"error": "No file or imageUrl provided"
}Example Requests
Method 1: Upload File
curl -X POST https://api.aluo.ai/api/remove-bg \ -H "Authorization: Bearer sk-your-api-key-here" \ -F "file=@/path/to/image.jpg"
Method 2: Use Image URL
curl -X POST https://api.aluo.ai/api/remove-bg \ -H "Authorization: Bearer sk-your-api-key-here" \ -F "imageUrl=https://example.com/product.jpg"
Node.js
const fs = require('fs');
const FormData = require('form-data');
const fetch = require('node-fetch');
const form = new FormData();
// 方式一:上传文件
form.append('file', fs.createReadStream('/path/to/image.jpg'));
// 方式二:使用 URL
// form.append('imageUrl', 'https://example.com/product.jpg');
const response = await fetch('https://api.aluo.ai/api/remove-bg', {
method: 'POST',
headers: {
'Authorization': 'Bearer sk-your-api-key-here',
...form.getHeaders()
},
body: form
});
const result = await response.json();
console.log(result);Python
import requests
headers = {
'Authorization': 'Bearer sk-your-api-key-here'
}
# 方式一:上传文件
files = {
'file': open('/path/to/image.jpg', 'rb')
}
response = requests.post(
'https://api.aluo.ai/api/remove-bg',
headers=headers,
files=files
)
# 方式二:使用 URL
# data = {
# 'imageUrl': 'https://example.com/product.jpg'
# }
# response = requests.post(
# 'https://api.aluo.ai/api/remove-bg',
# headers=headers,
# data=data
# )
result = response.json()
print(result)Credits & Processing Time
| Item | Free User | PRO User |
|---|---|---|
| Credits Cost | 8 credits/image | 6 credits/image |
| Processing Time | Usually 10-30 seconds | |
Common Errors
| Error Message | Cause | Solution |
|---|---|---|
No file or imageUrl provided | No image provided | Must provide either file or imageUrl |
Insufficient credits | Not enough credits | Recharge credits or upgrade to PRO |
Authentication required | Invalid API Key | Check Authorization header |