API callings get stuck and don't return anything

Hi, I’m currently using the gpt-3.5-turbo model for chat completions, and I’ve encountered an issue while making multiple API calls in a loop. After several iterations, the API requests become stuck without returning any error information. I want to know what may cause this and how to solve this problem.

My code structure is as below:

def get_response(prompt):
    try:
        response = openai.ChatCompletion.create(
            model=gpt_model,
            messages=[{"role": "user", "content": prompt}]
        )
        res = response.choices[0].message['content'].split('\n')
        return res

    except openai.error.OpenAIError as e:
        print(f"Error: {e}")
        exit(1)

for prompt in prompts:
    answer  = get_response(prompt)
    print(answer)
    time.sleep(1)

Thank you!

P.S. I am a paid users and I am pretty sure I am under RPM and TPM limitations.

Hi and welcome to the Developer Forum!

Paying for ChatGPT Plus is not the same as having a payment method assigned to your API account, you will need to do that to lift the 3TPM limit, please add your card details to this section of the site OpenAI Platform