Claude AI
OpenAI
Google Gemini
Mistral AI
Ollama

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
API Endpoints

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#

Get Available Credits#

GET /available-credit

Retrieves information about your available API credits and their expiration date.

Response:#

  • Content-Type: application/json
  • Body:

Response Body

{
  "available_credits": 1000,
  "expiration_date": "2024-12-31T23:59:59Z"
}
Error Handling

Error Responses#

All error responses return JSON with an error message:

{"error": "Error description"}

Common HTTP Status Codes#

Status CodeDescription
200Success
401Invalid API Key
402Insufficient credits
403Expired credits
413File size too large (>10MB)
415Unsupported media type
429Rate limit exceeded (>7 requests/minute)
500Internal server error
Code Examples

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

Best Practices#

  1. Check credits before processing: Use the /available-credit endpoint to monitor your usage
  2. Handle rate limits: Implement retry logic with exponential backoff for 429 errors
  3. Optimize image size: Resize images before upload to reduce processing time and costs
  4. Use appropriate endpoint: Choose between transparent background, white background, or alpha channel based on your needs
  5. Error handling: Always check response status codes and handle errors gracefully
For more information about API limits and pricing, please visit our pricing page or contact support for enterprise solutions.