Getting rate limit error when using the API. Working fine on Playground

My code:

I am using Python client to make a call. Here is my Python code:

import os

import openai
from dotenv import load_dotenv, find_dotenv

_ = load_dotenv(find_dotenv())

openai.api_key = os.getenv("OPENAI_API_KEY")

response = openai.ChatCompletion.create(
    model="text-davinci-003",
    messages=[
        {"role": "user", "content": "Act as a senior software engineer. Explain binary search within 500 words."}
    ],
    temperature=0.5
)

print(response.choices[0].message["content"])

I am getting an exception which ends with this line:

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

More info:

  • I have a paid plan. $5 has been deducted a few days back, and should be valid for a month.
  • I’m sure I’ve not used up the quota.
  • This only happens with the Python client, not playground. I have not tested the node client though so can’t confirm.

I’m posting my usage just for sake:

1 Like

Hi there,

One possible solution to the issue you’re facing could be to double-check your API key. Make sure you’re using the correct API key, as sometimes you might have multiple API keys and might be accidentally using an expired key or one with an exhausted quota. To verify your current API key, you can head over to your OpenAI dashboard.

Personally, this is the only thing that comes to my mind at the moment. I hope this helps!
Let me know if this solved the problem :wink:

Sincerely,
Villaseque Joris

1 Like

The password is correct because it tells me directly, the problem is that it recognizes my mobile number as Premium and does not let me access, the password is correct. Please help me!
Thanks!

Welcome to the community @sntshk

This error is bound to happen, given this code.

You’re calling 'text-davinci-003' on chat completions endpoint.

I strongly recommend reading docs for chat completions and using the boilerplate code shared there.

If you want to use 'text-davinci-003', I recommend going through text completion docs

2 Likes

I created a new key and it worked with that key. Finally I’m getting a different error solution of which is given by @sps.

I did’t understood how this worked. Each key has their own limits? Is this thing documented?

I saw the first link you provided. I think it only works with gpt-3.5-turbo and gpt-4. Thanks for pointing it out.

I would like to ask a follow up question.

Talking about the text completion, I used this code:

response = openai.Completion.create(
    model="text-davinci-003",
    prompt="Act as a senior software engineer. Explain binary search within 500 words.",
    temperature=0.5
)

print(response.choices[0].text)

But the output is around 15 words only.

Binary search is an efficient algorithm for finding an item from an ordered

Do you know why? The ChatCompletion endpoint works good with gpt-3.5-turbo.

It’s because by default max_tokens is set to 16 on the text completion endpoint. I’d recommend reading API reference before you continue.