60

I'm making a Python script to use OpenAI via its API. However, I'm getting this error:

openai.error.RateLimitError: You exceeded your current quota, please check your plan and billing details

My script is the following:

#!/usr/bin/env python3.8
# -*- coding: utf-8 -*-

import openai
openai.api_key = "<My PAI Key>"

completion = openai.ChatCompletion.create(
  model="gpt-3.5-turbo",
  messages=[
    {"role": "user", "content": "Tell the world about the ChatGPT API in the style of a pirate."}
  ]
)

print(completion.choices[0].message.content)

I'm declaring the shebang python3.8, because I'm using pyenv. I think it should work, since I did 0 API requests, so I'm assuming there's an error in my code.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Unix
  • 1,358
  • 3
  • 14
  • 23
  • 15
    Did you enable the billing just now? When I did that it took a few minutes to start working (probably 10-15 mins), and before then I was getting that exact error message. – dcferreira Mar 31 '23 at 12:00
  • 1
    I think all my options are by default, excepting that I created a token 10 days ago, and today when I was gonna use it, it was not readable, so I created a new token and I removed the old one. Then I changed my "organization" name. But nothing else. – Unix Mar 31 '23 at 12:20
  • 1
    In case it might be helpful, I fixed the issue by activating the 'pay as you go' option in https://platform.openai.com/account/billing/overview. TL;DR: even if you have a paid ChatGPT account, you still need to pay for using the OpenAI API. – albus_c Apr 08 '23 at 13:47
  • 1
    i believe that this is a valid question because i had the same question. So even though it is closed, i have voted it up. The correct solution is suggested by @dcferreira. – D.L Jun 19 '23 at 16:36
  • a paid ChatGPT account is not the same as a paid API account – Gerry Aug 26 '23 at 16:20
  • apparently they also send an email to confirm for API key - not that they say anything about it! – Gerry Aug 26 '23 at 16:48

5 Answers5

77

TL;DR: You need to upgrade to a paid plan. Set up a paid account, add a credit or debit card, and generate a new API key if your old one was generated before the upgrade. It might take 10 minutes or so after you upgrade to a paid plan before the paid account becomes active and the error disappears.

Problem

As stated in the official OpenAI documentation:

TYPE OVERVIEW
RateLimitError Cause: You have hit your assigned rate limit.
Solution: Pace your requests. Read more in our rate limit guide.

Also, read more about Error Code 429 - You exceeded your current quota, please check your plan and billing details:

This (i.e., 429) error message indicates that you have hit your maximum monthly spend (hard limit) for the API. This means that you have consumed all the credits or units allocated to your plan and have reached the limit of your billing cycle. This could happen for several reasons, such as:

  • You are using a high-volume or complex service that consumes a lot of credits or units per request.

  • You are using a large or diverse data set that requires a lot of requests to process.

  • Your limit is set too low for your organization’s usage.


Did you sign up some time ago?

You're getting error 429 because either you used all your free tokens or 3 months have passed since you signed up.

As stated in the official OpenAI article:

To explore and experiment with the API, all new users get $5 worth of free tokens. These tokens expire after 3 months.

After the quota has passed you can choose to enter billing information to upgrade to a paid plan and continue your use of the API on pay-as-you-go basis. If no billing information is entered you will still have login access, but will be unable to make any further API requests.

Please see the pricing page for the latest information on pay-as-you-go pricing.

Note: If you signed up earlier (e.g., in December 2022), you got $18 worth of free tokens.

Check your API usage in the usage dashboard.

For example, my free trial expires tomorrow and this is what I see right now in the usage dashboard:

Before expiration

This is how my dashboard looks after expiration:

After expiration

If I run a simple script after my free trial has expired, I get the following error:

openai.error.RateLimitError: You exceeded your current quota, please check your plan and billing details.


Did you create your second OpenAI account?

You're getting error 429 because you created a second OpenAI account with the same phone number. It seems like free credit is given based on phone numbers.

As explained on the official OpenAI forum by @SapphireFelineBytes:

I created an Open AI account in November and my $18 credits expired on March 1st. So, like many of you here, I tried creating a new account with a different email address, but same number. They gave me $0 credits.

I tried now with a different phone number and email. This time I got $5 credits.

UPDATE:

It's confirmed that free credit is given based on phone numbers, as explained on the official OpenAI forum by @logankilpatrick:

Also note, you only get free credits for the first account associated with your phone number. Subsequent accounts are not granted free credits.

Solution

Try to do the following:

  1. Set up paid account.
  2. Add a credit or debit card.
  3. Generate a new API key if your old API key was generated before you upgraded to the paid plan.

When you upgrade to a paid plan, don't expect the error to disappear immediately, as @dcferreira mentioned in the comment above. It might take a few minutes after the upgrade before the error disappears.

UPDATE:

In the comment below, @JoeMornin confirmed that it took 10 minutes for his paid account to become active. In the meantime, he got the following error:

You've reached your usage limit. See your usage dashboard and billing settings for more details. If you have further questions, please contact us through our help center at help.openai.com.

