Skip to Content

Streaming

Streaming

AI providers can be slow when producing responses, but many make their responses available in chunks as they're processed. Streaming enables you to show users those chunks of data as they arrive rather than waiting for the full response, improving the perceived speed of AI-powered apps.

Vercel recommends using Vercel's AI SDK to stream responses from LLMs and AI APIs. It reduces the boilerplate necessary for streaming responses from AI providers and allows you to change AI providers with a few lines of code, rather than rewriting your entire application.

Getting started

The following example shows how to send a message to one of OpenAI's models and streams:

Prerequisites

  1. You should understand how to setup a Vercel Function. See the Functions quickstart for more information.
  2. You should be using Node.js 20 or later and the latest version of the Vercel CLI.
  3. You should copy your OpenAI API key in the .env.local file with name OPENAI_API_KEY. See the AI SDK docs for more information on how to do this.
  4. Install the ai package: pnpm yarn npm bun

    pnpm i ai

Our Services

messages: [{ role:'user', content:'What is the capital of Australia?' }],

// This method must be named GET

exportasyncfunctionGET() {

import { streamText } from'ai';
},
TypeScript

});

// Make a request to OpenAI's API based on

constresponse=streamText({
model:'openai/gpt-4o-mini',
Next.js (/app)
returnresponse.toTextStreamResponse({

headers: {

});

}
'Content-Type':'text/event-stream',
// Respond with the stream
// a placeholder prompt

Function duration

If your workload requires longer durations, you should consider enabling fluid compute, which has higher default max durations and limits across plans.

Maximum durations can be configured for Node.js functions to enable streaming responses for longer periods. See max durations for more information.

Streaming Python functions

You can stream responses from Vercel Functions that use the Python runtime.

When your function is streaming, it will be able to take advantage of the extended runtime logs, which will show you the real-time output of your function, in addition to larger and more frequent log entries. Because of this potential increase in frequency and format, your Log Drains may be affected. We recommend ensuring that your ingestion can handle both the new format and frequency.

More resources

Previous

Last updated September 1, 2026


Getting Started

Was this helpful?

Cross-link map: Streaming (/docs/functions/streaming-functions)From the Vercel docs graph (built 2026-09-21T05:26:59.511Z), spanning vercel.com docs + KB, nextjs.org, ai-sdk.dev, and other Vercel documentation sites. Full graph as JSON: https://vercel.com/docs/graph.jsonSemantically closest pagesStreaming in web applications — Learn how streaming works in web applications. Explore benefits, use cases, and implementation details with Vercel FunctStreaming responses from LLMs — Learn how to use the AI SDK to stream LLM responses.Function streaming to be framework-agnostic on VercelAn Introduction to Streaming on the WebVercel Functions — Build API routes, webhooks, and agent request handlers with Vercel Functions, then test and debug them with Vercel CLI.This page links to (12)Getting StartedVercel CLI Overview — Learn how to use the Vercel command-line interface \(CLI\) to manage and configure your Vercel Projects from the commandWorking with Drains — Drains collect logs, traces, speed insights, and analytics from your applications. Forward observability data to customFluid compute — Learn about fluid compute, an execution model for Vercel Functions that provides a more flexible and efficient way to ruVercel Functions — Build API routes, webhooks, and agent request handlers with Vercel Functions, then test and debug them with Vercel CLI.Vercel Functions Limits — Learn about the limits and restrictions of using Vercel Functions.Vercel Function Logs — Use runtime logs to debug and monitor your Vercel Functions.Getting started with Vercel Functions — Build your first Vercel Function in a few steps.Does streaming affect SEO and can streamed content be indexed? — Streamed content does not affect SEO and will still be indexed by Google. Learn more in this guide.Handling Backpressure — Learn how to handle backpressure by pushing data into a steam as it's needed, rather than as it's ready.Processing Data Chunks — Learn how to create an API endpoint that processes data chunks.Streaming in web applications — Learn how streaming works in web applications. Explore benefits, use cases, and implementation details with Vercel FunctPages that link here (30)By site: vercel-changelog (4) · vercel-kb (4) · vercel-web (3) · vercel-docs (19)From vercel-changelogPython Vercel Functions now have streaming enabled by defaultStreaming is now supported in Vercel Functions for the Python runtimeStreaming now enabled by default for all Node.js Vercel FunctionsStreaming to be enabled by default for all Node.js Vercel FunctionsFrom vercel-kbPublish and subscribe to realtime data on Vercel — Learn how to publish and subscribe to realtime data on Vercel with WebSockets, SSE, Redis, and Queues, and when a manageProduction architecture for a RAG chatbot on Vercel — Architect a production RAG chatbot on Vercel Functions with Fluid compute, AI Gateway, and a region-pinned vector store.How to stop Vercel Functions from timing out — Vercel Functions that time out usually trace back to a few causes. Learn how Fluid Compute fixes most of them and how toStreaming in web applications — Learn how streaming works in web applications. Explore benefits, use cases, and implementation details with Vercel FunctFrom vercel-webDeploying AI-driven apps on VercelVercel Edge Functions are now generally availableBuilding a GPT-3 app with Next.js and streaming (historical)From vercel-docsVercel CDN overview — Vercel's CDN is a globally distributed platform that handles routing, caching, security, and compression for every deploFrameworks on Vercel — Vercel supports a wide range of the most popular frameworks, optimizing how your application builds and runs no matter wFrontends on Vercel — Vercel supports a wide range of the most popular frontend frameworks, optimizing how your application builds and runs noReact Router on Vercel — Deploy React Router applications with SSR or SPA mode, then configure the Vercel preset, streaming, caching, and analytiFull-stack frameworks on Vercel — Vercel supports a wide range of the most popular backend frameworks, optimizing how your application builds and runs noNext.js on Vercel — Vercel is the native Next.js platform, designed to enhance the Next.js experience.Remix on Vercel — Deploy Remix applications to Vercel and configure the Vercel Vite preset, SSR, streaming, caching, and analytics.SvelteKit on Vercel — Deploy SvelteKit applications to Vercel and configure the adapter, rendering, streaming, ISR, analytics, and Routing MidSupported Frameworks on Vercel — Learn about the frameworks that can be deployed to Vercel.Vercel Functions — Build API routes, webhooks, and agent request handlers with Vercel Functions, then test and debug them with Vercel CLI.Advanced Configuration — Learn how to add utility files to the /api directory, and bundle Vercel Functions.Vercel Functions Limits — Learn about the limits and restrictions of using Vercel Functions.Vercel Function Logs — Use runtime logs to debug and monitor your Vercel Functions.Getting started with Vercel Functions — Build your first Vercel Function in a few steps.Runtimes — Runtimes transform your source code into Functions, which are served by our CDN. Learn about the official runtimes suppoEdge Runtime — Learn about the Edge runtime, an environment in which Vercel Functions can run.WebSockets — Serve WebSocket connections in Vercel Functions for realtime features like chat, collaboration, and AI streaming.Runtime Logs — Learn how to search, inspect, and share your runtime logs with the Logs tab.Monitoring Reference — This reference covers the clauses, fields, and variables used to create a Monitoring query.