Error Codes

Complete reference for SmartBills API error codes and how to handle them.

Error Codes

Complete reference for SmartBills API error codes and how to handle them.

Error Response Format

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"
    }
  }
}

HTTP Status Codes

Status CodeDescription
400Bad Request - Invalid parameters or request format
401Unauthorized - Invalid or missing API key
403Forbidden - Insufficient permissions
404Not Found - Resource doesn't exist
413Payload Too Large - File size exceeds limit
415Unsupported Media Type - Invalid file format
422Unprocessable Entity - Valid request but processing failed
429Too Many Requests - Rate limit exceeded
500Internal Server Error - Server-side error
502Bad Gateway - Service temporarily unavailable
503Service Unavailable - Maintenance or overload

Authentication Errors

INVALID_API_KEY

Status: 401 Description: The provided API key is invalid or malformed.

{
  "error": {
    "code": "INVALID_API_KEY",
    "message": "The API key provided is invalid"
  }
}

Solutions:

  • Verify your API key is correct
  • Check that you're using the right environment key (test vs live)
  • Ensure the API key hasn't been revoked

MISSING_API_KEY

Status: 401 Description: No API key was provided in the request.

{
  "error": {
    "code": "MISSING_API_KEY",
    "message": "API key is required for authentication"
  }
}

Solutions:

  • Include the Authorization: Bearer YOUR_API_KEY header
  • Check that your HTTP client is sending headers correctly

API_KEY_REVOKED

Status: 401 Description: The API key has been revoked or disabled.

{
  "error": {
    "code": "API_KEY_REVOKED",
    "message": "This API key has been revoked"
  }
}

Solutions:

  • Generate a new API key from your dashboard
  • Contact support if you believe this is an error

File Upload Errors

INVALID_FILE_FORMAT

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:

  • Convert your file to a supported format (PDF, JPG, PNG, WEBP)
  • Check the file extension matches the actual file type

FILE_TOO_LARGE

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:

  • Compress your file to reduce size
  • Split multi-page PDFs into smaller documents
  • Use image compression for image files

CORRUPTED_FILE

Status: 422 Description: The uploaded file is corrupted or unreadable.

{
  "error": {
    "code": "CORRUPTED_FILE",
    "message": "The uploaded file appears to be corrupted"
  }
}

Solutions:

  • Try uploading the file again
  • Check if the file opens correctly on your device
  • Re-scan or re-export the document

MISSING_FILE

Status: 400 Description: No file was provided in the request.

{
  "error": {
    "code": "MISSING_FILE",
    "message": "A file must be provided for processing"
  }
}

Solutions:

  • Ensure you're including a file in your multipart/form-data request
  • Check that the form field name is "file"

Processing Errors

UNREADABLE_TEXT

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:

  • Use a higher resolution scan (300 DPI or higher)
  • Ensure good lighting when photographing documents
  • Try a different scanning app or method

NO_INVOICE_DETECTED

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:

  • Verify the document contains invoice information
  • Check that the entire invoice is visible in the image
  • Make sure the document isn't upside down or rotated

PROCESSING_TIMEOUT

Status: 422 Description: Processing took longer than the maximum allowed time.

{
  "error": {
    "code": "PROCESSING_TIMEOUT",
    "message": "Document processing timed out"
  }
}

Solutions:

  • Try again with a simpler or smaller document
  • Split complex multi-page documents
  • Contact support if the issue persists

UNSUPPORTED_LANGUAGE

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:

  • Check our list of supported languages
  • Contact support to request additional language support

Rate Limiting Errors

RATE_LIMIT_EXCEEDED

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:

  • Wait for the rate limit window to reset
  • Implement exponential backoff in your code
  • Upgrade your plan for higher rate limits
  • Spread your requests more evenly over time

Validation Errors

INVALID_WEBHOOK_URL

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:

  • Use HTTPS URLs for webhooks
  • Ensure the URL is properly formatted
  • Test that your webhook endpoint is accessible

INVALID_PARAMETER

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:

  • Check the API documentation for correct parameter types
  • Validate your request parameters before sending

Server Errors

INTERNAL_SERVER_ERROR

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:

  • Try your request again after a short delay
  • Check our status page for known issues
  • Contact support if the issue persists

SERVICE_UNAVAILABLE

Status: 503 Description: The service is temporarily unavailable.

{
  "error": {
    "code": "SERVICE_UNAVAILABLE",
    "message": "Service temporarily unavailable for maintenance"
  }
}

Solutions:

  • Wait and retry your request
  • Check our status page for maintenance announcements
  • Implement retry logic with exponential backoff

Error Handling Best Practices

Implement Retry Logic

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;
    }
  }
}

Handle Specific Error Types

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');
  }
}

Monitor Error Rates

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;
}

Getting Help

If you encounter errors not covered here:

  1. Check our status page for known issues
  2. Review your implementation against our examples
  3. Contact support with the error details and request ID

Request IDs

Each API response includes a unique X-Request-ID header. Include this when contacting support for faster troubleshooting.