22

I am trying to make a request to the openai API with the following code in express nodeJS:

import { Configuration, OpenAIApi } from "openai";

const configuration = new Configuration({
    organization: "org-Fn2EqsTpiUCTKb8m61wr6H8m",
    apiKey: "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
});
const openai = new OpenAIApi(configuration);

async function callApi() {
    const response = await openai.createCompletion({
        model: "text-davinci-003",
        prompt: "Say this is a test",
        max_tokens: 3000,
        temperature: 0,
      });

    console.log(response.data.choices[0].text);
}

callApi();

The problem is that I keep getting error 429 Too many requests.

Here some more information:

  • The API key is correct.
  • When I go to my openai account > view API KEY: it shows that the key was never used so I have never been able to make a call. So how is it possibile that I'm getting error Too many requests?
  • I have already tried to implement exponential backoff in the function, but it didn't work.
Penny Liu
  • 15,447
  • 5
  • 79
  • 98
Karan
  • 247
  • 1
  • 2
  • 9
  • OpenAi has rate limit a number of request per minute. It may over your call. https://help.openai.com/en/articles/5955598-is-api-usage-subject-to-any-rate-limits – Bench Vue Jan 07 '23 at 16:08
  • 6
    I got the same error on my first call. I checked my billing and had not used any of my credit granted. – etoxin Mar 09 '23 at 08:33
  • Getting the same error. Checked if my API key was being used in the "usage" in open ai's dashboard, it said the api was unused. Dont understand why still getting a 429 error. – Awshaf Ishtiaque Apr 02 '23 at 09:19
  • 2
    Does this answer your question? [OpenAI ChatGPT (GPT-3.5) API error 429: "You exceeded your current quota, please check your plan and billing details"](https://stackoverflow.com/questions/75898276/openai-chatgpt-gpt-3-5-api-error-429-you-exceeded-your-current-quota-please) – Rok Benko Apr 12 '23 at 13:16
  • Getting this error without a specific error message (nothing like `Rate limit reached for default-text-davinci-002 in ...`). Getting the error sometimes, even though I'm way below my limits. – Jonas Sourlier May 31 '23 at 09:59

4 Answers4

22

If you get the same error (429) after April 1st, that means your free trial 18$ (of all accounts registed before April) expired, even you haven't use api key once.

In your API Usage page, you will found like this:

GRANT # CREDIT GRANTED  EXPIRES (UTC)
Grant 1 $18.00  Expired 2023-04-01

Good news is you can still use official web chat page.

Just be happy
  • 364
  • 3
  • 5
17

I had the same issue. The reason was that I created my API key BEFORE converting my OpenAI account to paid (adding credit card). Doesn't matter if you only upgrade, you also need to create a new api key entirely.

I created another API key AFTER I added my credit card and it worked fine!

Cain
  • 181
  • 1
  • 5
4

Not for OP, but in my case, the issue was that I needed to provide my organisation Id to the Configuration method like this:

import { Configuration } from "openai";

const configuration = new Configuration({
    organization: "org-xxxx",
    apiKey: "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
});

You can get the organisation Id from this page: https://platform.openai.com/account/org-settings

Josh
  • 41
  • 1
3

The answer is in the error that you have received.

The error 429 Too Many Requests means that you have exceeded your free $18 in API credits. You can pay for more on the official website.

It's not possible that your key is correct but is not being used when you try to make a request. Double check that you are using the correct key in your code.

joeymalvinni
  • 343
  • 9