Error Codes Reference

Complete reference for all API error codes, status codes, and error handling best practices. Build robust integrations with proper error handling.

HTTP Status Codes

200

OK

Request processed successfully

All endpoints return 200 for successful operations

400

Bad Request

Invalid request format, missing parameters, or malformed data

Check request body, file format, and required parameters

401

Unauthorized

Invalid, missing, or malformed API key

Verify Authorization header format: Bearer pk_live_...

402

Payment Required

Insufficient credit balance for operation

Purchase credits via dashboard or check balance

403

Forbidden

API key lacks required permissions for endpoint

Check API key permissions in dashboard

413

Payload Too Large

File exceeds maximum size limit (10MB)

Compress file or split into smaller parts

422

Unprocessable Entity

Valid request but content cannot be processed

PDF corrupted, no form fields, or unsupported content

429

Too Many Requests

Rate limit exceeded for API key

Implement exponential backoff and retry logic

500

Internal Server Error

Unexpected server error during processing

Retry request or contact support with request ID

Error Response Format

Standard Error Response
{
  "error": "Insufficient balance",
  "message": "Not enough credits to process this request",
  "details": {
    "code": "INSUFFICIENT_BALANCE",
    "amountRequired": 0.02,
    "currentBalance": 0.01,
    "pageCount": 1,
    "suggestion": "Purchase credits via dashboard"
  },
  "timestamp": "2024-01-15T10:30:00Z",
  "requestId": "req_abc123"
}
Validation Error Response
{
  "error": "Bad Request",
  "message": "Invalid file format",
  "details": {
    "code": "INVALID_FILE_FORMAT",
    "allowedFormats": ["pdf"],
    "receivedFormat": "docx",
    "field": "file"
  },
  "timestamp": "2024-01-15T10:30:00Z",
  "requestId": "req_def456"
}

Detailed Error Codes

Authentication Errors

MISSING_API_KEY401

Authorization header is missing

Include: Authorization: Bearer your_api_key

INVALID_API_KEY401

API key is malformed or invalid

Check key format: pk_live_ or pk_test_

API_KEY_REVOKED401

API key has been deactivated

Generate new key in dashboard

INSUFFICIENT_PERMISSIONS403

API key lacks endpoint permissions

Update key permissions in dashboard

File Processing Errors

INVALID_FILE_FORMAT400

File is not a valid PDF

Only PDF files are supported

FILE_TOO_LARGE413

File exceeds 10MB limit

Compress file or contact support for large files

CORRUPTED_PDF422

PDF file is corrupted or unreadable

Try re-saving or repairing the PDF

NO_FORM_FIELDS422

PDF contains no fillable form fields

Ensure PDF has interactive form fields

NO_TEXT_CONTENT422

PDF contains no extractable text

Document may be image-only or blank

Payment & Credit Errors

INSUFFICIENT_BALANCE402

Not enough credits for operation

Purchase credits via dashboard

ACCOUNT_SUSPENDED402

Account suspended due to payment issues

Contact support to resolve

Rate Limiting Errors

RATE_LIMIT_EXCEEDED429

Too many requests in time window

Implement exponential backoff

CONCURRENT_LIMIT_EXCEEDED429

Too many concurrent requests

Queue requests or reduce concurrency

Server Errors

PROCESSING_ERROR500

Unexpected processing error

Retry request or contact support

SERVICE_UNAVAILABLE503

Service temporarily unavailable

Check status page and retry later

Error Handling Best Practices

Retry Logic

JavaScript Retry Example
async function processWithRetry(url, formData, maxRetries = 3) {
  for (let attempt = 1; attempt <= maxRetries; attempt++) {
    try {
      const response = await fetch(url, {
        method: 'POST',
        headers: { 'Authorization': 'Bearer pk_live_...' },
        body: formData
      });
      
      if (response.ok) {
        return await response.blob();
      }
      
      const error = await response.json();
      
      // Don't retry client errors (4xx)
      if (response.status >= 400 && response.status < 500) {
        throw new Error(`Client error: ${error.message}`);
      }
      
      // Retry server errors (5xx) and rate limits (429)
      if (attempt === maxRetries) {
        throw new Error(`Max retries exceeded: ${error.message}`);
      }
      
      // Exponential backoff
      const delay = Math.pow(2, attempt) * 1000;
      await new Promise(resolve => setTimeout(resolve, delay));
      
    } catch (err) {
      if (attempt === maxRetries) throw err;
    }
  }
}

Error Response Handling

Comprehensive Error Handling
async function handleApiResponse(response) {
  if (response.ok) {
    return await response.blob();
  }
  
  const error = await response.json();
  
  switch (response.status) {
    case 400:
      throw new ValidationError(error.message, error.details);
    case 401:
      throw new AuthenticationError('Invalid API key');
    case 402:
      throw new PaymentError('Insufficient balance', error.details);
    case 403:
      throw new PermissionError('Access forbidden');
    case 413:
      throw new FileSizeError('File too large');
    case 422:
      throw new ProcessingError('Cannot process file', error.details);
    case 429:
      throw new RateLimitError('Rate limit exceeded', error.details);
    case 500:
      throw new ServerError('Server error', error.requestId);
    default:
      throw new ApiError(`HTTP ${response.status}: ${error.message}`);
  }
}

// Custom error classes for better error handling
class ValidationError extends Error {
  constructor(message, details) {
    super(message);
    this.name = 'ValidationError';
    this.details = details;
  }
}

Error Prevention Tips

Request Validation

• Validate file format and size before upload

• Check API key format (pk_live_ or pk_test_)

• Verify required parameters are present

• Test with sample files first

• Implement client-side validation

Monitoring & Alerts

• Monitor credit balance regularly

• Set up low balance alerts

• Track error rates and patterns

• Log request IDs for debugging

• Implement health checks

Need Help?

If you encounter errors not covered in this guide, our support team is here to help. Include the request ID from error responses for faster resolution.

PDF Mage - AI PDF Form Filler