API Reference

Errors

Error codes, handling strategies, and debugging tips.

Error Response Format

{
  "error": "Unauthorized",
  "message": "Invalid API key"
}
Field Type Description
error string Short error code or type
message string Human-readable description

HTTP Status Codes

400

Bad Request

Invalid request parameters or malformed JSON.

Common causes: Missing content, invalid JSON, content too large (>1MB), invalid PDF options
401

Unauthorized

Authentication failed or missing.

Common causes: Missing X-API-Key header, invalid or revoked API key
403

Forbidden

Feature requires a higher plan.

Common causes: Password protection requires Business+ plan
429

Too Many Requests

Rate limit or quota exceeded.

Response header: Retry-After: <seconds>
500

Internal Server Error

Unexpected error during PDF generation.

Common causes: Rendering failed, Chrome error, timeout, JavaScript error in HTML
503

Service Unavailable

Service temporarily unavailable.

Common causes: Service overloaded, no dedicated workers available for password protection
Resolution: Wait and retry. Check our status page

Common Errors

400
Provide content

Missing 'content' property for /pdf endpoint.

400
HTML content too large (max 1MB)

Reduce HTML size. Use external stylesheets or optimize embedded images.

400
Invalid JSON

Use a proper JSON encoder (JSON.stringify, json_encode) instead of manual building.

400
Internal/private URLs not allowed

Only public URLs are allowed (SSRF protection).

401
Missing X-API-Key header

Add the X-API-Key header with your API key to all requests.

429
Monthly quota exceeded

Upgrade your plan or wait for quota reset at next billing cycle.

403
Password protection requires Business plan or higher

Upgrade to Business+ plan to use PDF password protection.

503
No dedicated workers available

Password protection requires dedicated workers. Retry after 30 seconds.

failed
Upload failed: 403 Forbidden

Async job upload failed. Your presigned URL may be expired or invalid.

Error Handling Best Practices

Check response status

Verify HTTP status is 2xx before processing.

Implement retry logic

Exponential backoff for 429 and 503 errors.

Log errors

Log status code and message for debugging.

Set timeouts

Recommended: 30 second client timeout.

Retry Implementation

async function generatePdfWithRetry(content, maxRetries = 3) {
  let lastError;

  for (let attempt = 1; attempt <= maxRetries; attempt++) {
    try {
      const response = await fetch('https://api.tailpdf.com/pdf', {
        method: 'POST',
        headers: {
          'Content-Type': 'application/json',
          'X-API-Key': process.env.TAILPDF_API_KEY,
        },
        body: JSON.stringify({ content }),
      });

      if (response.ok) {
        return await response.arrayBuffer();
      }

      const error = await response.json();

      // Don't retry client errors (4xx except 429)
      if (response.status >= 400 && response.status < 500 && response.status !== 429) {
        throw new Error(`PDF generation failed: ${error.message}`);
      }

      lastError = new Error(error.message);

      // Exponential backoff
      const delay = Math.pow(2, attempt) * 1000;
      await new Promise(resolve => setTimeout(resolve, delay));

    } catch (err) {
      lastError = err;
      if (attempt === maxRetries) break;

      const delay = Math.pow(2, attempt) * 1000;
      await new Promise(resolve => setTimeout(resolve, delay));
    }
  }

  throw lastError;
}

Ready to get started?

Sign up free and start generating PDFs in minutes.

Create Free Account