Error code: 429 - 'You exceeded your current quota, please check your plan and billing details

I’ve been having a headache with the configuration the KEY API for a week now.

I have a MAC and I am using JupyterLab and I charged my Pay as you go to 20$ (Billing Settings)

I did the following steps:

1)Install Python
pip install --upgrade openai
I don’t have any virtual environment
My Python version is 3.8.18

2) Setup my API key on my MAC by Terminal
export OPENAI_API_KEY=‘sk-*******’
I verify than that I have the API KEY environment variable correctly configured on my MAC.

    echo $OPENAI_API_KEY
    sk-****************  (It works fine)

**3) Sending my first API request
I make a “openai-test.py” by Terminal and Copy and Paste the next code:

    from openai import OpenAI
    client = OpenAI()
    completion = client.chat.completions.create(
            model="gpt-3.5-turbo",
            messages=[
            {"role": "system", "content": "You are a poetic assistant, skilled in                   explaining complex programming concepts with creative flair."},
            {"role": "user", "content": "Compose a poem that explains the concept of                recursion in programming."}
           ]
   )
  print(completion.choices[0].message)

Now, the following line is executed via Terminal
python openai-test.py and it works fine

**But on my JupiterLab script it doesn’t work when I execute this sentence,

   import os
   api_key = os.getenv('OPENAI_API_KEY')
   
    from openai import OpenAI
    client = OpenAI()
    completion = client.chat.completions.create(
            model="gpt-3.5-turbo",
            messages=[
            {"role": "system", "content": "You are a poetic assistant, skilled in                   explaining complex programming concepts with creative flair."},
            {"role": "user", "content": "Compose a poem that explains the concept of                recursion in programming."}
           ]
   )
  print(completion.choices[0].message)

it doesn’t founds my environment variable OPENAI_API_KEY Why? What it is happening?

I’m also facing the same issue. Please share if you’ve got a solution.

Check if JupyterLab is Running in a Different Environment: Sometimes, JupyterLab might be running in a different Python environment from your terminal. You can check the environment in JupyterLab by running:

import sys
print(sys.executable)

Compare this with the output of which python or which python3 in your terminal to see if they match.

Alternatively, use a .env File: you can create a .env file in the same directory as your Jupyter notebook and set your environment variables there. Then, use a library like python-dotenv to load these variables in your notebook:

from dotenv import load_dotenv
load_dotenv()

Remember to add this .env file to your .gitignore.

2 Likes

Same problem here, I paid for API usage but I can’t use it.

Same here, also made separate post on today’s payment issue: Recently set up paid account with 5$ in the morning, still getting openai.RateLimitError: Error code: 429 - {'error': {'message': 'You exceeded your current quota, please check your plan and billing details

1 Like

You make an interesting observation - the last time that purchased credits had a significant delay in being made available for use (despite the purchased balance showing on the account) was the last “first-of-the-month” — when OpenAI starts processing all the monthly billings of accounts.

Until OpenAI and Stripe recognizes this and gets their act together, at least letting you know your payment is “in process, not yet charged”, it’s either simply wait (and you can check online banking), or in the future, make sure your account is set to auto-refill with significant margin.

(the OP had a similar error message but different cause)

Well, it seems like the amount has been deducted from the bank, and is successfully shown in the settings > billing page. And rather openai api aren’t aware post transaction that its recharged somehow.

i have the same issue the money has been removed from my bank, i have 15 USD credits, pay as you go, i made new API keys changed the usage limites and nothing works.

1 Like