Vercel Functions using Node.js can now detect when a request is cancelled and stop execution before completion. This is configurable on a per-path basis, and 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 would never see.
To enable cancellation, add "supportsCancellation": true
to your vercel.json
configuration. You can apply it to specific paths or all functions:
Once enabled, 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.