agentskit.js
Security

Rate limiting

Token-bucket rate limiter keyed by user, IP, or API key — with Redis/Upstash support for multi-host deployments.

Without a rate limiter, a single user can exhaust your API budget or trigger abuse at scale. createRateLimiter enforces a token-bucket policy per request key and returns a retryAfterMs value you can forward directly in the retry-after header.

import { createRateLimiter } from '@agentskit/core/security'

const limiter = createRateLimiter({
  capacity: 10,
  refillPerSecond: 1,
  keyBy: (req) => req.userId,
})

app.post('/chat', async (req) => {
  const { allowed, retryAfterMs } = await limiter.take(req)
  if (!allowed) return new Response('Too Many Requests', { status: 429, headers: { 'retry-after': `${Math.ceil(retryAfterMs / 1000)}` } })
  // ... run agent
})

#Storage

In-memory storage works for a single host. For multi-host deployments, pass a { get, set } adapter backed by Redis, Upstash, or any key/value store.

Explore nearby

✎ Edit this page on GitHub·Found a problem? Open an issue →·How to contribute →

On this page