Working with AI?
Error Handling Guide#
This guide covers error handling patterns and best practices when working with the WithoutBG API.
API Error Codes#
Authentication Errors#
Status Code | Error | Description |
---|---|---|
401 | Invalid API Key | The provided API key is invalid or missing |
403 | Credits Expired | Your API credits have expired |
Request Errors#
Status Code | Error | Description |
---|---|---|
402 | Insufficient Credit | Not enough credits available for this request |
413 | File Too Large | File size exceeds the 10 MB limit |
415 | Unsupported Media Type | File format not supported |
422 | Validation Error | Request validation failed |
429 | Rate Limit Exceeded | Rate limit of 7 requests/minute exceeded |
Server Errors#
Status Code | Error | Description |
---|---|---|
500 | Internal Server Error | Server-side error occurred |
Error Response Format#
All API errors return JSON responses with error details:
Error Response Format
{
"detail": "Error description"
}
Validation Error Example#
Validation Error Response
{
"detail": [
{
"loc": ["body", "image"],
"msg": "field required",
"type": "value_error.missing"
}
]
}
Troubleshooting#
Common Issues#
1. Invalid API Key (401)#
- Verify your API key is correctly set
- Check for extra spaces or characters
- Ensure the key hasn't been revoked
2. Rate Limit Exceeded (429)#
- Wait at least 60 seconds before retrying
- Use
--retry-delay
with curl - Consider upgrading to a higher tier plan
3. File Size Too Large (413)#
- Compress images before upload
- Use image optimization tools
- Check file size with
stat
command
4. Validation Errors (422)#
- Check file format is supported (JPEG, PNG, WebP)
- Ensure file is not corrupted
- Verify file extension matches content
Support#
For persistent issues, contact support at: contact@withoutbg.com
Include error details, request timestamps, and your account information for faster resolution.