OpenAI API giving error: 429 Too Many Requests
Asked Answered
A

9

43

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.
Anuria answered 7/1, 2023 at 15:38 Comment(6)
OpenAi has rate limit a number of request per minute. It may over your call. help.openai.com/en/articles/…Ethics
I got the same error on my first call. I checked my billing and had not used any of my credit granted.Currier
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.Grindle
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"Hafnium
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.Varion
I am getting the same error 429 Too Many Requests on first request. The API error persists also if I try again... I am below the rate limit (obviously) and I am below the quota (just checked in the dashboard).Ideography
O
44

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!

Opheliaophelie answered 21/4, 2023 at 4:53 Comment(5)
This solved it for me after I had just upgraded to a paid account.Zeitgeist
it worked for me after creating 2nd new keyTrailblazer
this is the correct answer for me and it all worked once i regenerated an api keyMadonna
This is the way. Add credits first, then create new API key.Haileyhailfellowwellmet
You can keep the old key, but it will work back again after about 48 hours after you add some creditAnatolic
C
26

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.

Chlorate answered 6/4, 2023 at 13:35 Comment(0)
L
10

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

Leifleifer answered 17/5, 2023 at 17:36 Comment(0)
D
5

My experience is that I started getting this error, in 2024, when OpenAI changed their payment policy to prepaid. They now require you to load your account with funds before you can use the API. Everything now works as it was.

Drogue answered 27/2 at 13:40 Comment(2)
Yes, this was the issue for me. I also had to wait around 5 minutes after I added funds to my account before the API started working again.Coroneted
Same for me. This answer helped me to find the settings.: You can go to Settings -> Billing to see your credit balance.Poynter
Q
3

Answer: add credit

I was getting 429 Too many requests even though it was my very first attempt at using the OpenAI API!

The solution was to add credit to the API account:

  1. Go to settings: https://platform.openai.com/settings
  2. Click on 'Billing'
  3. Click on the 'Add to credit balance' button
  4. It took ~3 minutes after adding credit that everything worked (it was not immediate)

enter image description here

Quicken answered 13/5 at 1:38 Comment(0)
O
1

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.

Ornie answered 8/1, 2023 at 1:4 Comment(4)
I'm seeing this error on the first request with a brand new API key.Rhizogenic
Well, I just installed Visual ChatGPT Studio and then try a simple question and I immediatelly get this error. I'm asking in the plugin window within VS 2022Skintight
@WayneSmallman that's strange. Could your IP possibly have exceeded the amount of credits?Ornie
Someone else pointed out that it could be because I authorized with a telephone number that's attached to another account that's expired.Rhizogenic
P
1

The same error is also caused by insufficient credits. https://platform.openai.com/docs/guides/error-codes

Code Overview
429 - You exceeded your current quota, please check your plan and billing details Cause: You have run out of credits or hit your maximum monthly spend. Solution: Buy more credits or learn how to increase your limits.

You can go to Settings -> Billing to see your credit balance.

Picked answered 1/4 at 20:38 Comment(0)
H
0

I just fix it. (if it's really the same problem).

Now we have to add fund to openAI in the billing section.

OpenAI --> personal --> billing

In the Overview tab, you have a "Add to credit balance". I do not remember what the previous message was, but there's will be a popup to allowing you to add a minimum amount threshold to automatically add credit money. I put the minimum at $5 and every time your credit go under this amount, i put $10.

After about 5 minutes, everything worked. You can go to the playground to test, and you will receive a popup message warning if it do not work yet.

Haler answered 19/4 at 22:39 Comment(0)
E
0

Their website doesn't alert you when you've depleted your prepaid balance.

Conspiring with this is the design of their website where you have to choose the right project and the right month to see your usage.

And in my case, conspiring further still was that I ran out just as April ended so the May chart showed no usage! Leading me to think it was faulty.

It would all be easier if

  1. There was a banner at the top of the page saying that my account balance was ZERO.

  2. The HTTP error included something about account balance, if possible.

  3. There was either a continuous chart, or as a quick solution, to have a recap of the prior month on the current month with a navigation button.

Estoppel answered 2/5 at 9:34 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.