File: pipe-ui-message-stream-to-response.md | Updated: 11/15/2025
Menu
v5 (Latest)
AI SDK 5.x
Model Context Protocol (MCP) Tools
Copy markdown
================================================================================================================================================
The pipeUIMessageStreamToResponse function pipes streaming data to a Node.js ServerResponse object (see Streaming Data
).
import { pipeUIMessageStreamToResponse } from "ai"
pipeUIMessageStreamToResponse({ response: serverResponse, status: 200, statusText: 'OK', headers: { 'Custom-Header': 'value', }, stream: myUIMessageStream, consumeSseStream: ({ stream }) => { // Optional: consume the SSE stream independently console.log('Consuming SSE stream:', stream); },});
ServerResponse
The Node.js ServerResponse object to pipe the data to.
ReadableStream<UIMessageChunk>
The UI message stream to pipe to the response.
number
The status code for the response.
string
The status text for the response.
Headers | Record<string, string>
Additional headers for the response.
({ stream }: { stream: ReadableStream }) => void
Optional function to consume the SSE stream independently. The stream is teed and this function receives a copy.
On this page
Deploy and Scale AI Apps with Vercel.
Vercel delivers the infrastructure and developer experience you need to ship reliable AI-powered applications at scale.
Trusted by industry leaders: