api-rate-limiting
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.
下記のコマンドをコピーしてターミナル(Mac/Linux)または PowerShell(Windows)に貼り付けてください。 ダウンロード → 解凍 → 配置まで全自動。
mkdir -p ~/.claude/skills && cd ~/.claude/skills && curl -L -o api-rate-limiting.zip https://jpskill.com/download/21330.zip && unzip -o api-rate-limiting.zip && rm api-rate-limiting.zip
$d = "$env:USERPROFILE\.claude\skills"; ni -Force -ItemType Directory $d | Out-Null; iwr https://jpskill.com/download/21330.zip -OutFile "$d\api-rate-limiting.zip"; Expand-Archive "$d\api-rate-limiting.zip" -DestinationPath $d -Force; ri "$d\api-rate-limiting.zip"
完了後、Claude Code を再起動 → 普通に「動画プロンプト作って」のように話しかけるだけで自動発動します。
💾 手動でダウンロードしたい(コマンドが難しい人向け)
- 1. 下の青いボタンを押して
api-rate-limiting.zipをダウンロード - 2. ZIPファイルをダブルクリックで解凍 →
api-rate-limitingフォルダができる - 3. そのフォルダを
C:\Users\あなたの名前\.claude\skills\(Win)または~/.claude/skills/(Mac)へ移動 - 4. Claude Code を再起動
⚠️ ダウンロード・利用は自己責任でお願いします。当サイトは内容・動作・安全性について責任を負いません。
🎯 このSkillでできること
下記の説明文を読むと、このSkillがあなたに何をしてくれるかが分かります。Claudeにこの分野の依頼をすると、自動で発動します。
📦 インストール方法 (3ステップ)
- 1. 上の「ダウンロード」ボタンを押して .skill ファイルを取得
- 2. ファイル名の拡張子を .skill から .zip に変えて展開(macは自動展開可)
- 3. 展開してできたフォルダを、ホームフォルダの
.claude/skills/に置く- · macOS / Linux:
~/.claude/skills/ - · Windows:
%USERPROFILE%\.claude\skills\
- · macOS / Linux:
Claude Code を再起動すれば完了。「このSkillを使って…」と話しかけなくても、関連する依頼で自動的に呼び出されます。
詳しい使い方ガイドを見る →- 最終更新
- 2026-05-18
- 取得日時
- 2026-05-18
- 同梱ファイル
- 8
📖 Skill本文(日本語訳)
※ 原文(英語/中国語)を Gemini で日本語化したものです。Claude 自身は原文を読みます。誤訳がある場合は原文をご確認ください。
APIレート制限
目次
概要
APIを不正利用から保護し、トラフィックを管理するために、ユーザーごと、IPごと、エンドポイントごとの戦略で、さまざまなレート制限アルゴリズムを使用します。
使用場面
- ブルートフォース攻撃からAPIを保護する場合
- トラフィックスパイクを管理する場合
- 段階的なサービスプランを実装する場合
- DoS攻撃を防止する場合
- リソース割り当ての公平性を確保する場合
- クォータと使用制限を強制する場合
クイックスタート
最小限の動作例:
// 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;
}
// ... (完全な実装についてはリファレンスガイドを参照してください)
リファレンスガイド
references/ディレクトリにある詳細な実装:
| ガイド | 内容 |
|---|---|
| Token Bucket Algorithm | トークンバケットアルゴリズム |
| Sliding Window Algorithm | スライディングウィンドウアルゴリズム |
| Redis-Based Rate Limiting | Redisベースのレート制限 |
| Tiered Rate Limiting | 段階的なレート制限 |
| Python Rate Limiting (Flask) | Pythonレート制限 (Flask) |
| Response Headers | レスポンスヘッダー |
ベストプラクティス
✅ 実施すべきこと
- レスポンスにレート制限ヘッダーを含める
- 分散レート制限にはRedisを使用する
- 異なるユーザープランに対して段階的な制限を実装する
- 適切なウィンドウサイズと制限を設定する
- レート制限のメトリクスを監視する
- 明確なリトライガイダンスを提供する
- APIドキュメントにレート制限を記載する
- 高負荷下でテストする
❌ 実施すべきでないこと
- 本番環境でインメモリストレージを使用する
- 制限を厳しすぎに設定する
- Retry-Afterヘッダーを含めるのを忘れる
- 分散シナリオを無視する
- レート制限を公開する (セキュリティ上の理由)
- 分散システムに単純なカウンターを使用する
- 古いデータのクリーンアップを忘れる
📜 原文 SKILL.md(Claudeが読む英語/中国語)を展開
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
同梱ファイル
※ ZIPに含まれるファイル一覧。`SKILL.md` 本体に加え、参考資料・サンプル・スクリプトが入っている場合があります。
- 📄 SKILL.md (2,831 bytes)
- 📎 references/python-rate-limiting-flask.md (1,385 bytes)
- 📎 references/redis-based-rate-limiting.md (1,559 bytes)
- 📎 references/response-headers.md (579 bytes)
- 📎 references/sliding-window-algorithm.md (1,539 bytes)
- 📎 references/tiered-rate-limiting.md (1,250 bytes)
- 📎 references/token-bucket-algorithm.md (1,637 bytes)
- 📎 scripts/validate-api.sh (440 bytes)