{"msg":"Missing credentials","status":"error"}

I have written a script to implement a generate art button on my website using html and Javascript,

upon testing I am getting the error in the headline. I have the proper API key in the code.

Any ideas?

Can you share a code snippet of how you are doing this (with sensitive info omitted)?

<script>
  // JavaScript code to generate AI art when the button is clicked
  document.getElementById("generate-ai-art-button").addEventListener("click", function() {
    // Use DALL-E API to generate the AI art
    const url = 'https://api.openai.com/v1/images/generations';
    const prompt = 'generate a painting of a landscape';
    const apiKey = 'YOUR_API_KEY';

    const options = {
        method: 'POST',
        headers: {
            'Content-Type': 'application/json',
            'Authorization': `Bearer ${apiKey}`
        },
        body: JSON.stringify({prompt: prompt, model: 'image-alpha-001'})
    };

    fetch(url, options)
        .then(response => response.json())
        .then(data => {
            const imageUrl = data.data[0].url;
            // insert the image into the container
            document.getElementById("ai-art-container").innerHTML = `<img src='${imageUrl}'/>`;
        })
        .catch(error => {
            console.log(error);
        });
  });
</script>