Complete reference for SmartBills API error codes and how to handle them.
Complete reference for SmartBills API error codes and how to handle them.
When an error occurs, the API returns a JSON response with the following structure:
{
"success": false,
"data": null,
"error": {
"code": "ERROR_CODE",
"message": "Human-readable error description",
"details": {
"field": "Additional error context"
}
}
}
Status Code | Description |
---|---|
400 | Bad Request - Invalid parameters or request format |
401 | Unauthorized - Invalid or missing API key |
403 | Forbidden - Insufficient permissions |
404 | Not Found - Resource doesn't exist |
413 | Payload Too Large - File size exceeds limit |
415 | Unsupported Media Type - Invalid file format |
422 | Unprocessable Entity - Valid request but processing failed |
429 | Too Many Requests - Rate limit exceeded |
500 | Internal Server Error - Server-side error |
502 | Bad Gateway - Service temporarily unavailable |
503 | Service Unavailable - Maintenance or overload |
Status: 401 Description: The provided API key is invalid or malformed.
{
"error": {
"code": "INVALID_API_KEY",
"message": "The API key provided is invalid"
}
}
Solutions:
Status: 401 Description: No API key was provided in the request.
{
"error": {
"code": "MISSING_API_KEY",
"message": "API key is required for authentication"
}
}
Solutions:
Authorization: Bearer YOUR_API_KEY
headerStatus: 401 Description: The API key has been revoked or disabled.
{
"error": {
"code": "API_KEY_REVOKED",
"message": "This API key has been revoked"
}
}
Solutions:
Status: 415 Description: The uploaded file format is not supported.
{
"error": {
"code": "INVALID_FILE_FORMAT",
"message": "File format not supported. Allowed formats: PDF, JPG, PNG",
"details": {
"allowed_formats": ["pdf", "jpg", "jpeg", "png", "webp"],
"received_format": "doc"
}
}
}
Solutions:
Status: 413 Description: The uploaded file exceeds the maximum size limit.
{
"error": {
"code": "FILE_TOO_LARGE",
"message": "File size exceeds the maximum limit of 10MB",
"details": {
"max_size_bytes": 10485760,
"received_size_bytes": 15728640
}
}
}
Solutions:
Status: 422 Description: The uploaded file is corrupted or unreadable.
{
"error": {
"code": "CORRUPTED_FILE",
"message": "The uploaded file appears to be corrupted"
}
}
Solutions:
Status: 400 Description: No file was provided in the request.
{
"error": {
"code": "MISSING_FILE",
"message": "A file must be provided for processing"
}
}
Solutions:
Status: 422 Description: The text in the document is too blurry or unclear to extract.
{
"error": {
"code": "UNREADABLE_TEXT",
"message": "The text in the image is too blurry to read accurately"
}
}
Solutions:
Status: 422 Description: No invoice content was detected in the uploaded file.
{
"error": {
"code": "NO_INVOICE_DETECTED",
"message": "No invoice content could be detected in this document"
}
}
Solutions:
Status: 422 Description: Processing took longer than the maximum allowed time.
{
"error": {
"code": "PROCESSING_TIMEOUT",
"message": "Document processing timed out"
}
}
Solutions:
Status: 422 Description: The document language is not supported.
{
"error": {
"code": "UNSUPPORTED_LANGUAGE",
"message": "Document language is not currently supported",
"details": {
"detected_language": "zh",
"supported_languages": ["en", "es", "fr", "de", "it"]
}
}
}
Solutions:
Status: 429 Description: You've exceeded your API rate limit.
{
"error": {
"code": "RATE_LIMIT_EXCEEDED",
"message": "Rate limit exceeded. Please slow down your requests",
"details": {
"limit": 100,
"window": "hour",
"retry_after": 3600
}
}
}
Solutions:
Status: 400 Description: The provided webhook URL is invalid.
{
"error": {
"code": "INVALID_WEBHOOK_URL",
"message": "Webhook URL must be a valid HTTPS URL",
"details": {
"provided_url": "http://example.com/webhook"
}
}
}
Solutions:
Status: 400 Description: One or more request parameters are invalid.
{
"error": {
"code": "INVALID_PARAMETER",
"message": "Invalid parameter value",
"details": {
"parameter": "extract_line_items",
"expected": "boolean",
"received": "string"
}
}
}
Solutions:
Status: 500 Description: An unexpected error occurred on our servers.
{
"error": {
"code": "INTERNAL_SERVER_ERROR",
"message": "An internal error occurred. Please try again later"
}
}
Solutions:
Status: 503 Description: The service is temporarily unavailable.
{
"error": {
"code": "SERVICE_UNAVAILABLE",
"message": "Service temporarily unavailable for maintenance"
}
}
Solutions:
async function extractInvoiceWithRetry(file, maxRetries = 3) {
for (let attempt = 1; attempt <= maxRetries; attempt++) {
try {
return await smartbills.invoices.extract({ file });
} catch (error) {
const shouldRetry = [500, 502, 503, 504].includes(error.status) ||
error.code === 'PROCESSING_TIMEOUT';
if (shouldRetry && attempt < maxRetries) {
const delay = Math.pow(2, attempt) * 1000; // Exponential backoff
await new Promise(resolve => setTimeout(resolve, delay));
continue;
}
throw error;
}
}
}
try {
const result = await smartbills.invoices.extract({ file });
} catch (error) {
switch (error.code) {
case 'INVALID_FILE_FORMAT':
// Show user-friendly message about file format
showError('Please upload a PDF, JPG, or PNG file');
break;
case 'FILE_TOO_LARGE':
// Suggest file compression
showError('File is too large. Please compress and try again');
break;
case 'RATE_LIMIT_EXCEEDED':
// Implement backoff and retry
const retryAfter = error.details.retry_after;
setTimeout(() => retryUpload(), retryAfter * 1000);
break;
case 'UNREADABLE_TEXT':
// Suggest better image quality
showError('Image quality is too low. Please use a clearer scan');
break;
default:
// Generic error handling
showError('Something went wrong. Please try again');
}
}
Track error rates to identify patterns:
const errorMetrics = {
total: 0,
byCode: {},
byStatus: {}
};
function trackError(error) {
errorMetrics.total++;
errorMetrics.byCode[error.code] = (errorMetrics.byCode[error.code] || 0) + 1;
errorMetrics.byStatus[error.status] = (errorMetrics.byStatus[error.status] || 0) + 1;
}
If you encounter errors not covered here:
Each API response includes a unique X-Request-ID
header. Include this when contacting support for faster troubleshooting.