Something strange is happening to my chatbot since yesterday.
I have 1.89/10$ usage in my dashboard, i did not use my API connection to the model for hours (i was in office) and suddenly since yesterday evening i cannot send any more requests and when i try i get:
Failed to load resource: the server responded with a status of 429 ()
txtchatbot.html:763 Error:
Error while requesting to the API
I was very disapointed because error 429 usually is for too many request, which was not the case… but when i click on the link for the completion in the error, i get the following result:
{
"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://platform.openai.com/account/api-keys.",
"type": "invalid_request_error",
"param": null,
"code": null
}
}
Which is not the case as well, because the API key is correctly sent to the model via this code.
// Fuction to interrogate OpenAI model and get response (TXT chatbot - simple chat)
async function getChatGPTResponse(userInput, chatMemory = []) {
const apikey = localStorage.getItem("openaikey");
document.getElementById("apikey").value = apikey;
console.log(apikey);
if (apikey === "") {
alert("No OpenAI API Key found.");
} else {
console.log(apikey);
}
const chatContainer = document.getElementById("chathistory");
const typingIndicator = document.createElement("p");
typingIndicator.id = "typing-indicator";
typingIndicator.innerHTML =
'<img src="preloader.gif" class="preloader" alt="Loading...">'; // need to have this gif in your folder
chatContainer.appendChild(typingIndicator);
try {
const response = await fetch("https://api.openai.com/v1/chat/completions", {
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: "Bearer " + apikey
},
body: JSON.stringify({
model: "gpt-4o-mini", // new model up to Oct. 2023
messages: [...chatMemory, { role: "user", content: userInput }]
})
});
if (!response.ok) {
throw new Error("Error while requesting to the API");
}
const data = await response.json();
if (
!data.choices ||
!data.choices.length ||
!data.choices[0].message ||
!data.choices[0].message.content
) {
throw new Error("Invalid API response");
}
and the console correctly reports the api key sent:
ResponsiveVoice r1.8.3
responsivevoice.js?key=yZtZhFyg:340 isHidden: false
responsivevoice.js?key=yZtZhFyg:341 Prerender: false
txtchatbot.html:1 [DOM] Password field is not contained in a form: (More info: Create Amazing Password Forms) <input type="password" id="apikey" placeholder="Your API key" readonly>
responsivevoice.js?key=yZtZhFyg:402 Configuring
responsivevoice.js?key=yZtZhFyg:144 RV: Voice support ready
2responsivevoice.js?key=yZtZhFyg:452 Selected text **
txtchatbot.html:590
sk-ZvwHV----------(dashed for security reason)
txtchatbot.html:595
sk-ZvwHV----------(dashed for security reason)
txtchatbot.html:684
sk-ZvwHV----------(dashed for security reason)
txtchatbot.html:688
sk-ZvwHV----------(dashed for security reason)
api.openai.com/v1/chat/completions:1Failed to load resource: the server responded with a status of 429 ()
txtchatbot.html:763 Error: Error while requesting to the API
at getChatGPTResponse (txtchatbot.html:712:13)
at async sendMessage (txtchatbot.html:601:20)
getChatGPTResponse @ txtchatbot.html:763