Open AI API not working well

I used an open ai api but i am not able to make more then 3 calls is it a API issue or some limitter issue i have not used any limiter init any one

Welcome, can you share the errors you are getting and your code (without API Key)?

ok here is the code i am using next js import { NextApiRequest, NextApiResponse } from ‘next’;
import { Configuration, OpenAIApi } from ‘openai’;

type ResponseData = {
text: string;
};

interface GenerateNextAPiRequest extends NextApiRequest {
body: {
prompt: string;
};
}

const configuration = new Configuration({
apiKey: process.env.OPEN_AI_API_KEY,
});
const openai = new OpenAIApi(configuration);

export default async function handler(
req: GenerateNextAPiRequest,
res: NextApiResponse
) {
const prompt = req.body.prompt;
if (!prompt) {
return new Response(‘Please ask your question’, { status: 400 });
}

try {
const aiResult = await openai.createCompletion({
model: ‘text-davinci-003’,
prompt: ${prompt},
temperature: 0.4,
max_tokens: 1000,
frequency_penalty: 0.5,
presence_penalty: 0,
n: 4,
});

//for generating random results from API response

const randomIndex = Math.floor(
  Math.random() * aiResult?.data?.choices.length
);
const choice = aiResult.data.choices[randomIndex];

const Result =
  choice?.text?.trim() || 'Sorry there is problem.. Try again later';
res.status(200).json({ text: Result });

} catch (error) {
res.status(500).json({
text: ‘Sorry, something is wrong with the server. Try again Later!’,
});
}
}

The “limiter” is that you are in free trial and do not have a payment method on file for the API to be billed when that runs out. Three requests per minute is the correct answer.

Add a payment method to show you are ready to step to the next level, 60 per minute for two days holdoff and then 3500. Your trial credit will still be used until exhausted or expired.

1 Like

so i had to add a payment method first to increase the number of calls ?

The information I provide is accurate.

https://platform.openai.com/docs/guides/rate-limits/what-are-the-rate-limits-for-our-api

If it always throws an error after 3 calls, then yes the payment method is likely the culprit. There are two types of limits. Overall usage and then rate-limiting. If you really don’t want to pay, you can instruct your program to wait 30 seconds between calls.