@@ -319,11 +319,26 @@ async def __aenter__(self) -> AsyncRealtimeConnection:
319319 except ImportError as exc :
320320 raise OpenAIError ("You need to install `openai[realtime]` to use this method" ) from exc
321321
322+ auth_headers = self .__client .auth_headers
323+ extra_query = self .__extra_query
324+ if self .__client .__class__ .__name__ == "AsyncAzureOpenAI" :
325+ extra_query = {
326+ ** self .__extra_query ,
327+ "api-version" : self .__client ._api_version ,
328+ "deployment" : self .__client ._azure_deployment or self .__model
329+ }
330+ if self .__client .api_key != "<missing API key>" :
331+ auth_headers = {"api-key" : self .__client .api_key }
332+ else :
333+ token = await self .__client ._get_azure_ad_token ()
334+ if token :
335+ auth_headers = {"Authorization" : f"Bearer { token } " }
336+
322337 url = self ._prepare_url ().copy_with (
323338 params = {
324339 ** self .__client .base_url .params ,
325340 "model" : self .__model ,
326- ** self . __extra_query ,
341+ ** extra_query ,
327342 },
328343 )
329344 log .debug ("Connecting to %s" , url )
@@ -336,7 +351,7 @@ async def __aenter__(self) -> AsyncRealtimeConnection:
336351 user_agent_header = self .__client .user_agent ,
337352 additional_headers = _merge_mappings (
338353 {
339- ** self . __client . auth_headers ,
354+ ** auth_headers ,
340355 "OpenAI-Beta" : "realtime=v1" ,
341356 },
342357 self .__extra_headers ,
@@ -496,11 +511,26 @@ def __enter__(self) -> RealtimeConnection:
496511 except ImportError as exc :
497512 raise OpenAIError ("You need to install `openai[realtime]` to use this method" ) from exc
498513
514+ auth_headers = self .__client .auth_headers
515+ extra_query = self .__extra_query
516+ if self .__client .__class__ .__name__ == "AzureOpenAI" :
517+ extra_query = {
518+ ** self .__extra_query ,
519+ "api-version" : self .__client ._api_version ,
520+ "deployment" : self .__client ._azure_deployment or self .__model
521+ }
522+ if self .__client .api_key != "<missing API key>" :
523+ auth_headers = {"api-key" : self .__client .api_key }
524+ else :
525+ token = self .__client ._get_azure_ad_token ()
526+ if token :
527+ auth_headers = {"Authorization" : f"Bearer { token } " }
528+
499529 url = self ._prepare_url ().copy_with (
500530 params = {
501531 ** self .__client .base_url .params ,
502532 "model" : self .__model ,
503- ** self . __extra_query ,
533+ ** extra_query ,
504534 },
505535 )
506536 log .debug ("Connecting to %s" , url )
@@ -513,7 +543,7 @@ def __enter__(self) -> RealtimeConnection:
513543 user_agent_header = self .__client .user_agent ,
514544 additional_headers = _merge_mappings (
515545 {
516- ** self . __client . auth_headers ,
546+ ** auth_headers ,
517547 "OpenAI-Beta" : "realtime=v1" ,
518548 },
519549 self .__extra_headers ,
0 commit comments