Keep Getting "You exceeded your current quota, please check your plan and billing details." in Python

Fellows, I’m not sure if I’m the only one, but I keep getting:

“You exceeded your current quota, please check your plan and billing details. For more information on this error.”

My app is extremely basic:

from langchain_openai import OpenAI
from langchain.prompts import PromptTemplate
from langchain.chains import LLMChain
from langchain.chains import SequentialChain

import os
os.environ['OPENAI_API_KEY'] = 'MY_KEY'

try:
    llm = OpenAI(model="gpt-3.5-turbo", temperature=0.7)
    # Rest of your code
except Exception as e:
    print(f"Error: {e}")

def generate_restaurant_name_and_items(cuisine):
    prompt_template_name = PromptTemplate(
        input_variables = ['cuisine'],
        template = "I want to pen a restaurant for {cuisine} food. Suggest a fancy name for this."
    )

    name_chain = LLMChain(llm = llm, prompt = prompt_template_name, output_key = "restaurant_name")

    prompt_template_items = PromptTemplate(
        input_variables = ['restaurant_name'],
        template = """Suggest some menu items for {restaurant_name}. Return them in a comma separated format only."""
    )

    food_items_chain = LLMChain(llm = llm, prompt = prompt_template_items, output_key = "menu_items")

    chain = SequentialChain(
        chains = [name_chain, food_items_chain],
        input_variables = ['cuisine'],
        output_variables = ['restaurant_name', 'menu_items']
    )

    response = chain.invoke({'cuisine': cuisine})

    return response

if __name__ == "__main__":
    print(generate_restaurant_name_and_items("Russian"))

Am I new to use the OpenAI API? No, I have my own account since Apr 2023. However, this is my first time using Python. I have mainly worked with JS, but for this case, I must use Python. I have also created 3 keys with exactly the same results. Any idea if there is something wrong with the OpenAI API today? Thanks.

1 Like

The message generally indicates that your account is not funded.

Since you might be going in and getting new API keys, it is important to make sure you have the correct organization selected. In platform.openai.com, at lower left where your name is, there may be a pop-up with either “personal” and then another organization. After selecting, you need to find the one in “billing overview” that either says you are billed at the end of the month, or that you have a prepaid balance.

OpenAI has been converting some accounts from post-paid monthly billing, so you may need to now purchase credits before using the API again.

1 Like

You need to go to Billing overview - OpenAI API and make sure your credit balance is positive. I’d reccommend having at least $10, and monitor the Usage - OpenAI API to make sure it’s not excessive and everything is set up effeciently.