Skip to main content
Copy and paste this minimal example into a Next.js API route (e.g. app/api/chat/route.ts):

What This Does

  1. EventsrequestEvent and responseEvent define typed messages with schema validation.
  2. AgentmyAgent listens for user-request, runs logic, and emits agent-response.
  3. Network — The main channel receives requests; the client channel streams responses via HTTP.
  4. APIexpose() turns the network into an SSE endpoint; NextEndpoint adapts it for Next.js.

Next