Trying to make JS Mastery T-Shirt Project and Trying to enter prompt which is then supposed to use the DALLE API and generate an image for me, but I keep getting an error.
All the code is below:
import express, { response } from 'express';
import * as dotenv from 'dotenv';
import OpenAI from 'openai';
dotenv.config();
const router = express.Router();
const openai = new OpenAI({
apiKey: process.env.OPENAI_API_KEY // This is also the default, can be omitted
});
router.route('/').get((req, res) => {
res.status(200).json({ message: "Hello from DALL.E 2.0" })
})
router.route('/').post(async (req, res) => {
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;
This is a screenshot of the error:
enter image description here
New contributor
seed9 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.