Registry / devops / axios-rate-limit

axios-rate-limit

JSON →
library1.9.0jsnpmunverified

A zero-dependency, fixed-window, queued rate limiter for Axios (current stable version: 1.9.0). It automatically delays requests that exceed configurable per-interval limits. Supports multiple windows (e.g., per second and per minute), custom queue implementations, and works well with axios-retry and axios-cache-adapter. TypeScript types are included. Release cadence is low; updates are rare and maintenance-focused. Alternative to the built-in Axios rate-limiting (experimental).

npm install axios-rate-limit
INSTALL
IMPORT
SIG · AXIOS-RATE-LIMIT
A
axios-rate-limit
devopsjavascriptv1.9.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

rateLimit
import rateLimit from 'axios-rate-limit'
import { rateLimit } from 'axios-rate-limit'
Package uses a default export, not a named export.
RateLimitOptions
import type { RateLimitOptions } from 'axios-rate-limit'
TypeScript users should import types with `import type` for better tree-shaking.
http.getQueue
const queueSize = http.getQueue()
The return from rateLimit() has a getQueue() method returning pending count.

Creates an axios instance with a fixed-window rate limit of 5 requests per second.

import axios from 'axios'; import rateLimit from 'axios-rate-limit'; const http = rateLimit(axios.create({ baseURL: 'https://api.example.com' }), { maxRequests: 5, perMilliseconds: 1000, // Or use the newer `limits` array for multiple windows: // limits: [ // { maxRequests: 5, duration: '2s' }, // { maxRequests: 2, duration: '500ms' } // ] }); // This will make up to 5 requests per second for (let i = 0; i < 10; i++) { http.get('/v1/users.json?page=' + (i + 1)) .then(response => console.log(response.data)) .catch(error => console.error(error.message)); } console.log('Pending requests:', http.getQueue());
Debug
Known issues
gotcharateLimit function returns a modified axios instance; it should be created using `rateLimit(axiosInstance, options)` and then used normally.
fix
Always pass the return value of rateLimit() to your application code.
affects: >=1.0.0
deprecatedThe older options `maxRequests` and `perMilliseconds` are still supported but deprecated in favor of the `limits` array for multiple windows.
fix
Use `limits` array with `maxRequests` and `duration` (string or number in ms).
affects: <=1.9.0
gotchaThe `duration` field in the `limits` array expects a string like '2s' or a number in milliseconds – not seconds directly.
fix
Use string format (e.g., '1s', '500ms') or number in milliseconds.
affects: >=1.0.0
gotchaIf you use `rateLimit()` with a fresh axios instance (axios.create()), it replaces the original adapter; calling `rateLimit()` on the same instance again may cause unexpected behavior.
fix
Only call rateLimit() once per axios instance.
affects: >=1.0.0
Errors
Common errors & fixes
import { rateLimit } from 'axios-rate-limit'
Named import used on a default-exported module.
fix
Use default import: import rateLimit from 'axios-rate-limit'
TypeError: http.get is not a function
Calling rateLimit() on an object that is not an axios instance (e.g., forgot to call axios.create()).
fix
Ensure the first argument is a valid axios instance: const http = rateLimit(axios.create(), options);
Uncaught TypeError: axios is not a function
Using require('axios') in ESM context or missing dependency.
fix
Install axios and import correctly: import axios from 'axios';
Upgrade
Version history
1.9.0latest on npm
Audit
Dependencies
axiosrequiredpeer dependency required as the target HTTP client
Agent activity
12 hits · last 30 days
node
10
OpenAI (training)
1
Resources
axios-rate-limit — npm install axios-rate-limit · libregistry