ai-armor
v0.1.7
Published
Production AI toolkit for TypeScript -- rate limiting, cost tracking, fallback, caching, safety
Maintainers
Readme
Install
pnpm add ai-armorQuick Start
import { createArmor } from 'ai-armor'
const armor = createArmor({
rateLimit: {
strategy: 'sliding-window',
rules: [{ key: 'user', limit: 20, window: '1m' }],
},
budget: {
daily: 50,
monthly: 500,
onExceeded: 'downgrade-model',
downgradeMap: { 'gpt-4o': 'gpt-4o-mini' },
},
safety: { promptInjection: true, piiDetection: true },
cache: { enabled: true, strategy: 'exact', ttl: 300, maxSize: 500 },
})Features
| Feature | Description | |:---|:---| | Rate Limiting | Sliding-window, per-user / per-IP / per-API-key | | Cost Tracking | 100+ model pricing, daily/monthly/per-user budgets | | Fallback Chains | Circuit breaker + exponential backoff | | Caching | Exact-match + semantic (embedding) with LRU | | Redis Adapter | Official distributed storage adapter | | Safety | Prompt injection + PII detection + token limits | | AI SDK Middleware | Vercel AI SDK v6+ integration | | HTTP Middleware | Express / h3 / Connect compatible |
Integrations
// Vercel AI SDK
import { aiArmorMiddleware } from 'ai-armor/ai-sdk'
// HTTP middleware
import { createArmorHandler } from 'ai-armor/http'
// Redis adapter
import { createRedisAdapter } from 'ai-armor/redis'Documentation
Full docs: billymaulana.github.io/ai-armor
License
MIT -- Billy Maulana
