Use when writing scripts or services that call external APIs, webhooks, or batch endpoints. Enforces timeouts, rate limiting, bounded parallelism, safe retries, and session reuse.
Installs into .claude/skills of the current project.
Sponsors
SSkills DirectorySkills Directory
Is that skill safe to install?
SSkills DirectorySkills Directory
Know which skills are safe — weekly.
Are you the author of External Api Calls And Rate Limits?
Add the live security badge to your README. It updates with every re-scan.
[](https://www.skillsdirectory.com/skills/ganesh-dark-external-api-calls-and-rate-limits)
---
name: external-api-calls-and-rate-limits
description: Use when writing scripts or services that call external APIs, webhooks, or batch endpoints. Enforces timeouts, rate limiting, bounded parallelism, safe retries, and session reuse.
---
# External API Calls and Rate Limits
Scripts that call external APIs often hang without timeouts, fire unbounded parallel requests that trigger `429` bans, retry permanent errors forever, or lose progress halfway through a large batch.
## Rules
- Always set explicit timeouts on every HTTP request (`requests`, `httpx`, `urllib`, or `aiohttp`). Never let a hung socket freeze a script forever.
- Bound parallelism strictly. Use `ThreadPoolExecutor(max_workers=5)` or `asyncio.Semaphore(5)` instead of firing unbounded `asyncio.gather(*...)` or hundreds of threads at once.
- Coordinate rate limits across parallel workers. Respect `429` and `Retry-After` headers, and share a rate limiter or token bucket so workers back off together instead of hammering the API.
- Retry only transient failures (`429`, `502`, `503`, `504`, and network timeouts) using exponential backoff with jitter and a strict max retry cap. Never retry `400`, `401`, `403`, or `404`.
- Reuse HTTP connections with a shared `requests.Session()` or `httpx.Client()`, checkpoint large batch runs so they can resume, and never log API keys or auth headers.
## Example
Bad:
Running `asyncio.gather(*[fetch(u) for u in urls])` or `ThreadPoolExecutor(max_workers=200)` over 2,000 URLs with no `timeout`, no concurrency limit, and a retry loop that retries `401 Unauthorized` forever.
Good:
Running `ThreadPoolExecutor(max_workers=5)` (or `asyncio.Semaphore(5)`) with a shared `requests.Session()`, a 10-second `timeout`, a shared rate limiter honoring `Retry-After` on `429`/`5xx`, and saving completed IDs to resume on failure.