Fill in these first
- Language and HTTP library: [e.g. TypeScript with fetch, Python with httpx, PHP with Guzzle]
- API base URL and authentication method: [e.g. bearer token in a header, API key in a header]
- Endpoints needed: [method, path, request fields and response fields for each]
- Rate limit documented by the provider: [e.g. 10 requests per second, with a Retry-After header on 429]
- Which calls are safe to retry: [e.g. GET requests, and POST requests that accept an idempotency key]
Task
Write a client module for this API that a team can reuse across the codebase.
Output format
- The client module in one code block, with:
- configuration read from environment variables, never hard-coded
- a timeout on every request
- retries with exponential backoff and jitter, for network errors, 429 and 5xx only
- respect for the Retry-After header
- typed request and response objects
- clear error types for authentication, validation, rate limit and server errors
- A usage example.
- A list of tests to write, including timeout, 429 with Retry-After, and a non-retryable 400.
Rules
- Never retry a request that is not safe to repeat unless it carries an idempotency key.
- Cap retries, for example at three attempts, and cap the total wait time.
- Never log the API key or the full authorisation header.
- Use only endpoints and fields from the inputs; do not guess undocumented fields.
Example
Retry delays with jitter: about 0.5 s, 1 s, 2 s, each plus a random 0 to 250 ms.






