Hi! I have web app for generating recipes from ingredients via open ai api. I am sending post request and using API key in Bearer Token for Authorization. Issue is: when I use open ai key from my account then the request takes more than 2 minutes and then gives the response. But when I used the api key from my friends account, then the response time becomes 12s to 16s. I couldn’t found any solution to this.
I am doing it in Nextjs. Here is my request body:
const getRecipes = async () => {
router.push("/recipes");
toggleLoadingRecipes();
try {
const response = await fetch(
"https://api.openai.com/v1/chat/completions",
{
method: "POST",
headers: {
Authorization: `Bearer ${process.env.NEXT_PUBLIC_OPENAI_API_KEY}`,
"Content-type": "application/json",
},
body: JSON.stringify({
model: "gpt-3.5-turbo",
messages: [
{
role: "system",
content:
"You are a skilled ....",
},
{
role: "user",
content: `Please produce two unique recipe for the following ingredients: ${formatStringArray(
ingredients
)}`,
},
],
}),
}
);
const fetchedRecipes = await response.json();
const recipesArray = Object.values(
JSON.parse(
removeTrailingCommas(fetchedRecipes.choices[0].message.content)
)
);
setIngredientsHandler(ingredients);
setRecipesHandler(recipesArray as Recipe[]);
// console.log(recipesArray);
setLoading(false);
toggleLoadingRecipes();
} catch (error) {
setLoading(false);
// console.log(error);
router.push("/");
}
};