By default, our functions run for 10 seconds. Your function is timing out which is why it’s crashing.
Our functions can run for a max of 26 seconds. They are intended to be used in live browser pages, but also, our infrastructure cuts off the connection at 26 seconds, so that is the practical max.
If you think that would be useful, you’d need to upgrade your team to a Pro plan and we can then update the timeout from 10 seconds to 26 seconds for you.
Otherwise, I’d recommend checking out this support guide for tips on optimizing your function: