Per-model concurrency limiter with FIFO queue for managing request rates and concurrency. Use when throttling API calls or LLM requests in memory.
// Source: https://github.com/b3nw/omniroute-slim | License: MIT | Copyright 2026 diegosouzapw
// Provided via justclaw.it.com; keep this notice with the code.
/**
* Rate-Limit Semaphore
*
* Per-model concurrency limiter with FIFO queue for round-robin combo strategy.
* When a model is at max concurrency, requests wait in a queue instead of failing.
* When a model hits rate-limits, it's temporarily paused and queued requests wait.
*
* All state is in-memory — resets on server restart (by design, since rate-limit
* windows are typically short-lived).
*/
interface QueueItem {
resolve: (release: () => void) => void;
reject: (error: Error) => void;
timer: ReturnType<typeof setTimeout>;
}
interface ModelGate {
running: number;
max: number;
queue: QueueItem[];
rateLimite
... (truncated -- full source via MCP)
See the full source, get the GitHub permalink, and search for more like it.
Get a free API key