@@ -26,7 +26,11 @@ export class OpenAIRealtimeWebSocket extends OpenAIRealtimeEmitter {
2626 props : {
2727 model : string ;
2828 dangerouslyAllowBrowser ?: boolean ;
29- onUrl ?: ( url : URL ) => void ;
29+ /**
30+ * Callback to mutate the URL, needed for Azure.
31+ * @internal
32+ */
33+ onURL ?: ( url : URL ) => void ;
3034 } ,
3135 client ?: Pick < OpenAI , 'apiKey' | 'baseURL' > ,
3236 ) {
@@ -46,14 +50,12 @@ export class OpenAIRealtimeWebSocket extends OpenAIRealtimeEmitter {
4650 client ??= new OpenAI ( { dangerouslyAllowBrowser } ) ;
4751
4852 this . url = buildRealtimeURL ( client , props . model ) ;
49- props . onUrl ?.( this . url ) ;
50-
51- const azureCheck = isAzure ( client ) ;
53+ props . onURL ?.( this . url ) ;
5254
5355 // @ts -ignore
5456 this . socket = new WebSocket ( this . url , [
5557 'realtime' ,
56- ...( azureCheck ? [ ] : [ `openai-insecure-api-key.${ client . apiKey } ` ] ) ,
58+ ...( isAzure ( client ) ? [ ] : [ `openai-insecure-api-key.${ client . apiKey } ` ] ) ,
5759 'openai-beta.realtime-v1' ,
5860 ] ) ;
5961
@@ -83,7 +85,7 @@ export class OpenAIRealtimeWebSocket extends OpenAIRealtimeEmitter {
8385 this . _onError ( null , event . message , null ) ;
8486 } ) ;
8587
86- if ( azureCheck ) {
88+ if ( isAzure ( client ) ) {
8789 if ( this . url . searchParams . get ( 'Authorization' ) !== null ) {
8890 this . url . searchParams . set ( 'Authorization' , '<REDACTED>' ) ;
8991 } else {
@@ -97,7 +99,7 @@ export class OpenAIRealtimeWebSocket extends OpenAIRealtimeEmitter {
9799 options : { deploymentName ?: string ; dangerouslyAllowBrowser ?: boolean } = { } ,
98100 ) : Promise < OpenAIRealtimeWebSocket > {
99101 const token = await client . _getAzureADToken ( ) ;
100- function onUrl ( url : URL ) {
102+ function onURL ( url : URL ) {
101103 if ( client . apiKey !== '<Missing Key>' ) {
102104 url . searchParams . set ( 'api-key' , client . apiKey ) ;
103105 } else {
@@ -114,7 +116,11 @@ export class OpenAIRealtimeWebSocket extends OpenAIRealtimeEmitter {
114116 }
115117 const { dangerouslyAllowBrowser } = options ;
116118 return new OpenAIRealtimeWebSocket (
117- { model : deploymentName , onUrl, ...( dangerouslyAllowBrowser ? { dangerouslyAllowBrowser } : { } ) } ,
119+ {
120+ model : deploymentName ,
121+ onURL,
122+ ...( dangerouslyAllowBrowser ? { dangerouslyAllowBrowser } : { } ) ,
123+ } ,
118124 client ,
119125 ) ;
120126 }
0 commit comments