Tips on how to reduce the response time of an express API that can take upto 2 minutes

96 Views Asked by At

I'm currently working on a portfolio project where I have developed an Express API that utilizes the OpenAI API to generate an array of objects based on a provided example object. Additionally, I have an "/img" endpoint that generates images to accompany each object in the array.

However, I'm facing an issue when it comes to hosting this API. Due to the time-consuming nature of the OpenAI API calls, the average response time of my API is around 1 minute. Since this is my first time hosting an API, I'm unsure how to handle these long response times, as most hosting platforms tend to time out responses after 10-30 seconds (especially on free tiers), which isn't sufficient for my API's needs.

I would greatly appreciate any help, advice, or optimizations you could suggest to improve the response time. As a reference, the code for my project is available in this repository: https://github.com/hasin202/ObjectAlchemy/.


To provide some additional context, when making a request to the "/img" endpoint, the OpenAI API is called three times:

  1. Generating the array of objects.
  2. Generating the prompt for each object's image.
  3. Generating each image.
0

There are 0 best solutions below