Error Reference
Complete reference for handling PicToText API errors with detailed error codes, troubleshooting steps, and best practices.
Error Format
All errors follow a consistent JSON structure:
{
"error": {
"code": 400,
"message": "Human-readable description",
"status": "HTTP Status Text",
"details": [
{
"reason": "ERROR_CODE",
"metadata": {} // Optional additional data
}
]
}
}
HTTP Status Codes
400 Bad Request
Invalid request parameters or missing required fields.
Common Causes:
- Missing image file
- Invalid document type
- Malformed request
- Invalid image format
Example:
{
"error": {
"code": 400,
"message": "Image file is required in form data.",
"status": "Bad Request",
"details": [{ "reason": "MISSING_IMAGE_FILE" }]
}
}
401 Unauthorized
Authentication failed.
Common Causes:
- Missing Authorization header
- Invalid API key
- API key not found
- Inactive API key
Example:
{
"error": {
"code": 401,
"message": "Invalid or inactive API key",
"status": "Unauthorized",
"details": [{ "reason": "INVALID_API_KEY" }]
}
}
402 Payment Required
Insufficient credits for enterprise users.
Example:
{
"error": {
"code": 402,
"message": "Insufficient credits. Please top up your account.",
"status": "Payment Required",
"details": [{ "reason": "INSUFFICIENT_CREDITS" }]
}
}
403 Forbidden
Access denied due to subscription or account issues.
Common Causes:
- Inactive subscription
- API key disabled
- Account suspended
- Regional restrictions
Example:
{
"error": {
"code": 403,
"message": "A subscription is required to use this API key.",
"status": "Forbidden",
"details": [{ "reason": "SUBSCRIPTION_REQUIRED" }]
}
}
500 Internal Server Error
Server-side processing error.
Common Causes:
- AI service failure
- Image processing error
- System maintenance
- Database issues
Example:
{
"error": {
"code": 500,
"message": "Failed to process image with AI service.",
"status": "Internal Server Error",
"details": [{ "reason": "AI_SERVICE_ERROR" }]
}
}
503 Service Unavailable
Service temporarily unavailable.
Common Causes:
- Maintenance window
- High load
- Infrastructure issues
Example:
{
"error": {
"code": 503,
"message": "Service temporarily unavailable. Please try again later.",
"status": "Service Unavailable",
"details": [{ "reason": "SERVICE_UNAVAILABLE" }]
}
}
Error Codes Reference
Authentication Errors
Reason Code | Description | Solution |
---|---|---|
INVALID_AUTH_HEADER |
Missing or malformed Authorization header | Use format: Bearer YOUR_API_KEY |
INVALID_API_KEY |
API key not found or inactive | Check key in dashboard |
SUBSCRIPTION_REQUIRED |
Active subscription needed | Upgrade to paid plan |
ACCOUNT_SUSPENDED |
Account access restricted | Contact support |
Request Errors
Reason Code | Description | Solution |
---|---|---|
MISSING_IMAGE_FILE |
No image file provided | Include image in form data |
INVALID_DOCUMENT_TYPE |
Unsupported document type | Check supported documents |
INVALID_IMAGE_FORMAT |
Unsupported image format | Use JPG, PNG, GIF, or WebP |
IMAGE_TOO_LARGE |
Image exceeds 10MB limit | Resize or compress image |
IMAGE_TOO_SMALL |
Image too small to process | Use higher resolution image |
IMAGE_CORRUPTED |
Image file is corrupted | Re-upload the image |
INVALID_JSON |
Malformed JSON in request | Check request format |
Processing Errors
Reason Code | Description | Solution |
---|---|---|
AI_SERVICE_ERROR |
AI processing failed | Retry request, contact support if persists |
IMAGE_PROCESSING_ERROR |
Cannot analyze image | Check image quality |
TEXT_EXTRACTION_FAILED |
Cannot extract text | Ensure document is clear |
STRUCTURED_DATA_ERROR |
Cannot parse document structure | Verify document type |
DOCUMENT_RECOGNITION_FAILED |
Cannot identify document type | Use specific document type |
LOW_CONFIDENCE_RESULT |
Low confidence in extracted data | Check image quality |
Account Errors
Reason Code | Description | Solution |
---|---|---|
INSUFFICIENT_CREDITS |
Enterprise user out of credits | Purchase more credits |
BILLING_ISSUE |
Payment method issue | Update payment method |
System Errors
Reason Code | Description | Solution |
---|---|---|
DATABASE_ERROR |
Database operation failed | Retry, contact support if persists |
EXTERNAL_SERVICE_ERROR |
Dependent service failure | Retry, check status page |
MAINTENANCE_MODE |
System under maintenance | Check status page for ETA |
CONFIGURATION_ERROR |
System configuration issue | Contact support |
Error Handling Best Practices
1. Implement Retry Logic
async function callOcrApi(formData, maxRetries = 3) {
for (let attempt = 1; attempt <= maxRetries; attempt++) {
try {
const response = await fetch('/api/v1/ocr', {
method: 'POST',
headers: {
'Authorization': 'Bearer YOUR_API_KEY'
},
body: formData
});
if (response.ok) {
return await response.json();
}
const error = await response.json();
// Don't retry client errors (4xx)
if (response.status >= 400 && response.status < 500) {
throw new Error(error.error.message);
}
// Retry server errors (5xx) with exponential backoff
if (attempt < maxRetries) {
const delay = Math.pow(2, attempt) * 1000;
await new Promise(resolve => setTimeout(resolve, delay));
}
} catch (error) {
if (attempt === maxRetries) throw error;
}
}
}
2. User-Friendly Error Messages
function getUserFriendlyError(apiError) {
const errorMap = {
'INVALID_API_KEY': 'Please check your API key and try again.',
'SUBSCRIPTION_REQUIRED': 'A paid subscription is required. Please upgrade your account.',
'MISSING_IMAGE_FILE': 'Please select an image file to upload.',
'INVALID_DOCUMENT_TYPE': 'Please select a valid document type.',
'AI_SERVICE_ERROR': 'Processing failed. Please try again or contact support.',
'INSUFFICIENT_CREDITS': 'You have run out of credits. Please top up your account.',
'RATE_LIMIT_EXCEEDED': 'Too many requests. Please wait a moment and try again.',
'IMAGE_TOO_LARGE': 'Image is too large. Please use a smaller file (max 10MB).'
};
const reason = apiError.error.details?.[0]?.reason;
return errorMap[reason] || 'An unexpected error occurred. Please try again.';
}
3. Comprehensive Error Logging
function logApiError(error, context = {}) {
const errorData = {
timestamp: new Date().toISOString(),
code: error.error.code,
message: error.error.message,
reason: error.error.details?.[0]?.reason,
endpoint: context.endpoint,
documentType: context.documentType,
userAgent: navigator.userAgent,
// Don't log sensitive data like API keys
};
console.error('API Error:', errorData);
// Send to your error tracking service
if (window.errorTracker) {
window.errorTracker.log(errorData);
}
}
4. Rate Limit Handling
async function handleRateLimit(response) {
const remaining = response.headers.get('X-RateLimit-Remaining');
const reset = response.headers.get('X-RateLimit-Reset');
if (remaining && parseInt(remaining) < 5) {
console.warn(`Rate limit warning: ${remaining} requests remaining`);
}
if (response.status === 429) {
const resetTime = new Date(parseInt(reset) * 1000);
const waitTime = resetTime - new Date();
throw new Error(`Rate limit exceeded. Try again at ${resetTime.toLocaleTimeString()}`);
}
}
Common Issues & Solutions
"Invalid API Key" Error
Problem: Getting 401 Unauthorized with INVALID_API_KEY
Solutions:
- Verify API key format:
Bearer sk_live_...
- Check key is active in dashboard
- Ensure no extra spaces in header
- Try regenerating API key
- Check subscription status
"AI Service Error" Error
Problem: Getting 500 Internal Server Error with AI_SERVICE_ERROR
Solutions:
- Retry request (transient error)
- Check image quality and clarity
- Verify document type selection
- Contact support if persistent
- Check status page
"Invalid Document Type" Error
Problem: Getting 400 Bad Request with INVALID_DOCUMENT_TYPE
Solutions:
- Use exact document type string (case-sensitive)
- Check supported documents list
- Avoid using "auto" for production
- Verify no typos in document type
Rate Limit Issues
Problem: Getting 429 Too Many Requests
Solutions:
- Check rate limit headers in responses
- Implement request queuing
- Upgrade to higher plan
- Contact support for custom limits
- Implement exponential backoff
Image Quality Issues
Problem: Low accuracy or processing errors
Solutions:
- Ensure proper lighting and focus
- Check image resolution (min 300 DPI)
- Avoid shadows and glare
- Ensure document is fully visible
- Use supported image formats
Field Extraction Issues
Problem: Some fields are missing from the result or are incorrect.
Solutions:
- Ensure the specific field is not physically obscured, blurry, or affected by glare on the document.
- For documents with multiple languages or complex layouts, the AI may occasionally misinterpret a field.
- Address formatting can vary by region. Check the raw text to see if the address was extracted correctly but not parsed as expected.
- Name parsing may differ for non-standard or minority names.
Getting Help
If you encounter persistent errors:
- Check Status: Status page
- Review Request: Compare with code examples
- Test in Dashboard: Use web interface to isolate issues
- Contact Support: Include error details
Support Contact:
- Email: [email protected]
- Include: Error code, reason, timestamp, request details (sanitized)
- Response time: Within 24 hours (business days)
Related Documentation
- Authentication - API key management
- Rate Limits - Usage limits and quotas
- Quickstart Guide - Getting started
- Supported Documents - Complete list of supported document types