Skip to main content

Node.js Vercel Functions now support request cancellation

By Steven Van ·

Route-level cancellation lets functions stop compute and AI token generation when users leave, but it must be enabled in vercel.json.

Node.js Vercel Functions can now detect when a request is cancelled and stop running before it finishes. Cancellation covers cases such as navigating away, closing a tab, or hitting stop on an AI chat. Ending the work early cuts unnecessary compute, token generation, and data sent to a user who never sees it.

Request cancellation is supported at the route level, and it has to be enabled manually in vercel.json. A function can listen for it with Request.signal.aborted or the abort event. Projects using the AI SDK can forward abortSignal to their stream, passing req.signal so the model call stops when the client leaves.

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

Original source

Read Node.js Vercel Functions now support request cancellation on Creators Toolbox