This covers the three main rate limiting algorithms you'll actually use: token bucket for smooth traffic shaping, sliding window for precision, and fixed window when you need something simple. The reference guides include Redis implementations, which is what you want for any production system that runs on multiple servers. It also handles the tiered limits scenario, so you can give paying customers higher quotas. The code examples are JavaScript and Python/Flask, and it reminds you to include the standard rate limit headers in responses. One thing to know: the best practices correctly warn against in-memory storage in production, but the quick start example is in-memory, so you'll need to jump to the Redis guide for real deployments.

skills.sh installs
647
GitHub stars
379
last updated
Aug 21, 2026

Install

$ npx -y skills add aj-geddes/useful-ai-prompts --skill api-rate-limiting --agent claude-code

Installs into .claude/skills of the current project.

Files

API Rate Limiting

Table of Contents

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:

// 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();

Sponsors

Details

Repository
github.com/aj-geddes/useful-ai-prompts
Categories
Backend & APIs, AI & Agent Building, Marketing & SEO
First seen
Jun 3, 2026

More from aj-geddes/useful-ai-prompts

All 258
1sickn33 avatarapi-documentersickn33/antigravity-awesome-skillsapi documenter628skills.sh installs
2manutej avataroauth2-authenticationmanutej/luxor-claude-marketplaceComprehensive OAuth2 authentication skill covering authorization flows, token management, PKCE, OpenID Connect, and security best practices for modern authentic603skills.sh installs
3encoredev avatarencore-go-apiencoredev/skillsDefine typed API endpoints in Encore Go using `//encore:api` annotations. Covers typed request/response structs, path/query/header/cookie params, and error retu597skills.sh installs
4aj-geddes avatardatabase-schema-documentationaj-geddes/useful-ai-promptsDocument database schemas, ERD diagrams, table relationships, indexes, and constraints. Use when documenting database schema, creating ERD diagrams, or writing 576skills.sh installs
5aj-geddes avatarapi-error-handlingaj-geddes/useful-ai-promptsImplement comprehensive API error handling with standardized error responses, logging, monitoring, retry logic, and validation patterns. Use when building resil513skills.sh installs
6yoanbernabeu avatarsupabase-audit-tables-readyoanbernabeu/supabase-pentest-skillsAttempt to read data from exposed tables to verify actual data exposure and RLS effectiveness.511skills.sh installs