Limit API

Limit

import { limit } from "limit-api";
 
const { status, data } = await limit(
  {
    apiKey: string,
  },
  {
    tag: string,
 
    key: string,
 
    // Optional if not provided the limiter will consume 1 token
    value: number,
 
    // See [Limiter Config] page for the different limiter configurations
    config: TokenBucketLimiterConfig | FixedWindowLimiterConfig,
  }
);
 
if (status === "success") {
  // The request was allowed
  const {
    throughputExceeded, // boolean
    valueRemaining, // number
  } = data;
} else if (status === "blocked") {
  // The request was usage or rate limited
  const {
    throughputExceeded, // boolean
    valueRemaining, // number
  } = data;
} else {
  // An error occurred such as a network error, invalid API key, etc.
  const {
    message, // string
    debugMessage, // optional string
  } = data;
}