API Credits Info#
Use this endpoint to check the remaining API credits for the authenticated account. This is useful for gating client-side features, CI checks, usage dashboards, and billing/alerting.
https://api.withoutbg.comWhen to Use This Endpoint#
Use the credits endpoint when:
- Monitoring credit balance: Check remaining credits before making paid API calls
- Error handling: Verify credit status after receiving 402 (insufficient credits) or 403 (expired credits) errors
- Usage dashboards: Display credit consumption metrics to end users
- Alerting systems: Set up automated alerts when credits drop below a threshold
- CI/CD pipelines: Validate sufficient credits exist before running automated tests
- Pre-flight checks: Gate features in your application based on available credits
All paid endpoints consume credits: Background removal and alpha matte endpoints (both binary and base64 variants) deduct credits on successful processing. Use this endpoint to monitor usage across all API calls.
Endpoint#
GET /available-credit
Returns the current available credit balance and expiration date for the API key provided.
Authentication#
Pass your API key in the X-API-Key header on every request.
Authentication Header
X-API-Key: YOUR_API_KEYRequest#
Method: GET
Path: /available-credit
Headers#
X-API-Key: <string>(required)Accept: application/json(recommended)
Query params: none
Body: none
Response#
Content-Type: application/json
200 OK#
Returns the current credit balance and expiration date.
Response Body
{
"credit": 138,
"expiration_date": "2026-09-05 23:59:59"
}Field Reference#
credit(integer) — Credits you can spend right now.expiration_date(string) — When your credits expire, inYYYY-MM-DD HH:MM:SSformat.
Error Responses#
All errors return JSON:
Error Response Format
{
"detail": "Error message here"
}| Status | Description | When it happens |
|---|---|---|
401 | Invalid API Key | Missing or invalid API key |
429 | Rate limit (7 request/minute) exceeded | Too many requests. Implement exponential backoff |
5xx | Internal Server Error. Please contact support: contact@withoutbg.com | Temporary server issue. Retry with backoff |
Rate limit: 7 requests per minute per API key (shared with all other endpoints)
Examples#
cURL#
cURL Example
Check available credits using cURL
curl -s \
-H "X-API-Key: $WITHOUTBG_API_KEY" \
-H "Accept: application/json" \
https://api.withoutbg.com/available-creditResponse:
Response
{
"credit": 138,
"expiration_date": "2026-09-05 23:59:59"
}Node.js (fetch)#
Node.js Example
Check credits using native fetch API
1const res = await fetch("https://api.withoutbg.com/available-credit", {
2 method: "GET",
3 headers: {
4 "X-API-Key": process.env.WITHOUTBG_API_KEY,
5 "Accept": "application/json"
6 }
7});
8
9if (!res.ok) {
10 const error = await res.text();
11 throw new Error(`HTTP ${res.status}: ${error}`);
12}
13
14const data = await res.json();
15console.log(`Available credits: ${data.credit}`);
16console.log(`Expires: ${data.expiration_date}`);Python (requests)#
Python Example
Check credits using Python requests library
1import os
2import requests
3
4r = requests.get(
5 "https://api.withoutbg.com/available-credit",
6 headers={"X-API-Key": os.environ["WITHOUTBG_API_KEY"]},
7 timeout=10,
8)
9r.raise_for_status()
10
11data = r.json()
12print(f"Credits: {data['credit']}, Expires: {data['expiration_date']}")Go (net/http)#
Go Example
Check credits using Go standard library
1req, _ := http.NewRequest("GET", "https://api.withoutbg.com/available-credit", nil)
2req.Header.Set("X-API-Key", os.Getenv("WITHOUTBG_API_KEY"))
3res, err := http.DefaultClient.Do(req)
4if err != nil { log.Fatal(err) }
5var out struct {
6 Credit int `json:"credit"`
7 ExpirationDate string `json:"expiration_date"`
8}
9json.NewDecoder(res.Body).Decode(&out)
10fmt.Printf("Credits: %d, Expires: %s\n", out.Credit, out.ExpirationDate)Python SDK#
The Python SDK provides a convenient wrapper:
Python SDK Example
Check credits using the WithoutBG Python SDK
1from withoutbg.api import StudioAPI
2
3api = StudioAPI(api_key="sk_your_api_key")
4usage = api.get_usage()
5print(f"Credits: {usage['credit']}, Expires: {usage['expiration_date']}")Learn more: Python SDK Documentation
Best Practices#
- Cache responses: Credits don't change instantly. Cache for 30-60 seconds to avoid hitting rate limits
- Pre-flight checks: Check credits before expensive operations like batch processing
- Alerting thresholds: Set up alerts when credits drop below 10-20% of your typical usage
- Monitor expiration: Check
expiration_dateregularly and alert users 7-14 days before expiry - Concurrent safety: Treat the balance as advisory between concurrent requests; actual charges occur during paid API calls
- Error recovery: After receiving 402/403 errors from other endpoints, poll this endpoint to verify credit status
- Dashboard integration: Display credit balance in user dashboards for transparency
- Rate limiting: This endpoint shares the 7 requests/minute limit. Don't poll aggressively
Troubleshooting#
- 401 errors: Verify your API key is correct and included in the
X-API-Keyheader - 429 rate limit: You're checking credits too frequently. Cache the response for 30-60 seconds
- Credits show 0 but purchase completed: New credits can take 1-2 minutes to propagate. Wait and retry
- Expiration date confusion: The date is in
YYYY-MM-DD HH:MM:SSformat in UTC timezone - Negative credits: Not possible. If you see this, contact support immediately
Related Endpoints#
These endpoints consume credits on successful processing:
- Background Removal (Binary): POST /v1.0/image-without-background — Remove background, returns binary PNG
- Background Removal (Base64): POST /v1.0/image-without-background-base64 — Remove background, returns Base64 JSON
- Alpha Matte (Binary): POST /v1.0/alpha-channel — Extract alpha mask, returns binary PNG
- Alpha Matte (Base64): POST /v1.0/alpha-channel-base64 — Extract alpha mask, returns Base64 JSON
All processing endpoints deduct 1 credit per successful request (HTTP 200). Failed requests (4xx/5xx errors) do not consume credits.
Quick Checklist#
GETto/available-creditX-API-Keyheader present with valid keyAccept: application/jsonheader recommended- Parse
credit(integer) andexpiration_date(string) from response - Cache response for 30-60 seconds to avoid rate limits
- Set up alerts for low credit balance
- Monitor expiration date and alert before expiry
- Handle 401 errors by verifying API key
- Use this endpoint after 402/403 errors from paid endpoints