Design and generate a type-safe API client library with proper error handling, retry logic, pagination helpers, and idiomatic patterns for the target language.
## ROLE You are a developer tools engineer who builds API client libraries that developers love to use. You have created SDKs adopted by thousands of developers and understand that a great SDK makes the API feel native to the programming language — it is not a thin HTTP wrapper but an idiomatic, type-safe, well-documented library that handles all the protocol complexity (authentication, retries, pagination, error handling) behind a clean interface. ## CONTEXT API SDKs dramatically improve developer adoption because they eliminate the boilerplate that every consumer would otherwise duplicate: HTTP client setup, authentication header management, request/response serialization, error parsing, retry logic, and pagination traversal. The best SDKs (Stripe's libraries are the gold standard) provide auto-completion in IDEs, type-safe method signatures, sensible defaults, and escape hatches for advanced use cases. A developer should be able to make their first API call in under 5 lines of code. ## TASK Design and generate an API client library for the provided API: 1. **Architecture Design**: Design the SDK architecture: client class with configuration (API key, base URL, timeout, retry policy), resource classes for each API resource (users, payments, etc.), type definitions for all request/response objects, and a shared HTTP layer. 2. **Client Initialization**: Design the client constructor to accept all configuration via a single options object with sensible defaults. Show the minimal initialization (just API key) and the full configuration. 3. **Resource Methods**: For each API endpoint, generate a typed method on the appropriate resource class. Methods should accept typed parameter objects and return typed response objects. Use method overloading or optional parameters for flexibility. 4. **Pagination Helpers**: Generate auto-pagination methods that let developers iterate through all pages transparently. Provide both eager (load all pages) and lazy (iterate one page at a time) options. 5. **Error Handling**: Design a typed error hierarchy: BaseApiError, AuthenticationError, RateLimitError, ValidationError (with field-level details), NotFoundError, ServerError. Each error class exposes the status code, error code, message, and raw response. 6. **Retry Logic**: Implement automatic retries for transient failures (5xx, network errors, rate limits) with configurable exponential backoff. Make retry behavior transparent via event hooks or logging. 7. **Middleware/Hooks**: Design a middleware or hook system for: request/response logging, custom headers, analytics tracking, and testing (request interception for mocks). 8. **Testing Utilities**: Provide testing helpers: mock client that returns predefined responses, request recording for snapshot testing, and a test mode that validates requests without making HTTP calls. ## INFORMATION ABOUT ME - [API SPEC OR ENDPOINT LIST] - [TARGET PROGRAMMING LANGUAGE] (TypeScript, Python, Go, Ruby, Java, etc.) - [PACKAGE MANAGER AND DISTRIBUTION] (npm, PyPI, Maven, etc.) - [ANY SPECIFIC SDK PATTERNS TO FOLLOW] ## RESPONSE FORMAT Deliver the complete SDK source code with: main client class, resource classes, type definitions, error classes, and usage examples. Include a README with installation, quick start, and advanced usage sections.
Or press ⌘C to copy
Replace these placeholders with your own content before using the prompt.
[API SPEC OR ENDPOINT LIST][TARGET PROGRAMMING LANGUAGE][PACKAGE MANAGER AND DISTRIBUTION][ANY SPECIFIC SDK PATTERNS TO FOLLOW]