Keep your secret key on the server. The browser calls your route; your route calls Roadie. Both handlers below are executed in CI; the runnable sources are in 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
The SDK calls the default hosted gateway (). Set an optional ROADIE_BASE_URL to target a self-hosted or regional host — the routes below already read it.
.env.local is read only on the server. Never expose ROADIE_KEY to the client (no NEXT_PUBLIC_ prefix).

2. A chat route

Create app/api/chat/route.ts. The client is constructed lazily and memoized so it is built once per server instance.
snippets/nextjs/route.ts
Call it from the client:

3. A streaming route

Bridge the SDK’s async-iterable stream onto a ReadableStream the browser can read. Create app/api/chat/stream/route.ts:
snippets/nextjs/stream-route.ts
Read it on the client:
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.