venice-ai-sdk-apl
Version:
A comprehensive SDK for the Venice AI API with CLI support, programmatic CLI usage, CLI-style interface, and interactive demo
54 lines • 1.8 kB
JavaScript
;
/**
* Rate Limit Error class
*
* This class represents rate limit errors returned by the Venice AI API.
* It includes information about the rate limit such as the limit, remaining,
* and reset time.
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.RateLimitError = void 0;
const api_error_1 = require("./api-error");
/**
* Rate Limit Error class
*/
class RateLimitError extends api_error_1.ApiError {
/**
* Creates a new rate limit error
*
* @param options - Error options
*/
constructor(options) {
super(options);
this.name = 'RateLimitError';
this.rateLimitInfo = options.rateLimitInfo;
// This is needed for proper instanceof checks in TypeScript
Object.setPrototypeOf(this, RateLimitError.prototype);
}
/**
* Returns a string representation of the error
*/
toString() {
let message = `${this.name}: [${this.code}] ${this.message} (${this.status})`;
if (this.rateLimitInfo) {
const { limit, remaining, reset } = this.rateLimitInfo;
const resetDate = new Date(reset * 1000).toISOString();
message += `\nRate limit: ${remaining}/${limit}, resets at ${resetDate}`;
}
return message;
}
/**
* Returns the time in milliseconds until the rate limit resets
*/
getRetryAfterMs() {
if (this.rateLimitInfo?.reset) {
const now = Math.floor(Date.now() / 1000);
const resetTime = this.rateLimitInfo.reset;
return Math.max(0, resetTime - now) * 1000;
}
// Default to 60 seconds if no reset time is available
return 60 * 1000;
}
}
exports.RateLimitError = RateLimitError;
//# sourceMappingURL=rate-limit-error.js.map