I am having an issue in which I get a 429 error saying that the Max Quota was exceeded but then I check the billing in the account that I am using and I have only used 35% of the total billing amount.
I checked my API Key to make sure I had the correct one and I do. I do not know why I am getting this error.
Edit:
My code is pretty simple. And it’s been working until yesterday (3-26-2024) where it started giving the errors I mentioned.
def call_ai(system, user, model='gpt-4', max_tokens=256):
client = OpenAI(api_key = os.getenv('OPENAI_API_KEY'))
max_retries = 5
retry_delay = 2
factor = 5
for i in range(max_retries):
try:
response = client.chat.completions.create(
model=model,
messages=[
{
"role": "system",
"content": system
},
{
"role": "user",
"content": user
}
],
temperature=0.3,
max_tokens=max_tokens,
top_p=1,
frequency_penalty=0,
presence_penalty=0
)
answer = response.choices[0].message.content
# answer = response["choices"][0]["message"]["content"]
return answer
except Exception as e:
print(f"Attempt {i+1} failed with error: {e}")
error_msg = str(e)
# Check if the error message contains the rate limit text
if "Rate limit reached for" in error_msg:
print("Rate limit reached, sleeping for 2 minutes...")
time.sleep(120)
elif i < max_retries - 1:
time.sleep(retry_delay)
retry_delay *= factor
def main():
system = "You are a Math Expert "
user = 'What is 1092398423 + 3920482948'
response = ai.call_ai(system, user,"gpt-4-turbo-preview", max_tokens=256)
print(response)