Skip to main content

Error Classes

The SDK throws typed errors so you can handle specific failure cases. All errors include a requestId for debugging.
import UpliftAI, {
  UpliftAIError,
  UpliftAIAuthError,                // 401
  UpliftAIInsufficientBalanceError,  // 402
  UpliftAIRateLimitError,            // 429
} from '@upliftai/sdk-js';

const client = new UpliftAI({
  apiKey: 'your-api-key',
});

try {
  const { audio } = await client.tts.create({
    text: 'ٹیسٹ',
    voiceId: 'v_meklc281',
  });
} catch (err) {
  if (err instanceof UpliftAIAuthError) {
    // 401 — invalid or missing API key
    console.error('Check your API key');
  } else if (err instanceof UpliftAIRateLimitError) {
    // 429 — rate limited (auto-retried based on maxRetries)
    console.error('Rate limited, back off and retry');
  } else if (err instanceof UpliftAIInsufficientBalanceError) {
    // 402 — top up your account
    console.error('Insufficient balance');
  } else if (err instanceof UpliftAIError) {
    // Other API errors
    console.error(err.statusCode, err.code, err.requestId);
  }
}

Automatic Retries

The SDK automatically retries on transient errors with exponential backoff and jitter:
Status CodeDescriptionAuto-Retried?
408Request TimeoutYes
429Rate LimitedYes
500Internal Server ErrorYes
502Bad GatewayYes
503Service UnavailableYes
504Gateway TimeoutYes
401UnauthorizedNo
402Insufficient BalanceNo
400Bad RequestNo
Configure retry behavior via the maxRetries client option:
const client = new UpliftAI({
  apiKey: 'your-api-key',
  maxRetries: 3, // default is 2
  timeout: 60000, // default is 30000ms
});