interface RateLimitAddon {
    rateLimit?: {
        defaultWaitTime?: number;
        getReset?: (res: Response) => MaybePromise<null | string | number>;
        isRejected?: (res: Response) => MaybePromise<boolean>;
        jitter?: number;
        maxRetries?: number;
        maxWaitTime?: number;
        onRateLimitExceeded?: (res: Response, waitTime: number) => void;
    };
}

Properties

Properties

rateLimit?: {
    defaultWaitTime?: number;
    getReset?: (res: Response) => MaybePromise<null | string | number>;
    isRejected?: (res: Response) => MaybePromise<boolean>;
    jitter?: number;
    maxRetries?: number;
    maxWaitTime?: number;
    onRateLimitExceeded?: (res: Response, waitTime: number) => void;
}

Type declaration

  • OptionaldefaultWaitTime?: number

    when the rate limit is exceeded (i.e. isRejected returns true), but the reset time is unknown (i.e. getReset returns null), what is the default time to wait until the rate limit is reset? in milliseconds

    30_000

  • OptionalgetReset?: (res: Response) => MaybePromise<null | string | number>

    getter for the unix timestamp of the next reset can either be a unix timestamp in seconds or an ISO 8601 date string

    res => res.headers.get('x-ratelimit-reset')

  • OptionalisRejected?: (res: Response) => MaybePromise<boolean>

    check if the request was rejected due to rate limit

    res => res.status === 429

  • Optionaljitter?: number

    number of milliseconds to add to the reset time when the rate limit is exceeded, to account for network latency and other factors

    5000

  • OptionalmaxRetries?: number

    maximum number of retries

    3

  • OptionalmaxWaitTime?: number

    when the rate limit has exceeded (i.e. isRejected returns true), what is the maximum acceptable time to wait until the rate limit is reset? in milliseconds

    300_000

  • OptionalonRateLimitExceeded?: (res: Response, waitTime: number) => void

    function that will be called when the rate limit is exceeded (i.e. isRejected returns true), but before starting the wait timer