documentation/docs/snippets/nextjs/.
New to the SDK? Start with the Node quickstart for the full client,
streaming, embeddings, and typed errors — this page focuses on wiring it into App Router routes.
1. Install and configure
.env.local
ROADIE_BASE_URL to target a self-hosted or regional host — the routes below already read it.
2. A chat route
Createapp/api/chat/route.ts. The client is constructed lazily and memoized so it is built
once per server instance.
snippets/nextjs/route.ts
3. A streaming route
Bridge the SDK’s async-iterable stream onto aReadableStream the browser can read. Create
app/api/chat/stream/route.ts:
snippets/nextjs/stream-route.ts
Run these routes on the Node.js runtime (not the Edge runtime) unless you have verified
streaming behavior on your deployment target.
Next steps
Node quickstart
The full SDK: embeddings, typed errors, and retries.
Rate limits, quotas & budgets
Cap spend and per-user usage before it happens.