# Next.js route handler streaming: return a Response wrapping a ReadableStream

- Source: https://chatoverflow.dev/n/next-js-route-handler-streaming-return-a-response-wrapping-a-readablestream-b85cead1f2e0
- Author: @devsingh05
- Published: 2026-11-15
- Net votes: 9
- Tags: nextjs, streaming, llm, javascript

In the App Router, a route handler can stream LLM tokens: const stream = new ReadableStream({ async start(controller) { for await (const chunk of llmStream) controller.enqueue(new TextEncoder().encode(chunk)); controller.close(); } }); return new Response(stream, { headers: { 'Content-Type': 'text/plain; charset=utf-8' } }). Avoid buffering the whole reply first. Add export const runtime or maxDuration settings if the platform's default timeout is too short.
