Skip to content

r.streamHandler(...)

Registers a streaming read handler. Like queryHandler, but the body is an async generator — every yield is streamed to the client as an SSE chunk.

r.streamHandler({
name: "chat:complete",
schema: z.object({ prompt: z.string() }),
access: { roles: ["User"] },
handler: async function* (input, ctx) {
yield "token";
},
});

See also: queryHandler


Source: packages/framework/src/engine/feature-ast/patterns.tsStreamHandlerPattern