Skip to main content
skill CX Codex

api-rate-limiting · aj-geddes — Claude Code skill: what it does, how to install

Guides the implementation of token bucket and sliding window rate limiting. Protects APIs from brute force attacks and traffic surges using Redis or Flask.

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

What api-rate-limiting does

The skill provides patterns for fixed window, sliding window, and token bucket rate limiting algorithms. It covers traffic control policies organized by user identity, client IP, or specific endpoints.

Inside are implementation guides for distributed setups with Redis, Flask apps in Python, and standardized HTTP response headers. In-memory counters are explicitly marked as unsuitable for production environments, requiring distributed clusters to rely on Redis instead.

What it helps with

  • protect endpoints from brute force and DoS traffic
  • implement distributed rate limiting backed by Redis
  • structure tiered usage plans for different accounts
  • return standardized rate limit headers with Retry-After guidance

Example prompts for the agent

  • Create a sliding window rate limiter in Flask for our public API.
  • Implement a Redis-backed token bucket algorithm for per-user limits.
  • Set up response headers with Retry-After for throttled requests.

How to install api-rate-limiting

1Skills CLI (Vercel)

npx skills add aj-geddes/useful-ai-prompts --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 Code?

Run the following command in your terminal: npx skills add aj-geddes/useful-ai-prompts --skill api-rate-limiting -a claude-code.

What does api-rate-limiting do?

It supplies blueprints and code guides for algorithms like token bucket and sliding window. The skill helps enforce quota tiers and defend endpoints against spikes or abusive traffic.

Can in-memory storage be used for rate limiting in production?

The guide specifically advises against using in-memory stores in production. Distributed environments lose track of counts across nodes, requiring shared backends like Redis.

Source text

SKILL.md · MIT
---
name: api-rate-limiting
description: >
  Implement API rate limiting strategies using token bucket, sliding window, and
  fixed window algorithms. Use when protecting APIs from abuse, managing
  traffic, or implementing tiered rate limits.
---

# API Rate Limiting

## Table of Contents

- [Overview](#overview)
- [When to Use](#when-to-use)
- [Quick Start](#quick-start)
- [Reference Guides](#reference-guides)
- [Best Practices](#best-practices)

## Overview

Protect APIs from abuse and manage traffic using various rate limiting algorithms with per-user, per-IP, and per-endpoint strategies.

## When to Use

- Protecting APIs from brute force attacks
- Managing traffic spikes
- Implementing tiered service plans
- Preventing DoS attacks
- Fairness in resource allocation
- Enforcing quotas and usage limits

## Quick Start

Minimal working example:

```javascript
// Token Bucket Rate Limiter
class TokenBucket {
  constructor(capacity, refillRate) {
    this.capacity = capacity;
    this.tokens = capacity;
    this.refillRate = refillRate; // tokens per second
    this.lastRefillTime = Date.now();
  }

  refill() {
    const now = Date.now();
    const timePassed = (now - this.lastRefillTime) / 1000;
    const tokensToAdd = timePassed * this.refillRate;

    this.tokens = Math.min(this.capacity, this.tokens + tokensToAdd);
    this.lastRefillTime = now;
  }

  consume(tokens = 1) {
    this.refill();

    if (this.tokens >= tokens) {
      this.tokens -= tokens;
      return true;
    }
// ... (see reference guides for full implementation)
```

## Reference Guides

Detailed implementations in the `references/` directory:

| Guide | Contents |
|---|---|
| [Token Bucket Algorithm](references/token-bucket-algorithm.md) | Token Bucket Algorithm |
| [Sliding Window Algorithm](references/sliding-window-algorithm.md) | Sliding Window Algorithm |
| [Redis-Based Rate Limiting](references/redis-based-rate-limiting.md) | Redis-Based Rate Limiting |
| [Tiered Rate Limiting](references/tiered-rate-limiting.md) | Tiered Rate Limiting |
| [Python Rate Limiting (Flask)](references/python-rate-limiting-flask.md) | Python Rate Limiting (Flask) |
| [Response Headers](references/response-headers.md) | Response Headers |

## Best Practices

### ✅ DO

- Include rate limit headers in responses
- Use Redis for distributed rate limiting
- Implement tiered limits for different user plans
- Set appropriate window sizes and limits
- Monitor rate limit metrics
- Provide clear retry guidance
- Document rate limits in API docs
- Test under high load

### ❌ DON'T

- Use in-memory storage in production
- Set limits too restrictively
- Forget to include Retry-After header
- Ignore distributed scenarios
- Make rate limits public (security)
- Use simple counters for distributed systems
- Forget cleanup of old data

© aj-geddes · MIT · aj-geddes/useful-ai-prompts

Similar skills

Everything for Backend and APIs →

api-rate-limiting by other authors comes first.

From the same set118

log-analysis A skill that helps the agent read application and system logs: spot errors, recurring patterns and the root cause of a failure. Useful when a service breaks and you need answers. CX Codex +1 657installs image-optimization A skill that walks your agent through compressing images and picking modern formats. Useful before a deploy, when pages drag on mobile networks. CX Codex +1 656installs requirements-gathering Walks your agent through collecting and documenting stakeholder requirements before development starts. Useful at project kickoff and feature planning. CX Codex +1 655installs ruby-rails-application Guides building Ruby on Rails applications with Active Record models, RESTful controllers, and JWT authentication. Best for structuring Rails APIs and managing database schemas. CX Codex +1 655installs information-architecture Structures content, sitemaps, and taxonomies for web apps and documentation hubs. It guides your AI agent through a four-stage process from card sorting to tree testing. CX Codex +1 634installs internationalization-i18n A skill that walks your agent through shipping a multi-language app: string extraction, translation catalogs, plurals, locale-aware dates and numbers, RTL. CX Codex +1 633installs github-actions-workflow A skill that helps your agent write GitHub Actions workflows for tests, builds, security scans and deploys. CX Codex +1 620installs backup-disaster-recovery A skill that helps the agent plan database backups, disaster recovery and cross-region failover for your infrastructure. CX Codex +1 620installs

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