# p-limit — card for AI agents

Run multiple async functions with limited concurrency to control resource usage.

Category: Utilities · npm package `p-limit` · latest version 7.3.3 (checked 2026-11-01)
Install: `npm install p-limit`
License: MIT (permissive)

In your own product (generator, app, hosted service): **yes**. Permissive license: ship it inside your own product, closed or open source, and keep its license and copyright notice.

## Numbers (AgentGid data)
- Gid Score: 66.2 (#598 of all tools, 71 of 408 in its category)
- Used in 29 public projects set up for AI coding agents (0.5%)
- Downloads last week: 469,021,115 (as of 2026-11-24), +35.4% over 4 weeks
- GitHub stars: 2,943 (as of 2026-11-24)
- Last push: 2026-09-18

## Often used with
Vitest 82.8%, tsx 69.0%, dotenv 62.1%, Zod 79.3%, TypeScript 100.0%, ws 44.8%

## Links
- AgentGid page: https://agentgid.com/tools/p-limit/
- Homepage: https://github.com/sindresorhus/p-limit#readme
- Repository: https://github.com/sindresorhus/p-limit


## p-limit: run many slow jobs, only a few at once

p-limit is a tiny free JavaScript library that caps how many slow jobs run at the same time, such as downloads, file reads or calls to an AI service. Other jobs wait in line and start as soon as a slot frees up. Your app stays fast without flooding a server or hitting its limits.

### Where to use it
- Fetch many pages, three at a time: Your script loads a list of pages or records from a service; it keeps only a few requests open so the service does not block you.
- Process a folder of uploads: A batch job reads hundreds of uploaded files; five at a time keeps memory and disk use steady.
- Slow down when a service says wait: When an AI or data service answers "too many requests", lower the number of parallel calls on the fly, then raise it again.
- Keep going when some calls fail: One broken link should not stop a run of a thousand; collect the good results and list the failures at the end.
- Show progress of a long run: Print how many jobs are running and how many still wait, so people know a long import is moving.
- Batch AI calls for a spreadsheet: Your assistant writes a script that summarizes 500 rows with an AI service, four requests at a time, to stay within the plan's limits. (idea, not from the official pages)

### How to start
- Add the package (it needs Node.js 20 or newer, or any modern browser via a bundler).

```
npm install p-limit
```

- Make a limiter with the number of jobs allowed at once, and wrap each job in it.

```
import pLimit from 'p-limit';

const limit = pLimit(1);

const input = [
	limit(() => fetchSomething('foo')),
	limit(() => fetchSomething('bar')),
	limit(() => doSomething())
];

// Only one promise is run at once
const result = await Promise.all(input);
console.log(result);
```


### License
Free to use in any project, paid or not, under the MIT license. No visible credit is needed; keep the license notice with copies of its files.

### Good to know
- It limits how many jobs run at the same moment, not how many start per second. For a per-second cap, use a throttle library.
- Do not call the same limiter from inside a job it is already running; the inner job may wait forever.
- Clearing the line drops waiting jobs but does not stop jobs that are already running.
- Version 7 needs Node.js 20 or newer, and since version 4 it only loads with import, not require.

Checked 2026-11-10 against: https://github.com/sindresorhus/p-limit/blob/main/readme.md, https://github.com/sindresorhus/p-limit/blob/main/recipes.md, https://github.com/sindresorhus/p-limit/blob/main/license, https://github.com/sindresorhus/p-limit/releases/tag/v7.3.3, https://github.com/sindresorhus/p-limit/releases/tag/v7.0.0, https://github.com/sindresorhus/p-limit/releases/tag/v4.0.0, https://registry.npmjs.org/p-limit, https://registry.npmjs.org/p-limit/7.3.3

### Mistakes to avoid
- Don't: const pLimit = require('p-limit') in a CommonJS file → Do: import pLimit from 'p-limit' in an ES module (or const { default: pLimit } = await import('p-limit')) (The package has been ES module only since version 4.)
- Don't: Calling limit(...) again inside a job that is already running under the same limit → Do: Use a second, separate limiter for inner jobs (The outer jobs hold every slot while they wait for inner jobs that can never start.)
- Don't: limit.clearQueue() while code still awaits Promise.all of the queued jobs → Do: Create the limiter with pLimit({concurrency: 3, rejectOnClear: true}) so cleared jobs reject with AbortError (Without that option the cleared jobs' promises never settle, so the await hangs.)
- Don't: Using p-limit to keep under "60 requests per minute" → Do: Use p-throttle (calls per time window), or combine it with p-limit (p-limit counts jobs running at the same moment; fast jobs can still exceed a per-minute cap.)
- Don't: Installing p-limit 7 on Node.js 18 → Do: Use Node.js 20 or newer (Version 7 raised the minimum to Node.js 20.)

### Questions
- How is it different from p-queue? p-limit only caps how many jobs run at once. p-queue is a full queue with more options, inspection and pausing.
- Can I change the limit while it runs? Yes. Set limit.concurrency to a new number; the recipes lower it when a service answers 429 and raise it again later.
- Does it work in the browser? Yes, the readme says it works in Node.js and browsers.
- Are results returned in the order I passed the jobs? Yes. limit.map works like Promise.all over the inputs, so results keep the input order even when jobs finish in a different order.
- Is it still maintained? Yes. Version 7.3.3 came out on 2026-09-18 with a fix for limit.map.

---
AgentGid's catalog is curated: every entry was checked against the maker's official pages (registry, repository, license and pricing pages) on the date shown; a license value shows the quote it stands on wherever AgentGid has one. Usage numbers come from AgentGid's own scan of public repositories set up for AI coding agents. Claims by makers are reported, not tested by AgentGid.
