hello! i made a super simple server side web app for a larger project and my implementation depends on the DALL-E API. Generated a key, dropped that in my .env, used Node.js and Heroku to run the server. The server works fine but my code is failing to access the API itself. Anyone know how to troubleshoot? I'm new to basically all of this. Here is my server.js code, which is calling the API. ```const express = require('express');
const cors = require('cors');
const axios = require('axios');
const dotenv = require('dotenv');
dotenv.config();
const app = express();
app.use(cors());
app.use(express.json());
app.use(express.static('public'));
app.post('/generate-image', async (req, res) => {
const dreamDescription = req.body.dreamDescription;
const response = await callDalleAPI(dreamDescription);
res.send(response.data);
});
async function callDalleAPI(prompt) {
const apiEndpoint = 'https://api.openai.com/v1/images/generations';
const headers = {
'Content-Type': 'application/json',
'Authorization': Bearer ${process.env.DALLE_API_KEY},
};
const body = {
model: 'image-alpha-001',
prompt: prompt,
num_images: 1,
size: '1024x1024',
response_format: 'url',
};
try {
const response = await axios.post(apiEndpoint, body, { headers });
return response.data;
} catch (error) {
console.error('Error calling DALL-E API:', error.response ? error.response.data : error);
if (error.response) {
console.error('Error status:', error.response.status);
console.error('Error headers:', error.response.headers);
}
return { error: 'Failed to generate image' };
}
}
const port = process.env.PORT || 3000;
app.listen(port, () => {
console.log(Server running at http://localhost:${port});
});