An error occurred while communicating with OpenAI

An error occurred while communicating with OpenAI? how do I fix this? Am using a Personal API Key, not using a Project Key. It was working fine, randomly this error is showing.

import os
import discord
import openai
import aiohttp
import json
import asyncio

TOKEN = os.getenv(‘TOKEN’)
OPENAI_API_KEY = os.getenv(‘GPT’)

intents = discord.Intents.all()
client = discord.Client(intents=intents)
session = None

original_queries = {}
response_messages = {}

async def ask_chatgpt(question, chat_model=“gpt-4”):
global session
async with”,
“Authorization”: f"Bearer {OPENAI_API_KEY}“,
“Content-Type”: “application/json”
“messages”: [{
“You are a specialized assistant”
}, {
“role”: “user”,
“content”: question
})) as response:
if response.status == 200:
data = await response.json()
return data[‘choices’][0][‘message’][‘content’].strip()
return “An error occurred while communicating with OpenAI.”
except Exception as e:
return f"An error occurred: {str(e)}”


What’s the error code?

Do you have billing and credits up to date?

Error occured while communicating with OpenAI
Added a $6 Credit Balance
Same Issue

Can you log what error code it’s sending?

1 Like