Slice · AI prompt
Backend infrastructure (no UI). Single proxy that every other ai-* feature calls. Tier-routed — nano (Haiku) for classification, mid (Sonnet) for chat, flagship (Opus) for deep reasoning. Per-call usage log + cost guard. Works with direct provider keys or OpenRouter umbrella. Not something you mount — installed automatically as a peer when you add ai-workspace.
# Install `ai-router` — AI Router — Backend Provider Proxy
> Backend infrastructure (no UI).
📚 Knowledge base : https://resource.rahmanef.com/llms.txt
📦 Slice detail : https://resource.rahmanef.com/slices/ai-router
🧠 JSON catalog : https://resource.rahmanef.com/api/knowledge?slice=ai-router
🔗 Source : https://github.com/rahmanef63/resource-site/tree/main/frontend/slices/ai-router
## 1. Install
```bash
npm i ai @openrouter/ai-sdk-provider
# alias: npx rr add ai-router
```
The CLI copies `frontend/slices/ai-router/` into your project + augments `.env.example` + installs npm deps automatically. Run it from your project root.
## 2. What it ships
- npm: `ai`, `@openrouter/ai-sdk-provider`
- shadcn primitives: `button`
- env vars:
- `OPENROUTER_API_KEY` (convex, required)
- convex feature paths: `convex/features/ai`
## 3. Wire it up
Run `npx rr add ai-router`. Wrap every AI call through ai-router. Tiers: nano = quick classification (spam-flag, headline-suggest), mid = chat / draft, flagship = methodology-review / deep-think. Token usage logs to ai_usage table for the cost dashboard.
## Rules of engagement
- shadcn-only UI primitives. No raw `<button>` / `<dialog>` / native date or file inputs.
- 200-line hard cap per source file (extract neighbours when over).
- All Convex queries hit an index (`.withIndex(...)`); never bare `.collect()`.
- Public mutations/queries declare `args:` validators + authz.
- Full ruleset: https://resource.rahmanef.com/best-practice
The agent will fetch /llms.txt for the full ruleset and use /api/knowledge for the JSON catalog.