惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

量子位
博客园_首页
Google DeepMind News
Google DeepMind News
博客园 - Franky
The GitHub Blog
The GitHub Blog
GbyAI
GbyAI
有赞技术团队
有赞技术团队
Microsoft Azure Blog
Microsoft Azure Blog
G
Google Developers Blog
Recent Announcements
Recent Announcements
A
About on SuperTechFans
博客园 - 【当耐特】
博客园 - 三生石上(FineUI控件)
酷 壳 – CoolShell
酷 壳 – CoolShell
美团技术团队
罗磊的独立博客
IT之家
IT之家
博客园 - 聂微东
Stack Overflow Blog
Stack Overflow Blog
Jina AI
Jina AI
腾讯CDC
P
Proofpoint News Feed
Hugging Face - Blog
Hugging Face - Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com

Vercel News

Vercel Open Source Program: Winter 2026 cohort How Notion Workers run untrusted code at scale with Vercel Sandbox How we run Vercel's CDN in front of Discourse From idea to secure checkout in minutes with Stripe Building Slack agents can be easy Scaling redirects to infinity on Vercel Advancing Python typing Gamma builds design-first agents with Vercel How Avalara turns pipe dreams into patent-pending with v0 Keeping community human while scaling with agents How OpenEvidence built a healthcare AI that physicians actually trust Security boundaries in agentic architectures Skills Night: 69,000+ ways agents are getting smarter Video Generation with AI Gateway We Ralph Wiggumed WebStreams to make them 10x faster How Stably ships AI testing agents in hours, not weeks How we built AEO tracking for coding agents Anyone can build agents, but it takes a platform to run them Introducing Geist Pixel The Vercel AI Accelerator is back with $6m in credits Making agent-friendly pages with content negotiation The Vercel OSS Bug Bounty program is now available Introducing the new v0 Run untrusted code with Vercel Sandbox, now generally available How Stripe built a game-changing app in a single flight with v0 How Sensay went from zero to product in six weeks AGENTS.md outperforms skills in our agent evals Agent skills explained: An FAQ Testing if "bash is all you need" AWS databases are now live on the Vercel Marketplace and v0
Function streaming to be framework-agnostic on Vercel - V...
2024-07-04 · via Vercel News

2 min read

Streaming will soon be enabled by default for all Node.js Vercel Functions

In 2023, Vercel Functions added support for streaming HTTP responses.

This feature has been enabled for frameworks like Next.js (App Router), SvelteKit, Remix, and more. We've been progressively rolling out streaming to more frameworks over the past two years, and we're beginning to roll out streaming for all functions and compatible frameworks.

Link to headingWhat changes when streaming responses?

When your Vercel Functions stream responses instead of buffering, you can immediately return results to your visitors—either an API function response or a server-side template.

Link to headingResponses on runtime errors

When streaming, response headers are sent immediately with the initial stream. If there is a runtime error after the initial headers have been sent, the function closes the stream and logs an error to Vercel. For example:

api/index.js

import { setTimeout } from "node:timers/promises";

export default async function (req, res) {

res.writeHead(200, { "Content-Type": "text/plain" });

res.write("Chunk 1\\n");

await setTimeout(1000);

throw new Error("Oh no!");

}

An example function that writes to the response with a delay.

When buffering a response and not streaming, this function would not respond for several seconds. Since the function throws an error before completion, it would respond with a 500 error:

HTTP/2 500

cache-control: public, max-age=0, must-revalidate

content-type: text/plain; charset=utf-8

date: Mon, 24 Jun 2024 10:26:35 GMT

server: Vercel

strict-transport-security: max-age=63072000; includeSubDomains; preload

x-robots-tag: noindex

x-vercel-error: FUNCTION_INVOCATION_FAILED

x-vercel-id: cdg1::hgz6d-1719224792404-c4031128df3b

content-length: 56

A server error has occurred

FUNCTION_INVOCATION_FAILED

An example of a 500 error response from a Vercel Function.

When streaming is enabled, the response status code and part of the body will have already been sent to the client. The stream will send the status code and part of the body before ending. For example, you would then see Oh no! error in the Vercel logs.

HTTP/2 200

age: 0

cache-control: public, max-age=0, must-revalidate

content-type: text/plain

date: Mon, 24 Jun 2024 10:29:58 GMT

server: Vercel

strict-transport-security: max-age=63072000; includeSubDomains; preload

x-robots-tag: noindex

x-vercel-cache: MISS

x-vercel-execution-region: iad1

x-vercel-id: cdg1::iad1::zclv9-1719224997952-452256b220b0

Chunk 1

An example of a 200 response from a streamed function.

Link to headingEnhanced runtime logs experience

Without streaming, Functions need to finish executing before a response can be sent to the client. Similarly, logs are only sent from the function and visible in the Vercel logs UI until after the function finishes responding.

When viewing runtime logs in the Logs tab, you would see a single line for each function invocation. The log line contains all context for that invocation up to 4KB size limit. For example:

import { setTimeout } from "node:timers/promises";

export default async function (req, res) {

console.log("Before setting a response");

res.writeHead(200, { "Content-Type": "text/plain" });

res.write("Chunk 1\\n");

await setTimeout(1000);

console.warn("Before writing a second chunk");

res.write("Chunk 2\\n");

await setTimeout(1000);

console.error("Before ending the response");

res.end("Done!");

}

An example function that writes a response with a delay.

When this function is called three times in a row, we can see the following in Vercel Logs tab:

We see three log lines above, each appearing only after the function invocation had finished. Logs for each invocation are collapsed into a single line. Now, let's explore how this changes when we enable streaming.

With streaming, each log statement gets its own line with a precise timestamp. Logs appear in near real-time, streaming in as they happen. You do not need to wait for the function invocation to complete to see logs.

You will notice the individual log lines do not display the status code. This is because logs are independent of the response and can occur before a status code is determined. With streaming being enabled by default, this brings consistency to the logs experience when using Vercel Functions.

These changes in frequency and format of Function logs will also affect Vercel Log Drains. If you are using Log Drains, ensure that your provider supports streaming responses and this increase frequency for logs.

Link to headingEnabling streaming functions today

Streaming will be enabled by default for Hobby accounts starting July 8th, 2024; and for Pro and Enterprise accounts starting October 1st, 2024.

To enable streaming as the default today for all your Vercel Functions, set the VERCEL_FORCE_NODEJS_STREAMING environment variable in your project to true. Streaming will be enabled on your next deployment.