File contents 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();
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
Token Bucket Algorithm
Sliding Window Algorithm
Sliding Window Algorithm
Redis-Based Rate Limiting
Redis-Based Rate Limiting
Tiered Rate Limiting
Tiered Rate Limiting
Python Rate Limiting (Flask)
Python Rate Limiting (Flask)
Response Headers
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
Converted and distributed by TomeVault — claim your Tome and manage your conversions.
1 --- 2 name: aj-geddes-useful-ai-prompts-api-rate-limiting 3 description: API Rate Limiting 4 --- 5 6 # API Rate Limiting 7 8 ## Table of Contents 9 10 - [Overview](#overview) 11 - [When to Use](#when-to-use) 12 - [Quick Start](#quick-start) 13 - [Reference Guides](#reference-guides) 14 - [Best Practices](#best-practices) 15 16 ## Overview 17 18 Protect APIs from abuse and manage traffic using various rate limiting algorithms with per-user, per-IP, and per-endpoint strategies. 19 20 ## When to Use 21 22 - Protecting APIs from brute force attacks 23 - Managing traffic spikes 24 - Implementing tiered service plans 25 - Preventing DoS attacks 26 - Fairness in resource allocation 27 - Enforcing quotas and usage limits 28 29 ## Quick Start 30 31 Minimal working example: 32 33 ```javascript 34 // Token Bucket Rate Limiter 35 class TokenBucket { 36 constructor(capacity, refillRate) { 37 this.capacity = capacity; 38 this.tokens = capacity; 39 this.refillRate = refillRate; // tokens per second 40 this.lastRefillTime = Date.now(); 41 } 42 43 refill() { 44 const now = Date.now(); 45 const timePassed = (now - this.lastRefillTime) / 1000; 46 const tokensToAdd = timePassed * this.refillRate; 47 48 this.tokens = Math.min(this.capacity, this.tokens + tokensToAdd); 49 this.lastRefillTime = now; 50 } 51 52 consume(tokens = 1) { 53 this.refill(); 54 55 if (this.tokens >= tokens) { 56 this.tokens -= tokens; 57 return true; 58 } 59 // ... (see reference guides for full implementation) 60 ``` 61 62 ## Reference Guides 63 64 Detailed implementations in the `references/` directory: 65 66 | Guide | Contents | 67 |---|---| 68 | [Token Bucket Algorithm](references/token-bucket-algorithm.md) | Token Bucket Algorithm | 69 | [Sliding Window Algorithm](references/sliding-window-algorithm.md) | Sliding Window Algorithm | 70 | [Redis-Based Rate Limiting](references/redis-based-rate-limiting.md) | Redis-Based Rate Limiting | 71 | [Tiered Rate Limiting](references/tiered-rate-limiting.md) | Tiered Rate Limiting | 72 | [Python Rate Limiting (Flask)](references/python-rate-limiting-flask.md) | Python Rate Limiting (Flask) | 73 | [Response Headers](references/response-headers.md) | Response Headers | 74 75 ## Best Practices 76 77 ### ✅ DO 78 79 - Include rate limit headers in responses 80 - Use Redis for distributed rate limiting 81 - Implement tiered limits for different user plans 82 - Set appropriate window sizes and limits 83 - Monitor rate limit metrics 84 - Provide clear retry guidance 85 - Document rate limits in API docs 86 - Test under high load 87 88 ### ❌ DON'T 89 90 - Use in-memory storage in production 91 - Set limits too restrictively 92 - Forget to include Retry-After header 93 - Ignore distributed scenarios 94 - Make rate limits public (security) 95 - Use simple counters for distributed systems 96 - Forget cleanup of old data 97 98 --- 99 > Converted and distributed by [TomeVault](https://tomevault.io/claim/aj-geddes) — claim your Tome and manage your conversions. 100 <!-- tomevault:4.0:skill_md:2026-04-11 -->
tomevault-io/skills-registry/tree/main/aj-geddes--useful-ai-prompts--api-rate-limiting commit 7c6966c3da
Frequently asked questions How do I install the Aj Geddes Useful AI Prompts API Rate Limiting skill? Run npx skillmds@latest add tomevault-io/aj-geddes-useful-ai-prompts-api-rate-limiting in your terminal (requires Node.js), paste this page's agent-chat prompt into Claude, Cursor, or any MCP-connected agent, or download the SKILL.md file and copy it into your agent's skills directory.
What does the Aj Geddes Useful AI Prompts API Rate Limiting skill do? API Rate Limiting It is listed under Integrations & APIs on SkillMD.
Is Aj Geddes Useful AI Prompts API Rate Limiting safe to use? This skill has not completed SkillMD's automated safety review yet. Independent scanners report: SkillSpector: PASS, Skill Scanner: PASS. SkillMD never runs a skill's scripts for you; review the SKILL.md before installing.
Which AI agents work with Aj Geddes Useful AI Prompts API Rate Limiting? This skill is tagged as working with Claude Code, Claude.ai, OpenAI Codex. SKILL.md is an open format, so most agents that read a skills directory can load it too.
Is Aj Geddes Useful AI Prompts API Rate Limiting free to use? Yes. Installing skills from SkillMD is free, and the skill stays under its author's original license.
Who published Aj Geddes Useful AI Prompts API Rate Limiting? tomevault-io (@tomevault-io) published this skill. Their other Agent Skills are listed on their SkillMD profile.