Working with AI?
WithoutBG API Reference#
The WithoutBG API provides AI-powered background removal services with multiple processing options and output formats.
Base URL#
https://api.withoutbg.com
Authentication#
All API endpoints require authentication using an API key sent in the X-API-Key
header:
X-API-Key: your_api_key_here
Rate Limits#
- 7 requests per minute per API key
Supported Image Formats#
The API supports the following image formats: JPEG, PNG, WebP, TIFF, BMP, and GIF.
File Size Limits#
- Maximum file size: 10 MB
Background Removal#
Remove Background (Transparent)#
POST /v1.0/image-without-background
Removes the background from an image and returns a transparent PNG.
Request:#
- Content-Type:
multipart/form-data
- Body: Image file in form data
Response:#
- Content-Type:
image/png
- Body: PNG image with transparent background
Remove Background (Base64)#
POST /v1.0/image-without-background-base64
Removes the background from a base64-encoded image and returns a base64-encoded transparent image.
Request:#
- Content-Type:
application/json
- Body:
Request Body
{
"image": "base64_encoded_image_data"
}
Response:#
- Content-Type:
application/json
- Body:
Response Body
{
"image": "base64_encoded_transparent_image"
}
Alpha Channel#
Get Alpha Channel#
POST /v1.0/alpha-channel
Returns the alpha channel (mask) of the processed image.
Request:#
- Content-Type:
multipart/form-data
- Body: Image file in form data
Response:#
- Content-Type:
image/png
- Body: Grayscale PNG representing the alpha channel
Get Alpha Channel (Base64)#
POST /v1.0/alpha-channel-base64
Returns the base64-encoded alpha channel of the processed image.
Request:#
- Content-Type:
application/json
- Body:
Request Body
{
"image": "base64_encoded_image_data"
}
Response:#
- Content-Type:
application/json
- Body:
Response Body
{
"alpha_channel": "base64_encoded_alpha_channel_image"
}
Account Information#
Error Responses#
All error responses return JSON with an error message:
{"error": "Error description"}
Common HTTP Status Codes#
Status Code | Description |
---|---|
200 | Success |
401 | Invalid API Key |
402 | Insufficient credits |
403 | Expired credits |
413 | File size too large (>10MB) |
415 | Unsupported media type |
429 | Rate limit exceeded (>7 requests/minute) |
500 | Internal server error |
Example Usage#
cURL Examples#
Remove background (transparent):#
Remove Background - cURL
Remove background and get transparent PNG result
curl -X POST "https://api.withoutbg.com/v1.0/image-without-background" \
-H "X-API-Key: your_api_key_here" \
-F "image=@your_image.jpg" \
--output result.png
Get available credits:#
Check Credits - cURL
Check your available API credits
curl -X GET "https://api.withoutbg.com/available-credit" \
-H "X-API-Key: your_api_key_here"
Remove background (base64):#
Base64 Processing - cURL
Process base64 encoded images
curl -X POST "https://api.withoutbg.com/v1.0/image-without-background-base64" \
-H "X-API-Key: your_api_key_here" \
-H "Content-Type: application/json" \
-d '{"image": "your_base64_image_data"}'
Python Example#
Python Background Removal
Python script for removing backgrounds using the API
1import requests
2
3# Remove background
4url = "https://api.withoutbg.com/v1.0/image-without-background"
5headers = {"X-API-Key": "your_api_key_here"}
6
7with open("input.jpg", "rb") as image_file:
8 files = {"image": image_file}
9 response = requests.post(url, headers=headers, files=files)
10
11 if response.status_code == 200:
12 with open("output.png", "wb") as output_file:
13 output_file.write(response.content)
14 else:
15 print(f"Error: {response.json()}")
JavaScript/Node.js Example#
Node.js Background Removal
JavaScript/Node.js implementation for background removal
1const fs = require('fs');
2const FormData = require('form-data');
3const axios = require('axios');
4
5const form = new FormData();
6form.append('image', fs.createReadStream('input.jpg'));
7
8axios.post('https://api.withoutbg.com/v1.0/image-without-background', form, {
9 headers: {
10 'X-API-Key': 'your_api_key_here',
11 ...form.getHeaders()
12 },
13 responseType: 'stream'
14}).then(response => {
15 response.data.pipe(fs.createWriteStream('output.png'));
16}).catch(error => {
17 console.error('Error:', error.response.data);
18});
Best Practices#
- Check credits before processing: Use the
/available-credit
endpoint to monitor your usage - Handle rate limits: Implement retry logic with exponential backoff for 429 errors
- Optimize image size: Resize images before upload to reduce processing time and costs
- Use appropriate endpoint: Choose between transparent background, white background, or alpha channel based on your needs
- Error handling: Always check response status codes and handle errors gracefully