1.Check if the key is loaded:
console.log(process.env.OPENAI_API_KEY);
If it's undefined, dotenv didn't load it correctly.
2.Check if your network block access to external APIs by using curl.
curl https://api.openai.com/v1/models -H "Authorization: Bearer your-api-key"
If this fails, it's a network issue, not your code.
Please provide the complete error message and your config to analyze the problem.