@chatpack/next
v0.1.19
Published
Next.js App Router integration for Chatpack - mount the chat API on one route
Readme
@chatpack/next
Next.js App Router integration for Chatpack - mount the whole chat API on one catch-all route.
The Chatpack handler is already Web-standard (Request → Response), which is
exactly what App Router route handlers expect, so this package is a thin,
readable convenience wrapper.
Install
# pick your package manager
npm install @chatpack/core @chatpack/adapter-memory @chatpack/next
pnpm add @chatpack/core @chatpack/adapter-memory @chatpack/next
bun add @chatpack/core @chatpack/adapter-memory @chatpack/nextUse
// lib/chat.ts
import { chatpack } from "@chatpack/core";
import { memoryAdapter } from "@chatpack/adapter-memory";
export const chat = chatpack({
storage: memoryAdapter(),
auth: async (req) => getSessionUser(req), // your auth
});The
authhook must returnChatpackUser | null- an object with at least{ id: string }, ornullfor unauthenticated requests (401). A bare string is treated as unauthenticated. Prefer cookie-based sessions -EventSource(the SSE stream) cannot send custom headers.
// app/api/chat/[...chatpack]/route.ts
import { toNextRouteHandlers } from "@chatpack/next";
import { chat } from "@/lib/chat";
export const { GET, POST, PATCH, DELETE, PUT } = toNextRouteHandlers(chat);The route file must be a catch-all (
[...chatpack]) so every sub-path under/api/chat- including/api/chat/stream- reaches the handler.
Mounting somewhere other than /api/chat? Pass the base path:
export const { GET, POST, PATCH, DELETE, PUT } = toNextRouteHandlers(chat, {
basePath: "/api/messaging",
});See the REST API reference for all routes.
Community
- Discord — chat with the team and other developers
- X — releases and updates
- Docs — the full documentation site
- GitHub Discussions — questions, show-and-tell, and feedback
