CORS not working on remote server, but working on localhost for ChatGPT

I have a node server.js file that is working for CORS on all of my functions on localhost but when I deploy in production on my AWS server, everything works except my chatGPT API. The chatGPT API works fine on localhost. All of my environment variables are fine.

Has anyone run into this issue and is there a solution for this? Below is a sample of my server.js file:

const express = require('express');
const dotenv = require('dotenv')
dotenv.config()
const cors = require("cors");
var bodyParser = require('body-parser');

console.log(process.env.NODE_ENV)

const OpenAI = require('openai')
const path = require('path')
const {generateUploadURL} = require('./s3.js')
const { engine } = require('express-handlebars');

const app = express();
app.use(cors());
// app.use(express.urlencoded({extended: false}));

//Body parser middleware (for sending back data in html)
app.use(bodyParser.json({limit: '50mb'}));
app.use(bodyParser.urlencoded({limit: '100mb', extended: true}));
app.use(express.json());


//Homepage Route
app.get('/', (req,res)=>{
    res.sendFile(path.join(__dirname, '/', 'index.html'))
})

//Setup database query function
const {Pool} = require("pg");
const pool = new Pool({ ssl: { rejectUnauthorized: false } });
pool.connect((err, release) => {
    if (err) {
      return console.error(`connection error to database`, err.stack)
    } else {
      return console.log(`connected successfuly to database`)
    }
  })
const dbQuery=(text, params) =>pool.query(text, params);


//general database query <-- this is working fine from everywhere
app.use("/db/table", async (req, res)=>{
    
    const table = req.params.table
    const query = `SELECT * FROM ${table};`
    console.log(query)
    
    try{
        const result = await dbQuery(query);
        res.json(result.rows);
        console.log(result.rows)
    } catch(err){
        res.send(err)
        console.log(err)
    }
})


//Basic GPT response <--This is ok on localhost but not on AWS server
app.get("/getgpt/:prompt", async(req,res)=>{
    const prompt = req.params.prompt
    console.log(prompt)

    const openai = new OpenAI({
        apiKey: process.env.OPEN_AI_API_KEY,
    })
    try{
        const response = await openai.chat.completions.create(
            {
                model: "gpt-3.5-turbo",
                messages: [{"role": "user", "content": prompt}],
                max_tokens: 2000,
                temperature: 0
            }
        )
        console.log(response.choices[0].message.content)
        res.json(response.choices[0].message.content)

    }catch(error){
        console.log(error);
    }
});

//setup port for server
const port =3001;
app.listen(port, ()=>{
    console.log(`Server is running and listening on port ${port}`);
});