How to query a slow API with Nuxt and avoid time-out issues


I am building a Nuxt app (for internal use) where users query the OpenAI API. Those queries tend to be quite slow and regularly go beyond the 26 seconds limit.
I am not using Netlify functions atm, just making API calls to OpenAI through the nitro engine in Nuxt. What are my options to avoid time-outs here? I read about Netlify background functions, but struggle to understand how to use those with Nuxt3. Is it the only way forward? Any pointers would be greatly appreciated!

Hi @nif, kindly visit the Netlify blog post below if you have not already visited in order to get a clear understanding of how background functions work.

Also the blog post below is a very good resource to understand the difference between Regular Netlify Functions and Netlify Background Functions.
It was the resource I used myself to help me understand the difference between how Regular Netlify Functions and Netlify Background Functions work.
It goes into details with examples e.t.c

Hope this helps.


Thanks, I am working my way through those posts now, very useful indeed.

What puzzles me is the boundary and differences (if any) between the nitro server functions that I have out of the box with Nuxt and the serverless functions offered by Netlify. In general it seems I can use Nuxt’s server functions out-of-the box nicely but there is no way to handle background functions outside of using Netlify functions.

To my knowledge you can as soon as the background function is invoked, a 202 response is received and the process is queued in the background. Once a task is complete, you can either send a request to a Regular Netlify Function or a Web Hook.

With background functions you only get a 202 response and then the process continues in the background.

Hope the above explanations helps.