I am fairly new to API's and I'm trying to create a small web-app utilizing the Davinci text model.
I feel like I've done every step right when setting up the API, but I get an error that says:
{
"error": {
"message": "You didn't provide an API key. You need to provide your API key in an Authorization header using Bearer auth (i.e. Authorization: Bearer YOUR_KEY), or as the password field (with blank username) if you're accessing the API from your browser and are prompted for a username and password. You can obtain an API key from https://beta.openai.com.",
"type": "invalid_request_error",
"param": null,
"code": null
}
}
Here is the function, I have set up for it:
const [input, setInput] = useState("");
async function fetchAnswer() {
const res = await fetch("https://api.openai.com/v1/completions", {
method: "POST",
headers: {
"Content-Type": "applications/json",
Authorization:
"Bearer MY_API_KEY",
},
body: JSON.stringify({
model: "text-davinci-003",
prompt: "Create a lyric that rhymes with:" + input,
temperature: 1,
}),
});
const json = await res.json();
console.log(json);
}
Obviously I won't share the API key, but I can confirm that the API key I am copy and pasting into the function is correct and straight from what OpenAI provided me.
Is there something else I am missing?
It seems that you might have reached a limit, or your API key is not valid anymore due to payment settings missing in your account.
If you update that and generate a new API key, everything should work.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.