ChatGPT Course – Use The OpenAI API to Code 5 Projects

I’m watching Ania’s chatgpt YT video and I can’t seem to get the code working. I’m fairly certain I have the correct code. But the response variable in the fetchData function says " response’ is declared but it’s value is never read"
Watch 16 min into her video the code how it looks like on her end. Below is my code. Her code worked on the video but mine did not. What did I miss here? (not including my api key below.)

async function fetchData(){
    const response = await fetch("http://api.openai.com/v1/completions",{
        method: "POST",
    headers:{
        Authorization: `Bearer ${API_KEY}`,
        "Content-Type": "application/json"
    },
    body: JSON.stringify({
        model: "text-davinci-003", 
        prompt: "hello, how are you today?", 
        max_tokens: 7,
    })
    } )
    
};

const data = await response.json();
console.log(data);

fetchData();

You’re accessing response outside of your fetchData function.

1 Like

OMG. Thank you. I see it now. Much appreciate your help @nhcarrigan

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.