Spaces:
Runtime error
Runtime error
| BRIA RMBG Service API | |
| Base URL: http://localhost:7860 | |
| Endpoints | |
| - GET /health | |
| - Response 200 JSON: {"status": "ok", "device": "cpu|cuda", "cuda": true|false} | |
| - POST /api/remove_bg | |
| - Description: Remove background and return RGBA PNG, either as raw image or JSON(base64) | |
| - Request | |
| - Content-Type: multipart/form-data | |
| - Form field: file (image/*) | |
| - Query: output = image | json (default: image) | |
| - Responses | |
| - 200 image/png (when output=image) | |
| - 200 application/json { image_base64: string, format: "PNG" } (when output=json) | |
| - 400, 500 errors with JSON detail | |
| - POST /api/matte | |
| - Description: Return the alpha matte as PNG (grayscale) | |
| - Request: multipart/form-data with field "file" | |
| - Response: 200 image/png | |
| Examples | |
| - cURL (PNG bytes) | |
| curl -X POST "http://localhost:7860/api/remove_bg?output=image" \ | |
| -H "Content-Type: multipart/form-data" \ | |
| -F "file=@/path/to/image.jpg" \ | |
| --output result.png | |
| - cURL (JSON base64) | |
| curl -X POST "http://localhost:7860/api/remove_bg?output=json" \ | |
| -H "Content-Type: multipart/form-data" \ | |
| -F "file=@/path/to/image.jpg" | jq -r .image_base64 | base64 --decode > result.png | |
| - Python | |
| import requests | |
| with open("/path/to/image.jpg", "rb") as f: | |
| r = requests.post( | |
| "http://localhost:7860/api/remove_bg?output=image", | |
| files={"file": ("image.jpg", f, "image/jpeg")}, | |
| timeout=60, | |
| ) | |
| open("result.png", "wb").write(r.content) | |
| - JavaScript (Node) | |
| import fs from 'node:fs'; | |
| import fetch from 'node-fetch'; | |
| import FormData from 'form-data'; | |
| const fd = new FormData(); | |
| fd.append('file', fs.createReadStream('./image.jpg')); | |
| const res = await fetch('http://localhost:7860/api/remove_bg?output=image', { method: 'POST', body: fd }); | |
| const buf = await res.arrayBuffer(); | |
| fs.writeFileSync('result.png', Buffer.from(buf)); | |