4

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.

Shubham Srivastava
  • 1,190
  • 14
  • 28
  • 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. – ddejohn Mar 27 '23 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. – Shubham Srivastava Mar 27 '23 at 18:22
  • If you need to make more requests than that, then I guess you need to buy a plan. – Tim Roberts Mar 27 '23 at 18:23
  • @TimRoberts I have tried only 5-6 request and it is very less than the free trial – Shubham Srivastava Mar 27 '23 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. – ddejohn Mar 27 '23 at 18:30

2 Answers2

1

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".

Jaroslav Bezděk
  • 6,967
  • 6
  • 29
  • 46
Robert Brisita
  • 5,461
  • 3
  • 36
  • 35
1

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

Peewee 733
  • 31
  • 6