Aborting external long running api request inside a Vercel serverless function

I have a request in a Vercel serverless function to an external API using node fetch inside a serverless function. I do not want this to be long running so my plan is to abort the external request if it takes longer than a second.

Is this a good strategy?

>Solution :

Yes, this is a valid approach.

Serverless functions in the Vercel Hobby plan already have a built-in timeout of 10s, so maybe you don’t even need to worry about doing this yourself.

If you choose to do this, I would recommend increasing the timeout duration. It is common for an API request to take longer than a second ("depends", of course). But maybe a timeout of 3s or 5s is good enough.

Leave a Reply