RelayAPI
Guides

Error Handling

Understanding and handling API errors.

Error Format

All errors follow a consistent format:

{
  "error": {
    "code": "VALIDATION_ERROR",
    "message": "Content is required",
    "details": {
      "field": "content",
      "issue": "required"
    }
  }
}

HTTP Status Codes

CodeDescription
400Bad Request — Invalid parameters or request body
401Unauthorized — Missing or invalid API key
403Forbidden — Insufficient permissions
404Not Found — Resource doesn't exist
409Conflict — Resource already exists
422Unprocessable — Valid request but cannot be processed
429Rate Limited — Too many requests
500Internal Error — Something went wrong on our end

Error Codes

CodeDescription
VALIDATION_ERRORRequest body or parameters failed validation
AUTHENTICATION_ERRORAPI key is missing, invalid, or expired
AUTHORIZATION_ERRORAPI key lacks required permissions
NOT_FOUNDThe requested resource was not found
RATE_LIMITEDRequest rate limit exceeded
PLATFORM_ERRORThe target platform returned an error
PUBLISH_FAILEDPost could not be published to one or more platforms

Retry Strategy

For 429 and 500 errors, implement exponential backoff:

async function withRetry(fn: () => Promise<Response>, maxRetries = 3) {
  for (let i = 0; i < maxRetries; i++) {
    const response = await fn();
    if (response.status !== 429 && response.status < 500) return response;
    await new Promise((r) => setTimeout(r, Math.pow(2, i) * 1000));
  }
  throw new Error("Max retries exceeded");
}

On this page