# Rate Limit Error

**URL:** <https://community.deeplearning.ai/t/rate-limit-error/388934>\
**Category:** ChatGPT Prompt Engineering for Developers\
**Created:** [July 18, 2023, 10:00am UTC](https://community.deeplearning.ai/t/rate-limit-error/388934 "2023-07-18T10:00:18Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Devang\_Gangwar](https://avatars.discourse-cdn.com/v4/letter/d/85e7bf/32.png) [@Devang\_Gangwar](https://community.deeplearning.ai/u/Devang_Gangwar)\
**Post date:** [July 18, 2023, 10:00am UTC](https://community.deeplearning.ai/t/rate-limit-error/388934/1 "2023-07-18T10:00:18Z")

</div>

on running the prompt i got rate limit error.

---

<div class="post-metadata">

**Author:** ![pravinpathak](https://avatars.discourse-cdn.com/v4/letter/p/258eb7/32.png) [@pravinpathak](https://community.deeplearning.ai/u/pravinpathak)\
**Post date:** [August 2, 2023, 5:56pm UTC](https://community.deeplearning.ai/t/rate-limit-error/388934/2 "2023-08-02T17:56:08Z")

</div>

I’m also getting same error. Are you able to fix this?

---

<div class="post-metadata">

**Author:** ![marcda](https://avatars.discourse-cdn.com/v4/letter/m/838e76/32.png) [@marcda](https://community.deeplearning.ai/u/marcda)\
**Post date:** [August 3, 2023, 6:23am UTC](https://community.deeplearning.ai/t/rate-limit-error/388934/3 "2023-08-03T06:23:27Z")

</div>

Can you please give some advice to understand and avoid Rate Limit Errors?

---

<div class="post-metadata">

**Author:** ![CandyGZ](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/candygz/32/59673_2.png) [@CandyGZ](https://community.deeplearning.ai/u/CandyGZ)\
**Post date:** [August 16, 2023, 5:13pm UTC](https://community.deeplearning.ai/t/rate-limit-error/388934/4 "2023-08-16T17:13:16Z")

</div>

The rate limit error occurs because ChatGPT has a limit of responses by minute (3 by minute), so in order to fix it you need to paid for the “no limit version” or, as i fixed:  
“import time” in your code  
then each time you need a response add a  
“time.sleep(20)” where 20 is the time in second you will wait before asking ia to bring a response.  
this way, yes, you get a little bored waiting but you don´t have to execute example by example or pay nothing.

Example:

````auto
import openai
import os
import time

from dotenv import load_dotenv, find_dotenv

_ = load_dotenv(find_dotenv())

openai.api_key = "APIKEY"

def get_completion(prompt, model="gpt-3.5-turbo"):
    messages = [{"role": "user", "content": prompt}]
    response = openai.ChatCompletion.create(
        model=model,
        messages=messages,
        temperature=0, # this is the degree of randomness of the model's output
    )
    return response.choices[0].message["content"]

prompt = f"""
Translate the following English text to Spanish: \ 
```Hi, I would like to order a blender```
"""

response = get_completion(prompt)
print(response)

prompt = f"""
Tell me which language this is: 
```Combien coûte le lampadaire?```
"""
time.sleep(20)
response = get_completion(prompt)
print(response)

prompt = f"""
Translate the following text to French and Spanish
and English pirate: \
```I want to order a basketball```
"""
time.sleep(20)
response = get_completion(prompt)
print(response)

prompt = f"""
Translate the following text to Spanish in both the \
formal and informal forms: 
'Would you like to order a pillow?'
"""
time.sleep(20)
response = get_completion(prompt)
print(response)

````
