designing-sdks
This skill provides architectural patterns and best practices for designing production-ready SDKs across multiple programming languages. Use it when building client libraries for APIs, implementing authentication strategies, designing retry logic with exponential backoff, organizing resource-based or command-based API structures, and ensuring consistent developer experience through intuitive interfaces and error handling patterns.
git clone --depth 1 https://github.com/ancoleman/ai-design-components /tmp/designing-sdks && cp -r /tmp/designing-sdks/skills/designing-sdks ~/.claude/skills/designing-sdksSKILL.md
# SDK Design
Design client libraries (SDKs) with excellent developer experience through intuitive APIs, robust error handling, automatic retries, and consistent patterns across programming languages.
## When to Use This Skill
Use when building a client library for a REST API, creating internal service SDKs, implementing retry logic with exponential backoff, handling authentication patterns, creating typed error hierarchies, implementing pagination with async iterators, or designing streaming APIs for real-time data.
## Core Architecture Patterns
### Client → Resources → Methods
Organize SDK code hierarchically:
```
Client (config: API key, base URL, retries, timeout)
├─ Resources (users, payments, posts)
│ ├─ create(), retrieve(), update(), delete()
│ └─ list() (with pagination)
└─ Top-Level Methods (convenience)
```
**Resource-Based (Stripe style):**
```typescript
const client = new APIClient({ apiKey: 'sk_test_...' })
const user = await client.users.create({ email: 'user@example.com' })
```
Use for APIs <100 methods. Prioritizes developer experience.
**Command-Based (AWS SDK v3):**
```typescript
import { S3Client, PutObjectCommand } from '@aws-sdk/client-s3'
await client.send(new PutObjectCommand({ Bucket: '...' }))
```
Use for APIs >100 methods. Prioritizes bundle size and tree-shaking.
For detailed architectural guidance, see `references/architecture-patterns.md`.
## Language-Specific Patterns
### TypeScript: Async-Only
```typescript
const user = await client.users.create({ email: 'user@example.com' })
```
All methods return Promises. Avoid callbacks.
### Python: Dual Sync/Async
```python
# Sync
client = APIClient(api_key='sk_test_...')
user = client.users.create(email='user@example.com')
# Async
async_client = AsyncAPIClient(api_key='sk_test_...')
user = await async_client.users.create(email='user@example.com')
```
Provide both clients. Users choose based on architecture.
### Go: Sync with Context
```go
client := apiclient.New("api_key")
user, err := client.Users().Create(ctx, req)
```
Use context.Context for timeout and cancellation.
## Authentication
### API Key (Most Common)
```typescript
const client = new APIClient({ apiKey: process.env.API_KEY })
```
Store keys in environment variables, never hardcode.
### OAuth Token Refresh
```typescript
const client = new APIClient({
clientId: 'id',
clientSecret: 'secret',
refreshToken: 'token',
onTokenRefresh: (newToken) => saveToken(newToken)
})
```
SDK automatically refreshes tokens before expiry.
### Bearer Token Per-Request
```typescript
await client.users.list({
headers: { Authorization: `Bearer ${userToken}` }
})
```
Use for multi-tenant applications.
See `references/authentication.md` for OAuth flows, JWT handling, and credential providers.
## Retry and Backoff
### Exponential Backoff with Jitter
```typescript
async function retryWithBackoff<T>(fn: () => Promise<T>, maxRetries: number): Promise<T> {
let attempt = 0
while (attempt <= maxRetries) {
try {
return await fn()
} catch (error) {
attempt++
if (attempt > maxRetries || !isRetryable(error)) throw error
const exponential = Math.min(1000 * Math.pow(2, attempt - 1), 10000)
const jitter = Math.random() * 500
await sleep(exponential + jitter)
}
}
}
function isRetryable(error: any): boolean {
return (
error.code === 'ECONNRESET' ||
error.code === 'ETIMEDOUT' ||
(error.status >= 500 && error.status < 600) ||
error.status === 429
)
}
```
**Retry Decision Matrix:**
| Error Type | Retry? | Rationale |
|------------|--------|-----------|
| 5xx, 429, Network Timeout | ✅ Yes | Transient errors |
| 4xx, 401, 403, 404 | ❌ No | Client errors won't fix themselves |
### Rate Limit Handling
```typescript
if (error.status === 429) {
const retryAfter = parseInt(error.headers['retry-after'] || '60')
await sleep(retryAfter * 1000)
}
```
Respect `Retry-After` header on 429 responses.
See `references/retry-backoff.md` for jitter strategies, circuit breakers, and idempotency keys.
## Error Handling
### Typed Error Hierarchy
```typescript
class APIError extends Error {
constructor(
message: string,
public status: number,
public code: string,
public requestId: string
) {
super(message)
this.name = 'APIError'
}
}
class RateLimitError extends APIError {
constructor(message: string, requestId: string, public retryAfter: number) {
super(message, 429, 'rate_limit_error', requestId)
}
}
class AuthenticationError extends APIError {
constructor(message: string, requestId: string) {
super(message, 401, 'authentication_error', requestId)
}
}
```
### Error Handling in Practice
```typescript
try {
const user = await client.users.create({ email: 'invalid' })
} catch (error) {
if (error instanceof RateLimitError) {
await sleep(error.retryAfter * 1000)
} else if (error instanceof AuthenticationError) {
console.error('Invalid API key')
} else if (error instanceof APIError) {
console.error(`${error.message} (Request ID: ${error.requestId})`)
}
}
```
Include request ID in all errors for debugging.
See `references/error-handling.md` for user-friendly messages, validation errors, and debugging support.
## Pagination
### Async Iterators (Recommended)
**TypeScript:**
```typescript
for await (const user of client.users.list({ limit: 100 })) {
console.log(user.id, user.email)
}
```
**Python:**
```python
async for user in client.users.list(limit=100):
print(user.id, user.email)
```
SDK automatically fetches next page.
### Implementation
```typescript
class UsersResource {
async *list(options?: { limit?: number }): AsyncGenerator<User> {
let cursor: string | undefined = undefined
while (true) {
const response = await this.client.request('GET', '/users', {
query: { limit: String(options?.limit || 100), ...(cursor ? { cursor } : {}) }
})
for (const user of response.dManage Linux systems covering systemd services, process management, filesystems, networking, performance tuning, and troubleshooting. Use when deploying applications, optimizing server performance, diagnosing production issues, or managing users and security on Linux servers.
Data pipelines, feature stores, and embedding generation for AI/ML systems. Use when building RAG pipelines, ML feature serving, or data transformations. Covers feature stores (Feast, Tecton), embedding pipelines, chunking strategies, orchestration (Dagster, Prefect, Airflow), dbt transformations, data versioning (LakeFS), and experiment tracking (MLflow, W&B).
Strategic guidance for designing modern data platforms, covering storage paradigms (data lake, warehouse, lakehouse), modeling approaches (dimensional, normalized, data vault, wide tables), data mesh principles, and medallion architecture patterns. Use when architecting data platforms, choosing between centralized vs decentralized patterns, selecting table formats (Iceberg, Delta Lake), or designing data governance frameworks.
Design cloud network architectures with VPC patterns, subnet strategies, zero trust principles, and hybrid connectivity. Use when planning VPC topology, implementing multi-cloud networking, or establishing secure network segmentation for cloud workloads.
Design comprehensive security architectures using defense-in-depth, zero trust principles, threat modeling (STRIDE, PASTA), and control frameworks (NIST CSF, CIS Controls, ISO 27001). Use when designing security for new systems, auditing existing architectures, or establishing security governance programs.
Assembles component outputs from AI Design Components skills into unified, production-ready component systems with validated token integration, proper import chains, and framework-specific scaffolding. Use as the capstone skill after running theming, layout, dashboard, data-viz, or feedback skills to wire components into working React/Next.js, Python, or Rust projects.
Builds AI chat interfaces and conversational UI with streaming responses, context management, and multi-modal support. Use when creating ChatGPT-style interfaces, AI assistants, code copilots, or conversational agents. Handles streaming text, token limits, regeneration, feedback loops, tool usage visualization, and AI-specific error patterns. Provides battle-tested components from leading AI products with accessibility and performance built in.
Constructs secure, efficient CI/CD pipelines with supply chain security (SLSA), monorepo optimization, caching strategies, and parallelization patterns for GitHub Actions, GitLab CI, and Argo Workflows. Use when setting up automated testing, building, or deployment workflows.