6

I have started to implement openai gpt model in python. I have to send a single request in which I am getting RateLimitError.

My code looks like this

import openai

key = '<SECRET-KEY>'
openai.api_key = key
model_engine = 'text-ada-001'
prompt = 'Hi, How are you today?'
completion = openai.Completion.create(engine=model_engine, prompt=prompt, max_token=2048, n=1, stop=None, temprature=0.5)
print(completion.choices)

This is what error I am getting

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

So, How do I do development without getting this error? I have checked the doc they provide a free version with limitations but this is the initial stage I have sent only 5-6 requests in an hour.

Thanks advance for your help.

5
  • Did you do this inside a for loop at any point? What do the docs say are the limitations? The "rate limit" error could be referring to the frequency at which you were hitting the API. Commented Mar 27, 2023 at 18:18
  • No, I haven't used for loop. This is the only code I have written so far just to test so that I can proceed but getting error in this code only. Commented Mar 27, 2023 at 18:22
  • If you need to make more requests than that, then I guess you need to buy a plan. Commented Mar 27, 2023 at 18:23
  • @TimRoberts I have tried only 5-6 request and it is very less than the free trial Commented Mar 27, 2023 at 18:26
  • As I said it could also be the frequency at which you made the requests, not necessarily the number of requests you've made so far. Commented Mar 27, 2023 at 18:30

3 Answers 3

3

Later versions (>= 1.0.0) of the openai Python API include functionality to automatically retry requests. See GitHub discussion.

Sign up to request clarification or add additional context in comments.

Comments

2

This probably stems from the server being overloaded. There is an article on OpenAI's help subdomain.

If you encounter a RateLimitError, please try the following steps:

  • Wait until your rate limit resets (one minute) and retry your request. The error message should give you a sense of your usage rate and permitted usage.
  • Send fewer tokens or requests or slow down. You may need to reduce the frequency or volume of your requests, batch your tokens, or implement exponential backoff. You can read our rate limit guidance here.
  • You can also check your usage statistics from your account dashboard.

More helpful info:

The second link has limits that your script should take into account when making requests or retrying requests. All this info was found by doing a web search on "openai.error.RateLimitError".

Comments

1

You can use e.g. https://github.com/phelps-sg/openai-pygenerator to automatically retry requests when a RateLimitError occurs.

Edit: the new 1.0.0 Python API includes functionality for automatically retrying requests.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.