How it Works
This API uses the U-2-Net deep learning model to intelligently detect and remove backgrounds from images. The service is built with FastAPI (Python) and runs in a Docker container for consistent, isolated execution.
The AI model analyzes your image to identify the main subject (foreground) and separates it from the background, returning a clean PNG with transparency. Processing happens entirely server-side—you just send an image and get back the result.
The service includes built-in rate limiting, authentication, request tracking, and automatic resource management. To save server resources, the model unloads from memory after 15 minutes of inactivity (cold start may take 10-20 seconds to reload).
📦 Open Source: The complete source code is available on GitHub at
girste/fastapi-ai-gateway.
You can self-host it using Docker or adapt it for your own needs.
Authentication
Include your API key in the request header. Contact me to obtain an API key.
X-API-Key: your_api_key_here
Endpoint
POST
/tech/cutout/api/remove-bg
Remove background from images using AI.
Parameters:
file
Image file (JPEG, PNG, WebP). Max 5MB.
Response:
PNG image with transparent background
Examples
cURL:
curl -X POST https://girste.com/tech/cutout/api/remove-bg \
-H "X-API-Key: your_api_key_here" \
-F "file=@image.jpg" \
-o result.png
Python:
import requests
url = "https://girste.com/tech/cutout/api/remove-bg"
headers = {"X-API-Key": "your_api_key_here"}
files = {"file": open("image.jpg", "rb")}
response = requests.post(url, headers=headers, files=files)
with open("result.png", "wb") as f:
f.write(response.content)
JavaScript:
const formData = new FormData();
formData.append('file', fileInput.files[0]);
const response = await fetch('/tech/cutout/api/remove-bg', {
method: 'POST',
headers: {
'X-API-Key': 'your_api_key_here'
},
body: formData
});
const blob = await response.blob();
const url = URL.createObjectURL(blob);
Rate Limits
Rate limits vary by API key. Your current limit will be communicated when your key is issued.
Error Responses
// 401 Unauthorized - Missing API key
{
"detail": "Missing API key. Include X-API-Key header."
}
// 403 Forbidden - Invalid API key
{
"detail": "Invalid or inactive API key"
}
// 413 Payload Too Large - File too large
{
"detail": "File too large. Maximum size: 5MB"
}
// 429 Too Many Requests - Rate limit exceeded
{
"detail": "Rate limit exceeded"
}