@ai-armor/nuxt
v0.1.7
Published
Nuxt module for ai-armor -- production AI toolkit with rate limiting, cost tracking, fallback, caching, and safety guardrails for Nuxt 3/4
Downloads
644
Maintainers
Readme
Features
- Rate Limiting -- Sliding window, fixed window, or token bucket per IP/user/key
- Cost Tracking -- Real-time daily/monthly spend with budget alerts
- Safety Guardrails -- Prompt injection detection, PII filtering, content moderation
- Auto-Imported Composables --
useArmorCost(),useArmorStatus(),useArmorSafety() - Server API Routes -- Admin endpoints for monitoring and safety checks
- Zero Config -- Works out of the box with sensible defaults
- TypeScript First -- Full type safety with auto-generated types
Quick Setup
Install the module:
npx nuxi module add @ai-armor/nuxtOr manually:
pnpm add @ai-armor/nuxt ai-armorAdd to nuxt.config.ts:
export default defineNuxtConfig({
modules: ['@ai-armor/nuxt'],
aiArmor: {
rateLimit: {
strategy: 'sliding-window',
rules: [{ key: 'ip', limit: 30, window: '1m' }],
},
budget: { daily: 50, monthly: 500, onExceeded: 'warn' },
safety: { promptInjection: true, piiDetection: true },
adminSecret: process.env.ARMOR_ADMIN_SECRET,
},
})Composables
| Composable | Purpose |
|:---|:---|
| useArmorCost() | Track daily/monthly cost, budget proximity |
| useArmorStatus() | Health check, rate limit remaining |
| useArmorSafety() | Safety event tracking, block counts |
All composables are auto-imported -- no import statements needed.
Server API Routes
| Route | Description |
|:---|:---|
| GET /api/_armor/status | Health status, rate limit info |
| GET /api/_armor/usage | Cost tracking, budget utilization |
| POST /api/_armor/safety | Safety check for text content |
All routes protected by adminSecret when configured.
Server-Side Usage
Access the armor instance in server routes:
// server/api/chat.post.ts
export default defineEventHandler(async (event) => {
const armor = useArmor()
const result = await armor.invoke('openai:gpt-4o', {
messages: [{ role: 'user', content: 'Hello' }],
})
return result
})Compatibility
- Nuxt 3 (>=3.0.0)
- Nuxt 4 (>=4.0.0)
- Node.js >= 18
Documentation
Full documentation: billymaulana.github.io/ai-armor
License
MIT -- Billy Maulana
