Skip to main content

WebSocket support is now generally available

By Steven Van ·

WebSockets work on all Vercel plans with Fluid compute, using the same limits and pricing as other Function invocations.

WebSocket support in Vercel Functions is now generally available. Since the public beta launched in late June, Vercel CDN has served 300 million WebSocket connections, and it now serves 15 million per day. Customers use them for AI chat, streaming and realtime multiplayer apps, and they also power AI Gateway's realtime models.

How connections work

A WebSocket connection starts as an HTTP GET request with an Upgrade header. Before the upgrade, the request goes through the same routing and security controls as other Function requests, including Routing Middleware, rewrites, Firewall rules and rate limits. Firewall rules can target the WebSocket request path, and rate limits apply to each upgrade request.

Each connection is pinned to one Function instance for its lifetime, and Fluid compute lets one instance handle several connections. Connections close when a Function reaches its maximum duration, so clients need reconnect logic that recreates the connection, resubscribes to channels and reloads state. A reconnecting client may reach a different instance, and after a new deployment, existing connections stay on the previous deployment until they close. Durable state, presence, rooms and pub/sub coordination belong in an external store, such as Redis from the Vercel Marketplace.

Setting up an endpoint

Libraries like ws can upgrade connections with no additional configuration. Socket.IO also works, provided the client is set to use the WebSocket transport rather than its default HTTP long-polling.

  • Bun: the native Bun.serve() WebSocket API is supported, with some differences from a standalone Bun server. Headers passed to server.upgrade() are not applied, the drain handler is not invoked, and socket.send() does not return Bun's -1 backpressure status.
  • Node.js frameworks: Express, Hono and h3 can serve WebSockets.
  • Nitro and Nuxt: enable the websocket feature in the Nitro config and export a handler with defineWebSocketHandler().
  • Next.js: it has no API for WebSocket upgrades, so upgradeWebSocket() from @vercel/functions 3.10.0 or later is the workaround.
  • Python: FastAPI and Django Channels (ASGI) and Flask-Sock (WSGI) work without a Vercel-specific upgrade API. python-socketio and Flask-SocketIO are also supported.

Availability and pricing

WebSockets are available on all plans and require Fluid compute, which is the default for projects created on or after April 23, 2025. Connections follow the same limits and pricing as other Function invocations. That covers Function usage while the connection is active, plus Fast Data Transfer and Fast Origin Transfer for data sent over it. With Active CPU pricing, CPU is billed only for the time spent processing messages.

Vercel
Vercel
The platform for frontend developers — deploy, preview, and scale web apps and AI agents with zero config.
View Vercel →

Original source

Read WebSocket support is now generally available on Creators Toolbox