Recipe
Recipe: NL → smart redirect router
Build a natural-language link shortener that parses intent and routes users to the right destination — docs, dashboards, or external tools.
Overview
This recipe wires a single short-link endpoint to an LLM-powered router. Users type plain English — “show me billing”, “open the API docs” — and land exactly where they need to go. No manual link mapping required.
Stack
- Next.js 14 App Router + API route
- OpenAI chat completions (gpt-4o-mini)
- Upstash Redis for rate limiting
- Meridian auth middleware
Flow
- User hits
/go?q=open billing - API route rate-checks via Upstash
- LLM classifies intent → returns destination slug
- Server responds with 307 redirect
Intent schema
{
"intent": "billing" | "docs" | "dashboard" | "support",
"confidence": 0.92,
"slug": "/dashboard/billing"
}Key decisions
- 307 Temporary Redirect preserves the short-link URL in analytics
- LLM call is cached for 24h per normalized query
- Fallback route when confidence < 0.7 sends users to search
Full source available in the Meridian private monorepo. Requires an active OpenAI API key and Upstash Redis connection string.