Vercel Functions using Node.js can now detect when a request is cancelled and stop execution before completion. This includes actions like navigating away, closing a tab, or hitting stop on an AI chat to terminate compute processing early.
This reduces unnecessary compute, token generation, and sending data the user never see.
You can listen for cancellation using Request.signal.aborted
or the abort
event:
If you're using the AI SDK, forward the abortSignal
to your stream:
Learn more about cancelling Function requests.