Unable to use Openai API (RateLimitError)

I’m trying to program a very simple interface in python to use ChatGPT. But I always get this recurring error that prevents me from moving forward.

Traceback (most recent call last):
  File "/usr/lib/python3.8/tkinter/__init__.py", line 1892, in __call__
    return self.func(*args)
  File "fiche de lecture.py", line 22, in on_ask_button_press
    response = obtenir_reponse(user_input)
  File "fiche de lecture.py", line 12, in obtenir_reponse
    response = openai.Completion.create(
  File "/usr/local/lib/python3.8/dist-packages/openai/api_resources/completion.py", line 25, in create
    return super().create(*args, **kwargs)
  File "/usr/local/lib/python3.8/dist-packages/openai/api_resources/abstract/engine_api_resource.py", line 153, in create
    response, _, api_key = requestor.request(
  File "/usr/local/lib/python3.8/dist-packages/openai/api_requestor.py", line 298, in request
    resp, got_stream = self._interpret_response(result, stream)
  File "/usr/local/lib/python3.8/dist-packages/openai/api_requestor.py", line 700, in _interpret_response
    self._interpret_response_line(
  File "/usr/local/lib/python3.8/dist-packages/openai/api_requestor.py", line 763, in _interpret_response_line
    raise self.handle_error_response(
openai.error.RateLimitError: You exceeded your current quota, please check your plan and billing details.

What I don’t understand is that on my Openai account, I haven’t spent any of the $18 offered to me. I’ve tried using ready-made projects found on the Internet to make sure that my code had no errors, and I always end up with this error no matter what the request. Here’s my code just in case:

import tkinter as tk
import tkinter.messagebox as messagebox
import openai

openai.api_key = '■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■blZ7uBLJ'

def obtenir_reponse(variable):
    question = f"""Je veux faire une fiche de lecture détaillé complet pour different livre. 
                    Le modè de la fiche est le suivant: Biographie de l'auteur, description détaillé des personnages,
                    résumé détaillé du livre et enfin une analyse du livre.
                    Fait tout cela de la facon la plus compléte. Lelivre sera {variable}."""
    response = openai.Completion.create(
        engine="gpt-3.5-turbo",
        prompt=question,
        stop=["\n"]
    )
    return response['choices'][0]['text'].strip()

def on_ask_button_press():
    global question_input
    global response_label
    user_input = question_input.get().strip()
    if user_input:
        response = obtenir_reponse(user_input)
        response_label.config(state=tk.NORMAL)
        response_label.delete(1.0, tk.END)
        response_label.insert(tk.END, response)
        response_label.config(state=tk.DISABLED)
    else:
        messagebox.showwarning("Attention", "Entre le nom d'un livre")

app = tk.Tk()
app.title("Fiche de lecture")

question_label = tk.Label(app, text="Entre le nom du livre :")
question_label.pack(pady=10)

question_input = tk.Entry(app, width=50)
question_input.pack(pady=5)

ask_button = tk.Button(app, text="rédiger", command=on_ask_button_press)
ask_button.pack(pady=10)

response_label = tk.Text(app, wrap=tk.WORD, width=60, height=10, state=tk.DISABLED)
response_label.pack(pady=10)

app.mainloop()

At the moment I’m just testing my programme, so I don’t exceed a few requests a day. And in the activity history of my API account I still have zero requests.

If anyone has any ideas, I’d love to hear them, because I’m really not familiar with the Openai API.

Thanks in advance for any help.

Welcme to the forum!

Have you setup a payment method for your account? You can do so by visiting OpenAI Platform

No, but I had understood that for limited use, I could use the API for free. I’d like to be sure that adding a payment method won’t result in a levy.

The free credits expire, you can check here. After that you’ll need to put in a credit card and will be charged based on usage.