AI

AI Image Generator


const resultDiv = document.getElementById('result');
resultDiv.innerHTML = 'Generating image...';

try {
const response = await fetch('https://api.openai.com/v1/images/generations', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${apiKey}`,
},
body: JSON.stringify({ prompt: prompt, n: 1, size: "1024x1024" }),
});

const data = await response.json();
const imageUrl = data.data[0].url;

resultDiv.innerHTML = `Generated Image`;
} catch (error) {
console.error('Error generating image:', error);
resultDiv.innerHTML = 'Error generating image. Please try again.';
}
});

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top