js-next in the deployment cookbook.
Deploy to Vercel
Import the repository
Click Deploy with Vercel below, or import 
langchain-ai/deployment-cookbook manually..env.example.
Required API endpoints
The app exposes the Agent Streaming Protocol under/api/threads/.... Route handlers live in app/api/threads/.
Minimum (streaming chat)
These three endpoints are enough to run a single-threaded streaming chat with@langchain/react’s HttpAgentServerAdapter:
| Method | Path | Purpose |
|---|---|---|
POST | /api/threads/:threadId/commands | Accept protocol commands (run.start, …) and start agent runs |
POST | /api/threads/:threadId/stream | SSE stream of protocol events for a run |
GET / POST | /api/threads/:threadId/state | Read and bootstrap checkpointed thread state |
GET /state (and POST /state on 404) so hydration does not 404 before the first message is sent.
Optional (thread sidebar)
This example also implements endpoints for the thread-history sidebar. Omit them if your UI does not need multi-thread management:| Method | Path | Purpose |
|---|---|---|
GET | /api/threads | List threads known to the checkpointer |
DELETE | /api/threads/:threadId | Delete a thread’s session and checkpoints |
POST | /api/threads/:threadId/history | Paginated checkpoint history (Agent Protocol) |
Request flow
- Bootstrap thread state (
GET/POST /state). - On submit, the SDK sends
run.startto/commandsand receives arun_id. - The SDK subscribes to
/stream(SSE) for replay + live protocol events. - Subagent (
task) runs emit namespaced events surfaced asstream.subagents.
Production persistence
Out of the box, the agent uses an in-memoryMemorySaver checkpointer (lib/agent/index.ts) and a process-local session map (lib/server/registry.ts). That works for local dev and single-instance servers, but on Vercel (serverless, multiple replicas) conversation state is not durable across cold starts or instances.
For production, swap in a durable checkpointer:
| Package | Backend |
|---|---|
@langchain/langgraph-checkpoint-redis | Redis (RedisSaver) |
@langchain/langgraph-checkpoint-postgres | Postgres (PostgresSaver) |
@langchain/langgraph-checkpoint-sqlite | SQLite (SqliteSaver) |
MemorySaver in lib/agent/index.ts and pass the new checkpointer to createDeepAgent. The route handlers and lib/server/threads.ts helpers stay the same.
Redis on Vercel
A common choice for Vercel is Redis via the Marketplace (for example Upstash Redis). Install the integration on your Vercel project; credentials are injected as environment variables automatically. Then wire@langchain/langgraph-checkpoint-redis:
lib/server/registry.ts so SSE reconnection works across serverless invocations. The checkpointer swap is the main step for durable thread history; the session store is a separate concern for live-run replay.
For more information, see checkpointer libraries and add memory / persistence.
Local development
Project layout
lib/agent/: deep agent (createDeepAgent) withresearcherandmath-whizsubagents and mock tools. Markedserver-only.lib/server/: protocol server logic:session.ts(SSE runs),threads.ts(checkpointer-backed state),serialize.ts,registry.ts.app/api/threads/: Route Handlers for the protocol endpoints above.lib/chat/threads-client.ts: browser thread bootstrap and sidebar helpers.components/: chat UI (ChatApp,Chat,MessageList,Subagents,ThreadHistory, …).
See also
- Frameworks and platforms overview
- Agent Streaming Protocol
react-custom-backend— original Vite + Hono reference for a custom protocol server- Next.js Route Handlers
Connect these docs to Claude, VSCode, and more via MCP for real-time answers.

