Skip to content

Commit 390c131

Browse files
committed
update error messages
1 parent 577ebc6 commit 390c131

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

src/beta/realtime/websocket.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,13 @@ export class OpenAIRealtimeWebSocket extends OpenAIRealtimeEmitter {
5151
client ??= new OpenAI({ dangerouslyAllowBrowser });
5252

5353
if (typeof (client as any)?._options?.apiKey !== 'string') {
54-
throw new Error('Call the create method instead to construct the client');
54+
throw new Error(
55+
[
56+
'Cannot open Realtime WebSocket with a function-based apiKey.',
57+
'Use the factory so the key is resolved before connecting:',
58+
'- OpenAIRealtimeWebSocket.create(client, { model })',
59+
].join('\n'),
60+
);
5561
}
5662

5763
this.url = buildRealtimeURL(client, props.model);

src/beta/realtime/ws.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,13 @@ export class OpenAIRealtimeWS extends OpenAIRealtimeEmitter {
1414
super();
1515
client ??= new OpenAI();
1616
if (typeof (client as any)._options.apiKey !== 'string') {
17-
throw new Error('Call the create method instead to construct the client');
17+
throw new Error(
18+
[
19+
'Cannot open Realtime WebSocket with a function-based apiKey.',
20+
'Use the factory so the key is resolved before connecting:',
21+
'- OpenAIRealtimeWS.create(client, { model })',
22+
].join('\n'),
23+
);
1824
}
1925
this.url = buildRealtimeURL(client, props.model);
2026
this.socket = new WS.WebSocket(this.url, {

0 commit comments

Comments
 (0)