Getting quota exceeded error 429 when calling OpenAI ChatGPT API

I wrote a Python program that connects to OpenAI’s ChatGPT service through their API. When I run my code, I keep getting this error message:

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

Here’s my Python code:

#!/usr/bin/env python3

import openai

# Set up API credentials
openai.api_key = "<YOUR_API_KEY_HERE>"

# Create chat completion request
response = openai.ChatCompletion.create(
    model="gpt-3.5-turbo",
    messages=[
        {"role": "user", "content": "Write a story about AI in the style of Shakespeare"}
    ]
)

# Display the response
print(response.choices[0].message.content)

This is confusing because I haven’t made any API calls before this. I just got my API key and this is my first attempt to use it. Is there something wrong with how I’m setting up the request? The error makes it sound like a billing issue but I expected to have some free usage available.

The 429 error you’re encountering is related to a billing issue rather than a problem with your code. OpenAI has discontinued the provision of free trial credits for new accounts, which means you likely don’t have any balance despite having a new API key. To resolve this, you need to add a payment method and purchase credits in your OpenAI dashboard before the API calls can function correctly. It’s advisable to check the billing section to review your current balance and any usage limits. Furthermore, keep in mind that if free credits are offered, they may expire after a few months of inactivity. Your code appears to be correct; simply addressing the billing setup should solve the problem.

This topic was automatically closed 4 days after the last reply. New replies are no longer allowed.