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);
}
}