Error API chat.completation, requestor.request

This is my cod, and i dont know what is error. Can someone help me??? Please

import openai
import dotenv
env_vars = dotenv.dotenv_values()
openai.api_key = ["API_KEY"]
def ask_openai(message):
    response = openai.Completion.create(
        prompt = message,
    answer = response.choices[0].text.strip()
    return answer
def main():

    while True:
        message = input("Message: ")
        answer = ask_openai(message)
        print(f"Answer: {answer}")
if __name__ == "__main__":

This is the message of error:

If anyone can help me, i would be very very grateful.

The answer is at the bottom of your error message screen, where it says “please check your plan and billing details”.

The API is pay-per-data-use, and you must add a payment method and load your account with at least $5 of credit.

Also, by using davinci on the completion endpoint, you’d be spending 10x as much on a model from last year.

After you pay up and have a working API key, here’s a chatbot that will stream the words like ChatGPT, use the messages format for gpt-3.5-turbo, remember some conversation (and not word-wrap at words because that’s just as many lines of code to do elegantly).

import openai
openai.api_key = "sk-1234yourkey1234"
system = [{"role": "system", "content":
           "You are Jbot, a helpful AI assistant."}]
user = [{"role": "user", "content":
         "brief introduction?"}]
chat = []
while not user[0]['content'] == "exit":
    response = openai.ChatCompletion.create(
        messages = system + chat[-10:] + user,
        model="gpt-3.5-turbo", top_p=0.5, stream=True)
    reply = ""
    for delta in response:
        if not delta['choices'][0]['finish_reason']:
            word = delta['choices'][0]['delta']['content']
            reply += word
            print(word, end ="")
    chat += user + [{"role": "assistant", "content": reply}]
    user = [{"role": "user", "content": input("\nPrompt: ")}]

Yes, I don’t have any credit. I’ll reload later and try again. Thanks for your help.

Click here:

Account billing overview

Does it say that your credit balance is $0.00?

There’s a button “Add payment method” where you can fix that zero balance.

Then you’ll be able to use your minimum purchase of $5.00 of OpenAI API credit to consume OpenAI API services like language model AI.

1 Like

Yes, I don’t have any credit. I’ll reload later and try again. Thanks for your help.

1 Like