next js 13 always internal server error after 5 minutes

Next JS 13. I have a an api that takes 6-10 minutes long to process since I have to process 5,000 rows of data. Next js returns an internal server error after 5 minutes, but the api is still running. I have tried to reupload multiple times but it always sends a 500 internal server error while the request on the server is still running and processing.
I get this response below on my api call:
500 internal server error

I have tried extending timeout in my axios call.