API Documentation

v1.0.0

Error Handling

Understand API errors, error codes, and how to handle them gracefully in your applications.

Error Response Format

All API errors follow a consistent format:

{
  "success": false,              // Always false for errors
  "error": {
    "code": "ERROR_CODE",        // Machine-readable error code
    "message": "Description",    // Human-readable error message
    "details": {                 // Optional additional context
      "field": "specific info"
    }
  },
  "meta": {
    "request_id": "req_...",     // Unique request identifier
    "timestamp": "2025-01-15T10:30:00Z",
    "version": "v1"
  }
}

HTTP Status Codes

The API uses standard HTTP status codes:

StatusMeaningWhen It Happens
200OKRequest succeeded
400Bad RequestInvalid request body or parameters
401UnauthorizedMissing or invalid API key
403ForbiddenAPI key lacks required permissions
404Not FoundResource not found (e.g., source file)
429Too Many RequestsRate limit exceeded
500Internal Server ErrorUnexpected server error
503Service UnavailableService temporarily unavailable

Error Codes

Authentication Errors

CodeStatusDescriptionSolution
UNAUTHORIZED401Invalid or missing API keyCheck Authorization header format and API key validity
FORBIDDEN403API key lacks required permissionsGenerate a new API key with the correct permissions

Request Errors

CodeStatusDescriptionSolution
INVALID_REQUEST400Malformed request body or missing required fieldsCheck request body matches the schema
UNSUPPORTED_FORMAT400The specified format is not supportedUse the /formats endpoint to see supported formats
FILE_NOT_FOUND404Source file not found at the specified pathVerify file was uploaded successfully and path is correct
FILE_TOO_LARGE400File exceeds maximum size limit (50 MB)Split large files or contact support for enterprise options

Rate Limiting Errors

CodeStatusDescriptionSolution
RATE_LIMITED429Rate limit exceeded for this endpointWait for the rate limit to reset (see Retry-After header)

Conversion Errors

CodeStatusDescriptionSolution
CONVERSION_FAILED500File conversion process failedCheck file is valid for source format; contact support with request_id
INVALID_FILE_FORMAT400File content doesn't match specified formatVerify file is actually in the format you specified

Server Errors

CodeStatusDescriptionSolution
INTERNAL_ERROR500An unexpected error occurredRetry the request; if it persists, contact support with request_id
SERVICE_UNAVAILABLE503Service temporarily unavailableWait a moment and retry; check status page for ongoing incidents

Common Error Scenarios

Scenario 1: Invalid API Key

Error:

{
  "success": false,
  "error": {
    "code": "UNAUTHORIZED",
    "message": "Invalid or missing API key"
  }
}

Causes:

  • API key not included in Authorization header
  • Incorrect header format (should be "Bearer YOUR_KEY")
  • API key has been revoked or deleted
  • API key has expired

Solution:

# Correct format
curl https://agentsfordata.com/api/public/v1/convert/formats \
  -H "Authorization: Bearer tablab_api_xxxxx"

# Not this
-H "Authorization: tablab_api_xxxxx"  # Missing "Bearer"
-H "X-API-Key: tablab_api_xxxxx"       # Wrong header name

Scenario 2: Unsupported Format

Error:

{
  "success": false,
  "error": {
    "code": "UNSUPPORTED_FORMAT",
    "message": "The format 'pdf' is not supported",
    "details": {
      "format": "pdf"
    }
  }
}

Solution:

Check available formats using the formats endpoint:

curl https://agentsfordata.com/api/public/v1/convert/formats \
  -H "Authorization: Bearer YOUR_KEY"

Scenario 3: File Not Found

Error:

{
  "success": false,
  "error": {
    "code": "FILE_NOT_FOUND",
    "message": "Source file not found",
    "details": {
      "file_path": "2025-01-15/abc123/source-file.csv"
    }
  }
}

Common Causes:

  • File upload to signed URL failed
  • Wrong file_path passed to /convert endpoint
  • File expired (signed URLs expire after 5 minutes)

Solution:

  1. Verify upload succeeded (check HTTP status 200/204)
  2. Use exact file_path from /upload-urls response
  3. Complete conversion within 5 minutes of getting URLs

Scenario 4: Rate Limit Exceeded

Error:

{
  "success": false,
  "error": {
    "code": "RATE_LIMITED",
    "message": "Rate limit exceeded for this endpoint",
    "details": {
      "limit": 10,
      "window": "minute",
      "retry_after": 45
    }
  }
}

Solution:

if (response.status === 429) {
  const retryAfter = data.error.details.retry_after;
  console.log(`Waiting ${retryAfter} seconds...`);
  await new Promise(resolve => setTimeout(resolve, retryAfter * 1000));
  // Retry request
}

Error Handling Best Practices

1. Always Check the Success Field

const data = await response.json();
if (!data.success) {
  console.error('API Error:', data.error.code, data.error.message);
  // Handle error based on error code
  switch (data.error.code) {
    case 'UNAUTHORIZED':
      // Redirect to login or show API key error
      break;
    case 'RATE_LIMITED':
      // Implement retry with backoff
      break;
    case 'UNSUPPORTED_FORMAT':
      // Show user error about format
      break;
    default:
      // Generic error handling
  }
}

2. Save Request IDs for Debugging

if (!data.success) {
  const requestId = data.meta.request_id;
  console.error(`Error ${data.error.code}: ${data.error.message}`);
  console.error(`Request ID: ${requestId}`);
  
  // Save to logs for support team
  logError({
    code: data.error.code,
    message: data.error.message,
    requestId: requestId,
    timestamp: new Date()
  });
}

3. Implement Exponential Backoff

async function fetchWithRetry(url, options, maxRetries = 3) {
  for (let i = 0; i < maxRetries; i++) {
    try {
      const response = await fetch(url, options);
      const data = await response.json();
      
      if (response.ok && data.success) {
        return data;
      }
      
      // Don't retry client errors (except 429)
      if (response.status >= 400 && response.status < 500 && response.status !== 429) {
        throw new Error(data.error.message);
      }
      
      // Retry on server errors and rate limits
      if (i < maxRetries - 1) {
        const delay = Math.min(1000 * Math.pow(2, i), 32000);
        await new Promise(resolve => setTimeout(resolve, delay));
        continue;
      }
      
      throw new Error(data.error.message);
      
    } catch (error) {
      if (i === maxRetries - 1) throw error;
    }
  }
}

4. Validate Before Sending

// Validate format before making API call
const supportedFormats = ['csv', 'json', 'xlsx', 'parquet', 'tsv'];

function validateConversion(sourceFormat, destFormat) {
  if (!supportedFormats.includes(sourceFormat)) {
    throw new Error(`Unsupported source format: ${sourceFormat}`);
  }
  if (!supportedFormats.includes(destFormat)) {
    throw new Error(`Unsupported destination format: ${destFormat}`);
  }
  if (sourceFormat === destFormat) {
    throw new Error('Source and destination formats must be different');
  }
}

// Use before API call
try {
  validateConversion('csv', 'json');
  // Make API call
} catch (error) {
  console.error('Validation error:', error.message);
  // Show user-friendly error without making API call
}

5. Handle Network Errors

try {
  const response = await fetch(url, options);
  const data = await response.json();
  // Handle response
} catch (error) {
  if (error.name === 'TypeError' && error.message === 'Failed to fetch') {
    console.error('Network error: Check your internet connection');
  } else if (error.name === 'AbortError') {
    console.error('Request timeout');
  } else {
    console.error('Unexpected error:', error);
  }
}

Getting Help

If you encounter errors you can't resolve:

  1. Check this error reference for solutions
  2. Review the Getting Started guide
  3. Verify your request matches the endpoint schemas
  4. Check our status page for ongoing incidents
  5. Contact support with your request_id

Contact Support

When contacting support, include:

  • The request_id from the error response
  • The error code and message
  • The endpoint you were calling
  • What you were trying to do

Email: support@agentsfordata.com