Next.js App Router + Kontext SDK — fast path to a personalized chat
userQuery
NEXT_PUBLIC_KONTEXT_API_URL
, NEXT_PUBLIC_KONTEXT_API_KEY
(for OAuth trigger + React hooks)KONTEXT_API_KEY
(route handlers), DEFAULT_PRIVACY_LEVEL
(strict default).env
:
app/providers.tsx
and wrap your root layout. This exposes hooks (e.g., useKontext()
) and holds userId
after OAuth.
KontextProvider
stores ?user_id=...
for you.
app/api/completion/route.ts
to fetch per‑user context and stream an LLM response.
userQuery
personalizes retrieval per turn.useRealtimeContext()
to reflect updates as new facts arrive (requires REDIS_HOST
on the API). Use usePollingContext()
as a fallback.
KONTEXT_API_KEY
in the browser (use server routes)DEFAULT_PRIVACY_LEVEL
(strict by default)403
on context: ensure OAuth consent exists for (developerId, userId)
404
on dataset query: facts‑first returned no facts; use search or upload with asUser
REDIS_HOST
configured on the API