csp-api-governancelisted
Install: claude install-skill maythyai/code-skills-package
# API Governance
Patterns for managing API operations at scale, including rate limiting, API key lifecycle management, usage metering, versioning, error standardization, and health monitoring.
## When to Activate
- Implementing rate limiting on public or internal APIs
- Building an API key management system with generation, rotation, and revocation
- Adding usage metering and quota enforcement to API endpoints
- Choosing an API versioning strategy
- Standardizing error responses with RFC 7807 Problem Details
- Setting up API health monitoring and SLA tracking
## Rate Limiting Algorithms
### Algorithm Comparison
| Algorithm | Burst Handling | Memory | Accuracy | Complexity | Best For |
|-----------|---------------|--------|----------|------------|----------|
| Token Bucket | Allows bursts | Low | Good | Medium | General API rate limiting |
| Sliding Window Log | No bursts | High | Exact | Simple | Low-traffic, strict limits |
| Sliding Window Counter | Smoothed bursts | Low | Good | Medium | High-traffic APIs |
| Leaky Bucket | Constant rate | Low | Strict | Medium | Queue-based processing |
| Fixed Window | End-of-window bursts | Very Low | Approximate | Simple | Simple implementations |
### Token Bucket Implementation (TypeScript)
```typescript
interface TokenBucket {
tokens: number;
maxTokens: number;
refillRate: number; // tokens per second
lastRefill: number; // timestamp in ms
}
class RateLimiter {
private buckets = new Map<string, TokenBucket>();
c