@firstflow/runtime works in any React setup. In Next.js (App Router) the only rules are the usual ones: the provider is a client component, and your server-only Supabase key never crosses into the browser.
Provider in a client component
The provider uses hooks andlocalStorage, so it must run on the client. Wrap it in a "use client" component and mount that in your layout.
app/firstflow-provider.tsx
app/layout.tsx
Environment variables
Only the browser-safe pair carries theNEXT_PUBLIC_ prefix. The server SDK’s service_role key must not:
Wrapping LLM calls in route handlers
Use the server SDK inside route handlers (or server actions), where theservice_role key is safe:
app/api/chat/route.ts
Notes
- The browser runtime has no conversation id. Link the two sides by passing the same
user.idto the provider and to your server calls; the server-sideconversationId/sessionIdis owned by your own chat code. - Identify users from your auth in the client component (
user={...}); omit it for anonymous visitors.