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. Events — requestEvent and responseEvent define typed messages with schema validation.
  2. Agent — myAgent 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. API — expose() turns the network into an SSE endpoint; NextEndpoint adapts it for Next.js.

Next