Batch Limit
When using the batch limit api if any of the limiters fail none of them will be recorded.
import { batchLimit } from "limit-api";
const { status, data } = await batchLimit(
{
apiKey: string,
},
{
// Min 1, max 3 limiters
limitRequests: {
// The limiterId is used to return limiter specific data in the response such as tokens remaining per limiter.
[limiterId: string]: {
tag: string,
key: string;
value: number;
config:
TokenBucketLimiterConfig | FixedWindowLimiterConfig;
};
};
}
);
if (status === "success") {
// The request was allowed
const {
responses,
} = data;
// The responses object will have the limiterId as the key and the limiter response as the value.
// eg. if limiterId === "limiter1"
const {
throughputExceeded, // boolean
valueRemaining, // number
} = responses["limiter1"];
} else if (status === "blocked") {
// The request was usage or rate limited
const {
responses,
} = data;
} else {
// An error occurred such as a network error, invalid API key, etc.
const {
message, // string
debugMessage, // optional string
} = data;
}