$npx -y skills add LambdaTest/agent-skills --skill api-sdk-generatorGenerates client SDK code, API wrapper libraries, request/response models, and language-specific usage patterns for any REST API. Use whenever the user asks to "generate an SDK", "write a client library", "create API wrappers", "generate TypeScript types from my API", "write a Py
| 1 | # API SDK & Codegen Skill |
| 2 | |
| 3 | Generate production-quality client libraries and SDK code for any API in any language. |
| 4 | |
| 5 | --- |
| 6 | |
| 7 | ## SDK Structure (any language) |
| 8 | |
| 9 | ``` |
| 10 | sdk/ |
| 11 | ├── client.{ext} — main client class with base URL, auth, retry |
| 12 | ├── resources/ |
| 13 | │ ├── users.{ext} — one file per API resource |
| 14 | │ ├── orders.{ext} |
| 15 | │ └── ... |
| 16 | ├── models/ |
| 17 | │ ├── user.{ext} — request/response data models |
| 18 | │ └── ... |
| 19 | ├── errors.{ext} — typed error classes |
| 20 | └── utils/ |
| 21 | ├── retry.{ext} |
| 22 | └── pagination.{ext} |
| 23 | ``` |
| 24 | |
| 25 | --- |
| 26 | |
| 27 | ## Base Client Pattern |
| 28 | |
| 29 | ### Python |
| 30 | ```python |
| 31 | import httpx |
| 32 | from typing import Optional |
| 33 | import time |
| 34 | |
| 35 | class APIClient: |
| 36 | def __init__(self, api_key: str, base_url: str = "https://api.example.com/v1"): |
| 37 | self.base_url = base_url |
| 38 | self._headers = { |
| 39 | "Authorization": f"Bearer {api_key}", |
| 40 | "Content-Type": "application/json", |
| 41 | "User-Agent": "example-sdk-python/1.0.0" |
| 42 | } |
| 43 | self._client = httpx.Client(timeout=30.0) |
| 44 | |
| 45 | def _request(self, method: str, path: str, **kwargs) -> dict: |
| 46 | url = f"{self.base_url}{path}" |
| 47 | for attempt in range(3): |
| 48 | try: |
| 49 | resp = self._client.request(method, url, headers=self._headers, **kwargs) |
| 50 | if resp.status_code == 429: |
| 51 | retry_after = int(resp.headers.get("Retry-After", 2 ** attempt)) |
| 52 | time.sleep(retry_after) |
| 53 | continue |
| 54 | resp.raise_for_status() |
| 55 | return resp.json() |
| 56 | except httpx.HTTPStatusError as e: |
| 57 | raise APIError(e.response.status_code, e.response.json()) from e |
| 58 | raise RateLimitError("Max retries exceeded") |
| 59 | ``` |
| 60 | |
| 61 | ### TypeScript |
| 62 | ```typescript |
| 63 | class APIClient { |
| 64 | private readonly baseUrl: string; |
| 65 | private readonly headers: Record<string, string>; |
| 66 | |
| 67 | constructor(apiKey: string, baseUrl = 'https://api.example.com/v1') { |
| 68 | this.baseUrl = baseUrl; |
| 69 | this.headers = { |
| 70 | 'Authorization': `Bearer ${apiKey}`, |
| 71 | 'Content-Type': 'application/json', |
| 72 | }; |
| 73 | } |
| 74 | |
| 75 | async request<T>(method: string, path: string, body?: unknown): Promise<T> { |
| 76 | const res = await fetch(`${this.baseUrl}${path}`, { |
| 77 | method, |
| 78 | headers: this.headers, |
| 79 | body: body ? JSON.stringify(body) : undefined, |
| 80 | }); |
| 81 | if (!res.ok) { |
| 82 | const err = await res.json(); |
| 83 | throw new APIError(res.status, err.message); |
| 84 | } |
| 85 | return res.json() as T; |
| 86 | } |
| 87 | } |
| 88 | ``` |
| 89 | |
| 90 | --- |
| 91 | |
| 92 | ## Resource Class Pattern |
| 93 | |
| 94 | ### Python |
| 95 | ```python |
| 96 | from dataclasses import dataclass |
| 97 | from typing import Optional, List |
| 98 | |
| 99 | @dataclass |
| 100 | class User: |
| 101 | id: str |
| 102 | name: str |
| 103 | email: str |
| 104 | created_at: str |
| 105 | role: Optional[str] = None |
| 106 | |
| 107 | class UsersResource: |
| 108 | def __init__(self, client: APIClient): |
| 109 | self._client = client |
| 110 | |
| 111 | def list(self, page: int = 1, limit: int = 20) -> List[User]: |
| 112 | data = self._client._request("GET", f"/users?page={page}&limit={limit}") |
| 113 | return [User(**u) for u in data["data"]] |
| 114 | |
| 115 | def get(self, user_id: str) -> User: |
| 116 | data = self._client._request("GET", f"/users/{user_id}") |
| 117 | return User(**data) |
| 118 | |
| 119 | def create(self, name: str, email: str, role: Optional[str] = None) -> User: |
| 120 | payload = {"name": name, "email": email} |
| 121 | if role: |
| 122 | payload["role"] = role |
| 123 | data = self._client._request("POST", "/users", json=payload) |
| 124 | return User(**data) |
| 125 | |
| 126 | def delete(self, user_id: str) -> None: |
| 127 | self._client._request("DELETE", f"/users/{user_id}") |
| 128 | ``` |
| 129 | |
| 130 | --- |
| 131 | |
| 132 | ## Typed Error Classes |
| 133 | |
| 134 | ```python |
| 135 | class APIError(Exception): |
| 136 | def __init__(self, status_code: int, message: str): |
| 137 | self.status_code = status_code |
| 138 | self.message = message |
| 139 | super().__init__(f"HTTP {status_code}: {message}") |
| 140 | |
| 141 | class AuthenticationError(APIError): pass # 401 |
| 142 | class AuthorizationError(APIError): pass # 403 |
| 143 | class NotFoundError(APIError): pass # 404 |
| 144 | class ValidationError(APIError): pass # 422 |
| 145 | class RateLimitError(APIError): pass # 429 |
| 146 | class ServerError(APIError): pass # 5xx |
| 147 | ``` |
| 148 | |
| 149 | --- |
| 150 | |
| 151 | ## Pagination Helper |
| 152 | |
| 153 | ```python |
| 154 | def paginat |