No access: HTTP Authentication failed; no valid credentials available


I get this error message:

       WebSocket connection to 'wss://' failed: HTTP Authentication failed; no valid credentials available

with that code:

var socket;

function startStream() {
    var prompt = document.getElementById("prompt").value;
    var apiKey = "xxxxxxxxxxxxxx";

    socket = new WebSocket("wss://" + encodeURIComponent(prompt) + "&max_tokens=2048&stop=%5Cn&temperature=0");
    socket.onopen = function() {
    socket.onmessage = function(event) {
        var response = JSON.parse(;
        document.getElementById("response").innerHTML = response.text;
    socket.onclose = function() {
        console.log("WebSocket closed");

function saveResponse(response) {
    var xhttp = new XMLHttpRequest();"POST", "save_response.php", true);

I checked the apiKey twice. The key is correct. Can you give me any hints what I am doing wrong, please?

Thank you, Bernd

Why are you using a websocket, and where is your authorization/bearer header ?

Simple example

Thank you. I just asked chatGPT for the best way to do a real time stream in JS and I got the code, but it does not work as expected. Thank you for the hint with the authorization/bearer header. I will look at this.