api-rate-limit-handler
하는 일
외부 API의 속도 제한을 프로그램이 처리하도록 돕는 도구입니다. API가 과부하나 기타 이유로 요청을 거부하면, 지능적으로 잠시 기다린 후 다시 시도합니다.
사용하는 경우
- ✓요청 빈도에 제한이 있는 API를 호출할 때.
- ✓‘429 Too Many Requests’ 같은 오류나 일시적인 서버 오류를 받을 때.
- ✓타사 서비스를 사용할 때도 안정적이어야 하는 프로그램을 만들 때.
스킬 링크
https://github.com/sickn33/agentic-awesome-skills/blob/main/plugins/agentic-awesome-skills-claude/skills/api-rate-limit-handler/SKILL.md복사해서 AI(Claude, ChatGPT, Cursor)에 붙여넣고 지침을 따르도록 요청하세요.
사용 방법
가장 쉬운 방법입니다. 메시지를 복사해 AI에 붙여넣으세요. AI가 스킬을 읽고 지침을 따릅니다.
바로 붙여넣을 수 있는 메시지
Claude Code, Codex, Cursor용입니다. 프로젝트 폴더에서 실행하면 스킬이 설치됩니다.
SKILL.md를 다운로드해 에이전트의 스킬 폴더에 넣으세요.
AI에게 요청하는 예시
“API가 느릴 때 제 프로그램이 다시 시도하도록 어떻게 만들 수 있나요?”
매주 새 스킬 5개. 읽는 데 1분.
작동 방식
먼저 오류 유형을 확인해 다시 시도해야 하는지 판단합니다. 그렇다면 API가 설정한 시간이나 자동으로 계산된 시간만큼 기다린 후 다시 시도해 과부하를 막습니다.
기술 내용 (원본 SKILL.md)
작성자의 영어 원문을 GitHub에서 그대로 가져왔습니다.
API Rate Limit Handler
Overview
A skill for implementing production-grade rate limiting, exponential backoff, and retry strategies when integrating with external APIs. Prevents cascading failures, respects upstream quotas, and keeps your application resilient under load.
When to Use This Skill
- Use when calling external APIs that enforce rate limits (OpenAI, Stripe, GitHub, etc.)
- Use when you receive 429 Too Many Requests or 5xx errors and need graceful recovery
- Use when building a client that must respect
Retry-Afterheaders - Use when designing a system that fans out to multiple API providers
- Use when the user says "handle rate limits", "add retry logic", "backoff strategy", or "don't get throttled"
How It Works
Step 1: Classify the response
Determine whether a failed request is retryable or terminal.
| Status | Classification | Action |
|---|---|---|
| 200-299 | Success | Return response |
| 400, 401, 403, 404 | Terminal client error | Do not retry — fix the request |
| 408, 429 | Retryable (rate limit / timeout) | Retry with backoff |
| 500, 502, 503, 504 | Retryable (server error) | Retry with backoff |
Step 2: Parse rate limit headers
Always check upstream hints before computing your own delay.
function getRetryDelay(
response: Response,
attempt: number,
maxDelayMs = 60_000
): number {
// Prefer upstream hints
const retryAfter = response.headers.get("Retry-After");
if (retryAfter) {
const seconds = Number(retryAfter);
if (Number.isFinite(seconds) && seconds >= 0) {
return seconds * 1000;
}
// HTTP-date format
const date = new Date(retryAfter).getTime();
if (Number.isFinite(date)) {
return Math.max(0, date - Date.now());
}
}
// GitHub documents x-ratelimit-reset as Unix epoch seconds.
const resetHeader = response.headers.get("x-ratelimit-reset");
const githubReset = resetHeader === null || resetHeader.trim() === "" ? NaN : Number(resetHeader);
if (Number.isFinite(githubReset)) {
return Math.max(0, githubReset * 1000 - Date.now());
}
// Fallback: capped exponential backoff with full jitter.
const cap = Math.min(1000 * 2 ** attempt, maxDelayMs);
return Math.floor(Math.random() * cap);
}
Upstream hints are minimum waits; never truncate them to retry early. If a hint exceeds the remaining operation budget, stop without scheduling another request. The cap applies only to fallback backoff.
Provider-specific reset headers do not share one unit or format. For example, some APIs return durations while GitHub returns epoch seconds. Parse an additional header only after checking that provider's current documentation.
Step 3: Implement the retry loop
async function fetchWithRetry(
url: string,
options: RequestInit,
maxRetries = 3,
maxElapsedMs = 120_000,
retryNonIdempotent = false
): Promise<Response> {
const startedAt = Date.now();
const method = (options.method ?? "GET").toUpperCase();
const replaySafe = ["GET", "HEAD", "OPTIONS", "PUT", "DELETE"].includes(method)
|| retryNonIdempotent;
for (let attempt = 0; attempt <= maxRetries; attempt++) {
const response = await fetch(url, options);
if (response.ok) return response;
// Terminal errors — do not retry
if (![408, 429, 500, 502, 503, 504].includes(response.status)) {
throw new Error(`Terminal error ${response.status}: ${response.statusText}`);
}
if (!replaySafe) {
throw new Error(
`${method} was not retried because replay safety was not explicitly established`
);
}
// Retryable — but exhausted attempts
if (attempt === maxRetries) {
throw new Error(`Failed after ${maxRetries} retries: ${response.status}`);
}
const remaining = maxElapsedMs - (Date.now() - startedAt);
const delay = getRetryDelay(response, attempt);
if (remaining <= 0 || delay > remaining) {
throw new Error(`Retry cannot be scheduled within ${maxElapsedMs}ms`);
}
// Release the connection before waiting when the body is not needed.
await response.body?.cancel();
console.warn(
`Request failed (${response.status}), retrying in ${Math.round(delay)}ms (attempt ${attempt + 1}/${maxRetries})`
);
await new Promise(resolve => setTimeout(resolve, delay));
}
throw new Error("Unreachable");
}
Step 4: Add a client-side rate limiter (proactive)
…
자주 묻는 질문
‘요청 제한(rate limits)’이란 무엇인가요?
온라인 서비스가 사용자나 프로그램이 일정 시간 안에 할 수 있는 요청 수를 제한하는 규칙입니다. 한 사용자가 서비스를 압도하지 못하게 합니다.
‘백오프를 사용한 재시도(retry with backoff)’는 무엇을 뜻하나요?
요청이 실패하면 프로그램이 잠시 기다렸다가 다시 시도한다는 뜻입니다. 실패할 때마다 기다리는 시간이 늘어나, 서비스가 회복할 시간을 줍니다.
‘429’와 ‘5xx’ 오류는 무엇인가요?
‘429’ 오류는 요청 한도를 초과했다는 뜻입니다. ‘5xx’ 오류(500, 503 등)는 API 서버의 문제를 나타내며, 여러분의 요청이 아니라 보통 일시적입니다.
상세 정보
작성자의 원본 설명
Implement bounded, idempotency-aware API throttling, backoff, and retry handling for 429 and transient 5xx responses.
인기도
- GitHub 스타
- 48k
- 순위
- #3777
- 라이선스
- MIT
- 업데이트
- 2026. 10. 15.
댓글
- …
이 저장소의 다른 스킬
00-andruia-consultant
48k에이전트가 AI 프로젝트를 시작하거나 개선할 수 있도록 코드를 분석하고 스페인어로 실행 계획을 세워 줍니다.
007
48k에이전트가 보안 감사와 위협 모델링을 수행해 공격과 취약점으로부터 프로젝트를 보호하도록 돕습니다.
10-andruia-skill-smith
48k에이전트가 AI 도구의 작동 방식을 정의하고 문서를 쓰며 구조를 검증하도록 돕습니다.
20-andruia-niche-intelligence
48k에이전트가 신뢰할 수 있는 자료를 바탕으로 특정 산업의 맥락, 규칙, 사용 패턴, 위험을 정리한 요약을 만들도록 돕습니다.
비슷한 스킬
api-connector-builder
280k에이전트가 기존 패턴을 따라 새로운 API 연결을 만들도록 합니다. 새로운 방식을 도입하지 않고 연동을 하나 더 추가할 때 씁니다.
api-design
280k에이전트가 모범 사례에 따라 REST API를 설계하도록 돕습니다. API가 통신하는 방식, 오류를 보여 주는 방식, 데이터를 정리하는 방식을 정하는 데 유용합니다.
backend-patterns
280k에이전트가 서버 쪽 아키텍처 패턴과 데이터베이스 최적화를 다루도록 돕습니다. 서버에서 실행되는 코드를 만들거나 검토할 때 유용합니다.