API Error Handling

Error Response Format

All API errors follow a consistent JSON format to help you handle them programmatically:

{
 "error": "error_code",
 "message": "Human-readable error description",
 "details": {
 "field": "specific field causing the error (if applicable)",
 "code": "internal_error_code",
 "suggestion": "Recommended action to resolve the error"
 },
 "request_id": "unique_request_identifier_for_support"
}

HTTP Status Codes

400 - Bad Request

HTTP 400

The request was invalid or cannot be served

Common scenarios:

  • Invalid URL provided for conversion
  • Malformed JSON in request body
  • File size exceeds maximum limit
  • Unsupported file format

401 - Unauthorized

HTTP 401

Authentication failed or API key is invalid

Common scenarios:

  • Missing X-API-Key header
  • Invalid API key
  • Expired API key
  • API key not activated

403 - Forbidden

HTTP 403

Access denied due to insufficient permissions

Common scenarios:

  • API key lacks required permissions
  • Account subscription expired
  • Feature not available in current plan
  • IP address not whitelisted

404 - Not Found

HTTP 404

The requested resource was not found

Common scenarios:

  • Job ID not found
  • Endpoint does not exist
  • File has been deleted
  • Invalid API version

422 - Unprocessable Entity

HTTP 422

Request is well-formed but contains semantic errors

Common scenarios:

  • File content is corrupted
  • Unsupported language for OCR
  • Invalid conversion options combination
  • File format not compatible with requested output

429 - Too Many Requests

HTTP 429

Rate limit exceeded

Common scenarios:

  • Too many requests per minute
  • Daily quota exceeded
  • Concurrent request limit reached
  • Account temporarily throttled

500 - Internal Server Error

HTTP 500

An unexpected error occurred on our servers

Common scenarios:

  • Temporary service disruption
  • OCR engine temporarily unavailable
  • File processing failed
  • Database connection error

Error Examples

Authentication Error (401)

HTTP/1.1 401 Unauthorized
Content-Type: application/json

{
 "error": "invalid_api_key",
 "message": "The provided API key is invalid or has expired",
 "details": {
 "code": "AUTH_001",
 "suggestion": "Please check your API key and ensure it's correctly set in the X-API-Key header"
 },
 "request_id": "req_1234567890abcdef"
}

Validation Error (400)

HTTP/1.1 400 Bad Request
Content-Type: application/json

{
 "error": "invalid_file_format",
 "message": "The uploaded file format is not supported",
 "details": {
 "field": "file",
 "code": "FILE_001",
 "suggestion": "Please upload a supported format: PDF, DOCX, XLSX, PPTX, HTML, or TXT",
 "supported_formats": ["pdf", "docx", "xlsx", "pptx", "html", "txt"]
 },
 "request_id": "req_abcdef1234567890"
}

Rate Limit Error (429)

HTTP/1.1 429 Too Many Requests
Content-Type: application/json
Retry-After: 60

{
 "error": "rate_limit_exceeded",
 "message": "You have exceeded the rate limit for your plan",
 "details": {
 "code": "RATE_001",
 "suggestion": "Please wait 60 seconds before making another request",
 "retry_after": 60,
 "limit": "100 requests per minute",
 "reset_time": "2024-01-15T10:31:00Z"
 },
 "request_id": "req_fedcba0987654321"
}

Error Handling Best Practices

Retry Logic

Exponential Backoff: Implement exponential backoff for 5xx errors and 429 rate limits.

Retry Limits: Don't retry 4xx errors (except 429). Set maximum retry attempts.

Respect Headers: Use Retry-After header values when provided.

Example cURL with retry:

curl --retry 3 \
 --retry-delay 5 \
 --retry-connrefused \
 -X POST https://api.markdownconverters.com/api/v1/convert

Error Logging

Request ID: Always log the request_id for support issues.

Context: Include relevant request parameters in your logs.

Monitoring: Set up alerts for high error rates or specific error types.

Troubleshooting Guide

Common Issues & Solutions

Authentication keeps failing

  • Verify API key is correctly set in X-API-Key header
  • Check if API key has expired in your dashboard
  • Ensure you're using the correct environment (staging vs production)
  • Confirm your account subscription is active

File conversion fails

  • Verify file is properly Base64 encoded
  • Check file size doesn't exceed plan limits
  • Ensure file format is supported
  • Try with a known-good sample file

Rate limit errors

  • Implement exponential backoff in your retry logic
  • Check your current plan's rate limits
  • Consider upgrading to a higher plan if needed
  • Use batch conversion for multiple files

Getting Help

When contacting support, please include:

  • The request_id from the error response
  • Your API key (first/last 4 characters only)
  • Timestamp of the error
  • Complete error response
  • Sample request that's failing

Success Responses

HTTP 200 Success

Successful responses include the converted content and metadata:

{
 "job_id": "conv_1234567890abcdef",
 "status": "completed",
 "markdown_content": "# Document Title\n\nConverted content...",
 "metadata": {
 "original_filename": "document.pdf",
 "file_size": 1024000,
 "pages_processed": 5,
 "processing_time": 12.34,
 "ocr_confidence": 0.95
 },
 "request_id": "req_1234567890abcdef"
}

Next Steps