Skip to main content
skill CX Codex

api-rate-limiting · secondsky — Claude Code skill: API rate limiting

A skill that walks you through rate limiting an API with token bucket, sliding window and Redis-backed counters. Useful when you open an endpoint to the public or split access by plan.

Install into Claude Code · Skills CLI (Vercel) All methods and platforms ↓
npx skills add secondsky/claude-skills --skill api-rate-limiting -a claude-code
Open on GitHub

What api-rate-limiting does

The skill hands you code for three algorithms. Token bucket absorbs bursts, sliding window counts more precisely, fixed window is the simplest but spikes at the boundary. Pick based on whether memory or accuracy matters more to you.

You get a TokenBucket class in Node.js with consume() and refill(), Express middleware built on express-rate-limit with a 15-minute window and a max of 100 requests, plus the response headers: X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset and Retry-After. For a shared counter the skill points at Redis. Without it your limits will disagree across app instances, so check that first if you run more than one replica.

There is also a tier table: Free at 100 requests per hour, Pro at 1,000, Enterprise at 10,000. The practice list covers returning 429 with Retry-After, watching rate limit metrics and testing under load. Treat all of it as examples to adapt, not a config for your project.

What it helps with

  • cap request volume on a public API
  • give Free, Pro and Enterprise plans different limits
  • smooth traffic bursts with a token bucket
  • return 429 with a Retry-After header
  • share a request counter across instances via Redis

Example prompts for the agent

  • add rate limiting to /api/ at 100 requests per 15 minutes
  • set up a token bucket for the file upload endpoint
  • split limits by plan: Free 100, Pro 1000, Enterprise 10000 requests per hour

How to install api-rate-limiting

1Skills CLI (Vercel)

npx skills add secondsky/claude-skills --skill api-rate-limiting -a claude-code

2Manually: put the files in place

~/.claude/skills/api-rate-limiting/SKILL.md

Copy the whole skill folder; for one project use .claude/skills/api-rate-limiting/

Step by step, with commands for each platform: How to install skills in Claude Code: five ways

Questions about api-rate-limiting

How do I install api-rate-limiting in Claude?

Run npx skills add secondsky/claude-skills --skill api-rate-limiting -a claude-code. The skill file then lands at ~/.claude/skills/api-rate-limiting/SKILL.md.

What does api-rate-limiting do?

It shows how to throttle API requests: three algorithms, Express middleware, response headers and a per-tier limit table.

Do I need Redis for this skill?

Redis is named as the way to make limits distributed. A single-process app can get by with an in-memory counter.

Source text

SKILL.md · MIT
---
name: api-rate-limiting
description: Implements API rate limiting using token bucket, sliding window, and Redis-based algorithms to protect against abuse. Use when securing public APIs, implementing tiered access, or preventing denial-of-service attacks.
license: MIT
---

# API Rate Limiting

Protect APIs from abuse using rate limiting algorithms with per-user and per-endpoint strategies.

## Algorithms

| Algorithm | Pros | Cons |
|-----------|------|------|
| Token Bucket | Handles bursts, smooth | Memory per user |
| Sliding Window | Accurate | Memory intensive |
| Fixed Window | Simple | Boundary spikes |

## Token Bucket (Node.js)

```javascript
class TokenBucket {
  constructor(capacity, refillRate) {
    this.capacity = capacity;
    this.tokens = capacity;
    this.refillRate = refillRate; // tokens per second
    this.lastRefill = Date.now();
  }

  consume() {
    this.refill();
    if (this.tokens >= 1) {
      this.tokens--;
      return true;
    }
    return false;
  }

  refill() {
    const now = Date.now();
    const elapsed = (now - this.lastRefill) / 1000;
    this.tokens = Math.min(this.capacity, this.tokens + elapsed * this.refillRate);
    this.lastRefill = now;
  }
}
```

## Express Middleware

```javascript
const rateLimit = require('express-rate-limit');

const limiter = rateLimit({
  windowMs: 15 * 60 * 1000, // 15 minutes
  max: 100,
  standardHeaders: true,
  message: { error: 'Too many requests, try again later' }
});

app.use('/api/', limiter);
```

## Response Headers

```
X-RateLimit-Limit: 100
X-RateLimit-Remaining: 45
X-RateLimit-Reset: 1705320000
Retry-After: 60
```

## Tiered Limits

| Tier | Requests/Hour |
|------|---------------|
| Free | 100 |
| Pro | 1,000 |
| Enterprise | 10,000 |

## Best Practices

- Use Redis for distributed rate limiting
- Include proper headers in responses
- Return 429 status with Retry-After
- Implement tiered limits for different plans
- Monitor rate limit metrics
- Test under load

© secondsky · MIT · secondsky/claude-skills

Similar skills

Everything for Backend and APIs →

api-rate-limiting by other authors comes first.

From the same set89

Project sponsors

Companies that keep this analytics open
Gold sponsor

Impressions, clicks and code copies — open statistics. We keep the numbers public for the same reason NeBlask itself is public. Become a sponsor