Skip to content
rmnr
DocsTourSlicesBest PracticeAgentsInstall

Command Palette

Search for a command to run...

New

Slice · AI prompt

AI Router — OpenRouter Tier Proxy

Authenticated tier-routed LLM access through one Convex action and OpenRouter. Ships a transport-injected ChatFab: React/Next remains default and SvelteKit gets native Svelte 5 UI over the same request/result core and the same aiUsage backend. Unconfigured hosts return an explicit notice instead of a fake reply.

Resource detail View source
Copy this prompt into Claude / Codex / Cursor
ai-router.prompt.mdmarkdown
# Install `ai-router` — AI Router — OpenRouter Tier Proxy

> Authenticated tier-routed LLM access through one Convex action and OpenRouter.

📚 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
npx rr add ai-router
# 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: `convex`, `ai`, `@openrouter/ai-sdk-provider`, `lucide-react`
- shadcn primitives: `button`, `card`, `input`
- env vars:
  - `OPENROUTER_API_KEY` (convex, required)
- convex feature paths: `convex/features/ai`

## 3. Wire it up

Run `npx rr add ai-router` or add `--framework sveltekit`. Bind ChatFab.route to api.features.ai.action.callModel. The action requires auth, keeps the provider key server-only, returns a notice when unavailable, and logs successful usage to aiUsage.

## 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.