Newshot
Account

Workflow SDK now writes over WebSockets on Vercel

Summary

The Workflow SDK now sends event writes and stream writes to Vercel Workflows over a WebSocket by default, replacing one HTTP request per write, or per write group for streams. No code change is needed beyond upgrading to [email protected] or later. Once you deploy the upgrade, new runs use it. In-flight runs finish on the deployment they started on. Existing streaming code works as is. A step that writes a burst of chunks, like AI tokens, sends them over the WebSocket once it opens: Streams keep pace with AI output In a benchmark replaying an AI agent's token stream, v5.2.0, which writes streams over a WebSocket by default, delivered the full response 4.2× faster than v4.8.12, with no chunk delayed over a second. Fewer HTTP requests for event writes Every step start and completion is an event write, now sent over the WebSocket, so workflows with many steps make fewer HTTP requests. The added efficiency also improves performance and reduces costs. The queue handler opens the connection fo…

Original text(via Vercel Blog)

The Workflow SDK now sends event writes and stream writes to Vercel Workflows over a WebSocket by default, replacing one HTTP request per write, or per write group for streams. No code change is needed beyond upgrading to [email protected] or later.

Once you deploy the upgrade, new runs use it. In-flight runs finish on the deployment they started on.


        npm install workflow@latest
      

Existing streaming code works as is. A step that writes a burst of chunks, like AI tokens, sends them over the WebSocket once it opens:


        import { getWritable } from "workflow";
async function streamChunks(chunks: string[]) {  "use step";  const writer = getWritable<string>().getWriter();  for (const chunk of chunks) {    await writer.write(chunk);  }  writer.releaseLock();}
export async function streamingWorkflow(chunks: string[]) {  "use workflow";  await streamChunks(chunks);}
      

Copy link to headingStreams keep pace with AI output

In a benchmark replaying an AI agent's token stream, v5.2.0, which writes streams over a WebSocket by default, delivered the full response 4.2× faster than v4.8.12, with no chunk delayed over a second.

Copy link to headingFewer HTTP requests for event writes

Every step start and completion is an event write, now sent over the WebSocket, so workflows with many steps make fewer HTTP requests. The added efficiency also improves performance and reduces costs. The queue handler opens the connection for every delivery.

Copy link to headingGet started

Read the Vercel World documentation to get started. If you're on 4.x, start with the upgrade guide, since v5 is a major release.

The text above was extracted automatically from the source page and may miss images, tables or code blocks. The original is authoritative.

Published by Vercel Blog
This site only summarises and aggregates; copyright stays with the original author. Headlines and summaries follow the source — where they differ, the original wins.
Read the original ↗