Rok Benko
  • 14,265
  • 2
  • 24
  • 49
  • Now I unerstand that. A known person had $18 for free. I wasted 0 tokents and still I had 0 tokens in my dashboard. So as I see, I have to get the free $5 tokens, and that's only fro three months now... – Unix Mar 31 '23 at 12:51
  • If you go to the [usage dashboard](https://platform.openai.com/account/usage), what do you see? I edited my answer (see the screenshot above). Do you see "Free trial usage" in your account? – Rok Benko Mar 31 '23 at 13:07
  • Yes, and the values are $0.00 / $0.00. That means I don't have the free trial $18.00 (neither the new $5.00 for three months). It's like I've never had free tokens for the API. The only thing I used is the ChatGPT via web browser. – Unix Mar 31 '23 at 13:29
  • Oh, wow... Did you contact customer support? Because this is very strange. Btw, using ChatGPT via browser shouldn't affect your API tokens. I'm really interested why do you see $0.00 / $0.00. – Rok Benko Mar 31 '23 at 13:34
  • I'm gonna contact them. For better context: I created my account in Feb 17 (2023) to test GPT3 (one or two prompts via web browser). Then I joined again in March 21 to test GPT4 (about 10 prompts via web browser), I created the first API key and I tried to connect without success. Then today I tried this script because I discovered that fact about the $18.00 with a lot of people using it in the terminal. – Unix Mar 31 '23 at 13:49
  • Explain it to them exactly like this so they can help you better. I created my API key right after signing up (the same day). That was in December 2022. Maybe they don't give free credit anymore and you created the first API key too late? Please let me know what the problem is once you have the answer. :) – Rok Benko Mar 31 '23 at 13:58
  • See [this](https://community.openai.com/t/how-can-i-get-free-trial-credits/26742). Do you only have one account? – Rok Benko Apr 03 '23 at 07:55
  • Yes, I only have one account. After reading the thread, I can see they are changing terms randomly... – Unix Apr 03 '23 at 16:03
  • I see. People are figuring out what's happening. Everyone has a different experience. – Rok Benko Apr 04 '23 at 07:44
  • @Unix Did you solve the problem? What was wrong? – Rok Benko Apr 14 '23 at 08:49
  • Still no, they are not giving me an answer, and the credits are still 0,00. I'm wondering if it's a version issue. Perhaps I'm logged for GPT4 when other people is using GPT3.5. I don't know how to chek it. – Unix Apr 14 '23 at 12:40
  • @Unix I had a [discussion in the comment section](https://stackoverflow.com/questions/76012599/ratelimiterror-in-chatgpt-discord-bot-code-without-even-using-it-once?noredirect=1#comment134063687_76012599) today with a guy having the same problem. – Rok Benko Apr 14 '23 at 12:57
  • 1
    @Unix - I created 2 accounts with separate email addresses, but using the same phone number. The first account was allocated $18 of credit - the second one was not allocated any credit. Apparently, this is because I used the same phone number: https://help.openai.com/en/articles/6614457-why-am-i-getting-an-error-message-stating-that-i-ve-reached-my-usage-limit Anyway, it's annoying that the credit expired after 3 months. I only used 1 cent (and I'm not sure how). They should give more thought to the overall user experience wrt registration and credits. – Peter Apr 25 '23 at 07:40
  • 1
    So Open AI is not an open ai for every one :( – lortschi Aug 01 '23 at 08:45
  • I created another account with another gmail to find out if I could have free credits, but when I registered it with the same number it didn't let me, it told me that it is limited even though it is another account, I suppose they detect your ip, fingerprint, number, etc... You must pay yes or yes after the free version – Lenin Zapata Aug 04 '23 at 19:35
  • It took about 10 minutes for my paid account to become active. During those ten minutes, I got this error message: "You've reached your usage limit. See your usage dashboard and billing settings for more details. If you have further questions, please contact us through our help center at help.openai.com." I waited and it fixed itself. – Joe Mornin Aug 10 '23 at 21:02
  • thanks. this answer helped me. in my case, my account was older than 3 months. – Vijay Aug 11 '23 at 08:17
4

Your code looks fine. In fact, I believe it's an example they give on their website. The problem appears to be on OpenAI's side. If you scroll all the way to the bottom, someone posted about this four days ago.

Rate Limit Error

Some people said that if they waited for a while it started working, so maybe just hang tight.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Brock Brown
  • 956
  • 5
  • 11
3

Just create a new API Key and use it. It worked for me.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
nayan dhabarde
  • 1,734
  • 1
  • 19
  • 38
  • 10
    This didn't work for me. The issue seems linked to the account, not to the API keys. – Unix May 08 '23 at 19:09
  • Okay so basically, I had no limit at first, then I updated to the paid plan, observed that even after setting up payment method it is not working. So i created new key and it worked, Updating payment option should be easy to find in settings – nayan dhabarde May 09 '23 at 03:05
  • 2
    This works if your old API key was created before you upgraded to the paid plan. Use a new API after upgrading to the paid plan – Forth Temple May 13 '23 at 03:43
  • Didn't work for me either. It must be to do with the account. – digitalWestie May 24 '23 at 13:46
3

I was facing the same error, and for me the steps were:

  1. Add a credit or debit card in payment methods.
  2. Generate a new API key in user preferences.
  3. (Optional) Delete the old API key.
  4. Be sure to set limits to not incur in charges

This are the limits for gpt-3.5-turbo RPM 3,500 TPM 90,000

Hope it helps.

  • Hi. In the last step, can you share the values you entered in order to avoid charges? Thanks. – James Silva May 17 '23 at 16:18
  • Because of my needs, I just added a soft limit of 1 USD and a hard limit of 5 USD, it is not possible to get rid of payment, but set the limits to an amount you feel comfortable with. – Toni Verger May 19 '23 at 13:25
  • under "usage" I can see that all my free-trial stuff is pink/expired.. that's that it was – SeanMC Jul 05 '23 at 02:51
1

I encountered a similar issue and found a solution that worked for me. I first canceled my paid account and renewed it with a different payment method. Next, I went to the 'API Keys' section, selected my organization under the 'Default Organizations' dropdown, and saved the changes. This action reset my soft limit, but I still needed to create a new API key to resolve the issue completely.

  • Cancel paid account and recreate with new payment method
  • Confirm Organization
  • Create new API Key