Version 1.0

bg.tools REST API Documentation

The bg.tools REST API allows you to programmatically perform neural background removal, watermark erasing, facial anonymization, and image conversion over standard HTTPS requests.

1. Quickstart (5 Minutes)

Follow these three simple steps to start processing images:

  1. Create an Account & Sign In: Register on bg.tools (includes 10 free credits daily).
  2. Generate an API Key: Visit your Account Dashboard and generate a secret key (e.g. bgt_live_...).
  3. Make your first request: Copy and run the cURL snippet below:
curl -X POST https://bg.tools/api/v1/remove-background \
  -H "Authorization: Bearer bgt_live_YOUR_KEY" \
  -F "image=@photo.jpg" \
  --output result.png

2. Authentication & API Keys

Authenticate your API requests by including your secret API key in the standard Authorization header:

Authorization: Bearer bgt_live_YOUR_API_KEY
Security Best Practice: Never expose your live API key in client-side code (browser JavaScript, React apps, or mobile bundles). Always invoke bg.tools through your server-side backend or API gateway.

3. Idempotency & Safe Retries

The bg.tools API supports the Idempotency-Key header to prevent double-charging your token balance during network retries.

Idempotency-Key: 9b1deb4d-3b7d-4bad-9bdd-2b0d7b3dcb6d

When you include an idempotency key, the server caches the response for 24 hours. Any retry with the same key returns the cached result with header X-Idempotent-Replay: true and does NOT charge additional tokens.

4. Credits & Billing

Every API response includes two custom headers detailing your current token status:

  • X-Credits-Used: 1 (the amount deducted for this request)
  • X-Credits-Remaining: 49 (your updated total token balance)

Credits are reserved inside an atomic SQLite transaction before image processing. If downstream inference fails for any reason, all credits are automatically refunded.

POST

/api/v1/remove-background

Segment and remove backgrounds cleanly, outputting a transparent PNG with edge matting. You can specify which dedicated AI model engine to use according to your specific precision and speed requirements.

Available AI Models & Engines
model: "ganga" (Default)
Our dedicated alpha matting model. Ideal for portraits, e-commerce products, animals, and intricate flyaway hair and transparent fabrics.
model: "karudi"
Our universal flagship orchestrator. Intelligently analyzes complex multi-subject scenes, applies edge refinement, and maximizes cut-out accuracy.
model: "brahmaputra"
High-throughput conversion, resizing, and lightweight segmentation for high-volume batch processing.
model: "narmada" & "saraswati"
Narmada powers watermark removal inpainting; Saraswati powers automated facial detection and anonymization.
Request Parameters
image (binary file, multipart): Image file (PNG, JPG, WebP up to 30 MB)
image_url (string, JSON): Remote HTTPS URL to download image with SSRF protection
model (string, optional): AI model to execute (ganga, karudi, brahmaputra). Default: ganga
response_format (string): binary (default) or json
// Example Response when response_format="json"
{
  "success": true,
  "model": "ganga",
  "image": "data:image/png;base64,iVBORw0KGgo...",
  "format": "png",
  "width": 1200,
  "height": 800,
  "credits_used": 1,
  "credits_remaining": 49,
  "request_id": "req_9f3a18b2c45e"
}
POST

/api/v1/remove-watermark

Deep neural inpainting to erase text, watermarks, and logos while preserving 100% of the original background texture.

POST

/api/v1/blur-face

Automated facial detection and blurring with customizable blurType (gaussian, pixelate, solid_black) and strength.

Image Converters & Optimization (0.25 Credit Each)

POST /api/v1/compress-image
Shrinks file size up to 85% with quality loss minimized (params: quality: 10-100).
POST /api/v1/convert-image
Converts image formats between PNG, JPEG, and WebP (params: format: png|jpeg|webp).
POST /api/v1/resize-image
High-quality Lanczos resampling (params: width, height).
POST /api/v1/crop-image
Crops bounding box (params: x, y, width, height).

HTTP Status Codes & Error Catalog

StatusError CodeDescription
400api_key_in_queryKeys in query parameters rejected
401unauthorized / invalid_api_keyMissing, invalid, or revoked key
402insufficient_creditsCredit balance too low for tool
403insufficient_scope / ip_not_allowedScope violation or IP allowlist block
413payload_too_largeFile size exceeds 30 MB
415unsupported_media_typeNon-image or executable binary detected
429rate_limit_exceeded / quota_exceededRequests per minute or daily quota reached
503engine_busy / api_disabledInference queue saturated or maintenance

Security & Privacy Guarantees

Zero Image Storage: bg.tools operates a strict ephemeral-only processing architecture. Customer images are decoded in memory, processed through our neural engines, and discarded immediately after HTTP transmission.

No Plaintext Key Storage: Your API secret keys are salted and hashed using cryptographic SHA-256 before storing in our database. We only store the key prefix for display. Plaintext keys are shown exactly once at creation time.

GDPR & Compliance: All metadata and EXIF location tags are automatically stripped from output images.