createRouteHandler(agent, options?) serves an agent from a route file of any
framework whose handlers take a Web Request and return a Response: the
Next.js App Router, SvelteKit, Remix / React Router, Hono, Bun.serve. It is a
thin wrapper over the same session API as lousho dev and the deployed server
(Deployment), so the React, Vue and Svelte bindings work against it
unchanged. It imports no framework and no node:* module.
Next.js App Router
auth is public: anyone who can reach it can run your agent
and spend your model budget. Pass a bearer token, or a function that checks your
own session or cookie:
Routes
All paths are underbasePath (default /api/agent; a trailing slash is
accepted, and a request outside the base path is a 404).
Sessions are kept by the agent’s
store (createAgent({ store })), so give
the agent one that outlives a serverless invocation when you use sessions.
Client: useLoushoAgent
Client: useChat
With uiMessageStream: true, point useChat at the ui route. The chat id
names the session, so only the newest user message is sent to the agent
(AI SDK UI).