I’m getting a 500 erroron the browser and a Error: Request failed with status code 400 on my node terminal. Able to console.log api key
import express from 'express';
import * as dotenv from 'dotenv';
import { Configuration, OpenAIApi } from "openai";
dotenv.config();
const router = express.Router();
const config = new Configuration({
apiKey: process.env.OPENAI_API_KEY,
});
const openai = new OpenAIApi(config);
console.log('API Key:', process.env.OPENAI_API_KEY);
router.route('/').get((req, res) => {
res.status(200).json({ message: 'Hello from DALL.E ROUTES!!!' });
});
router.route('/').post(async (req, res) => {
console.log('Received POST request:', req.body);
try {
const {prompt} = req.body;
const response = await openai.createImage({
prompt,
n: 1,
size: '1024x1024',
response_format: 'b64_json',
});
const image = response.data.data[0].b64_json;
res.status(200).json({ photo: image });
} catch (error) {
console.error(error);
res.status(500).json({ message: 'Something went wrong' });
}
});
export default router;
I tired passing different headers and also using a different configuration for openai.