mail55
October 8, 2024, 2:15am
1
Hello
I am trying connect to RealTime Api with following pure javascript code
const API_KEY = 'my key';
const MODEL = 'gpt-4o-realtime-preview-2024-10-01';
const WS_BASE_URL = 'wss://api.openai.com/v1/realtime';
socket = new WebSocket(wsUrl);
But I getting the following error:
“Missing bearer or basic authentication in header”
Key is valid
2 Likes
Welcome!
I checked the API reference docs real quick and found this which might help you?
The Realtime API is a stateful , event-based API that communicates over a WebSocket. The WebSocket connection requires the following parameters:
URL: wss://api.openai.com/v1/realtime
Query Parameters: ?model=gpt-4o-realtime-preview-2024-10-01
Headers:
Authorization: Bearer YOUR_API_KEY
OpenAI-Beta: realtime=v1
Below is a simple example using the popular ws
library in Node.js to establish a socket connection, send a message from the client, and receive a response from the server. It requires that a valid OPENAI_API_KEY
is exported in the system environment.
Sounds like your super-basic code is not sending the required headers.
The docs are really useful and may help?
https://platform.openai.com/docs/guides/realtime
Good luck and happy coding!
1 Like
mail55
October 8, 2024, 4:32am
3
Sorry, I missed th line - the full code looks like so
const API_KEY = 'my key';
const MODEL = 'gpt-4o-realtime-preview-2024-10-01';
const WS_BASE_URL = 'wss://api.openai.com/v1/realtime';
const wsUrl = ${WS_BASE_URL}?model=${encodeURIComponent(MODEL)}&Authorization=Bearer ${encodeURIComponent(API_KEY)}&OpenAI-Beta=realtime=v1
;
socket = new WebSocket(wsUrl);
Maybe I have a mistake in wsUrl?
1 Like
mail55
October 8, 2024, 6:13pm
4
Does anybody has solution?
1 Like
I have the similar problem.
There is my request:
GET /v1/realtime?model=gpt-4o-realtime-preview HTTP/1.1
Authorization: Bearer s************A
OpenAI-Beta: realtime=v1
Sec-WebSocket-Version: 13
Sec-WebSocket-Key: 1731060959581
Upgrade: websocket
Connection: Upgrade
Server responds 400 Bad request without any additional information.
1 Like