Rate Limiter
Design rate limit detection, throttling, and backoff strategy specifications to prevent API lockouts in insurance and financial services system integrations.
от TheLobbi★ 22 звезды на GitHub
Установить Rate Limiter в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Об этом скилле
Rate Limiter
Produce a complete rate limit handling design for an API integration. This covers detection, pre-emptive throttling, backoff strategy, request queuing, and multi-tenant isolation. The output is the technical specification a developer implements in the integration HTTP client layer.
Rate Limit Detection
HTTP 429 Response Handling
When the API returns HTTP 429 (Too Many Requests):
interface RateLimitResponse {
status: 429;
headers: {
'Retry-After'?: string; // Seconds to wait (preferred) or HTTP-date
'X-RateLimit-Limit'?: string; // Total limit per window
'X-RateLimit-Remaining'?: string; // Remaining requests in current window
'X-RateLimit-Reset'?: string; // Unix timestamp when limit resets
'X-RateLimit-RetryAfter'?: string; // Some APIs use this variant
};
}
function extractRetryAfter(response: Response): number {
const retryAfter = response.headers.get('Retry-After');
if (!retryAfter) {
// No header — use conservative default: 60 seconds
return 60;
}
// Check if it's a number (seconds) or an HTTP-date
const asNumber = parseInt(retryAfter, 10);
if (!isNaN(asNumber)) {
return Math.max(asNumber, 1); // At least 1 second
}
// It's an HTTP-date: parse and calculate seconds until that time
const resetDate = new Date(retryAfter);
const secondsUntilReset = Math.ceil((resetDate.getTime() - Date.now()) / 1000);
return Math.max(secondsUntilReset, 1);
}
Rate Limit Header Tracking
Parse rate limit headers on every response (not just 429), to detect when limits are approaching:
interface RateLimitState {
limit: number; // Total requests allowed per window
remaining: number; // Requests remaining in current window
resetAt: number; // Unix timestamp when window resets
}
function parseRateLimitHeaders(response: Response): RateLimitState | null {
const limit = response.headers.get('X-RateLimit-Limit');
const remaining = response.headers.get('X-RateLimit-Remaining');
const reset = response.headers.get('X-RateLimit-Reset');
if (!limit || !remaining || !reset) return null;
return {
limit: parseInt(limit, 10),
remaining: parseInt(remaining, 10),
resetAt: parseInt(reset, 10) // Unix timestamp
};
}
Known rate limit configurations by API type (document the specific vendor's limits):
| API | Limit | Window | Key | Notes |
|---|---|---|---|---|
| [Vendor AMS] | 100 req | 1 minute | Per API key | Sandbox: 10 req/min |
| [Carrier API] | 1000 req | 1 hour | Per account | Shared across all users |
| [Custom API] | 50 req | 1 minute | Per endpoint | Different limits per endpoint |
Pre-Emptive Throttling
Do not wait for a 429 to start throttling. Slow down before hitting the limit.
Throttle activation thresholds:
| Remaining % | Action |
|---|---|
| > 30% | Full speed — no throttling |
| 20-30% | Reduce rate by 25% |
| 10-20% | Reduce rate by 50% |
| < 10% | Reduce rate by 75%, log warning |
| 0% (exhausted) | Pause all requests until reset window; log alert |
Implementation:
class PreEmptiveThrottler {
private rateLimitState: RateLimitState | null = null;
updateState(state: RateLimitState): void {
this.rateLimitState = state;
}
async waitIfNeeded(): Promise<void> {
if (!this.rateLimitState) return; // No state yet — proceed
const remainingPct = this.rateLimitState.remaining / this.rateLimitState.limit;
if (remainingPct <= 0) {
// Exhausted — wait until reset
const msUntilReset = (this.rateLimitState.resetAt * 1000) - Date.now();
const waitMs = Math.max(msUntilReset + 500, 1000); // Add 500ms buffer after reset
logger.warn('Rate limit exhausted, pausing', { waitMs, resetAt: new Date(this.rateLimitState.resetAt * 1000) });
await sleep(waitMs);
} else if (remainingPct < 0.10) {
await sleep(750); // 750ms between requests
} else if (remainingPct < 0.20) {
await sleep(500); // 500ms between requests
} else if (remainingPct < 0.30) {
await sleep(250); // 250ms between requests
}
// > 30%: no delay
}
}
Backoff Strategy
Applied after a 429 response is received (reactive, not pre-emptive):
Primary strategy: Use Retry-After header value. This is always more accurate than any calculated backoff.
Fallback strategy (when no Retry-After header):
Exponential backoff with full jitter:
attempt_1: wait = random(5, 10) seconds
attempt_2: wait = random(10, 20) seconds
attempt_3: wait = random(20, 40) seconds
attempt_4: wait = random(40, 80) seconds [capped at max]
attempt_5: wait = random(80, 120) seconds [max — if still failing, dead-letter]
After attempt 5 with 429: Do not continue. Rate limiting this severe indicates
a systemic misconfiguration. Dead-letter the request and alert operations.
Do not retry immediately: Some integrations retry on
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
- 01
Read - 02
Grep - 03
Bash - 04
Write
FAQ
Что делает скилл Rate Limiter?
Design rate limit detection, throttling, and backoff strategy specifications to prevent API lockouts in insurance and financial services system integrations.
Как установить скилл Rate Limiter?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл Rate Limiter запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
mcp-builder
AnthropicGuide for creating high-quality MCP (Model Context Protocol) servers that enable LLMs to interact with external services through well-designed tools. Use when…
claude-api
AnthropicReference for the Claude API / Anthropic SDK — model ids, pricing, params, streaming, tool use, MCP, agents, caching, token counting, model migration. TRIGGER…
algorithmic-art
AnthropicCreating algorithmic art using p5.js with seeded randomness and interactive parameter exploration. Use this when users request creating art using code…
mcp-integration
AnthropicThis skill should be used when the user asks to "add MCP server", "integrate MCP", "configure MCP in plugin", "use .mcp.json", "set up Model Context…