2121)
2222from ...._types import NOT_GIVEN , Query , Headers , NotGiven
2323from ...._utils import (
24+ is_azure_client ,
2425 maybe_transform ,
2526 strip_not_given ,
2627 async_maybe_transform ,
28+ is_async_azure_client ,
2729)
2830from ...._compat import cached_property
2931from ...._models import construct_type_unchecked
@@ -319,11 +321,16 @@ async def __aenter__(self) -> AsyncRealtimeConnection:
319321 except ImportError as exc :
320322 raise OpenAIError ("You need to install `openai[realtime]` to use this method" ) from exc
321323
324+ extra_query = self .__extra_query
325+ auth_headers = self .__client .auth_headers
326+ if is_async_azure_client (self .__client ):
327+ extra_query , auth_headers = await self .__client ._configure_realtime (self .__model , extra_query )
328+
322329 url = self ._prepare_url ().copy_with (
323330 params = {
324331 ** self .__client .base_url .params ,
325332 "model" : self .__model ,
326- ** self . __extra_query ,
333+ ** extra_query ,
327334 },
328335 )
329336 log .debug ("Connecting to %s" , url )
@@ -336,7 +343,7 @@ async def __aenter__(self) -> AsyncRealtimeConnection:
336343 user_agent_header = self .__client .user_agent ,
337344 additional_headers = _merge_mappings (
338345 {
339- ** self . __client . auth_headers ,
346+ ** auth_headers ,
340347 "OpenAI-Beta" : "realtime=v1" ,
341348 },
342349 self .__extra_headers ,
@@ -496,11 +503,16 @@ def __enter__(self) -> RealtimeConnection:
496503 except ImportError as exc :
497504 raise OpenAIError ("You need to install `openai[realtime]` to use this method" ) from exc
498505
506+ extra_query = self .__extra_query
507+ auth_headers = self .__client .auth_headers
508+ if is_azure_client (self .__client ):
509+ extra_query , auth_headers = self .__client ._configure_realtime (self .__model , extra_query )
510+
499511 url = self ._prepare_url ().copy_with (
500512 params = {
501513 ** self .__client .base_url .params ,
502514 "model" : self .__model ,
503- ** self . __extra_query ,
515+ ** extra_query ,
504516 },
505517 )
506518 log .debug ("Connecting to %s" , url )
@@ -513,7 +525,7 @@ def __enter__(self) -> RealtimeConnection:
513525 user_agent_header = self .__client .user_agent ,
514526 additional_headers = _merge_mappings (
515527 {
516- ** self . __client . auth_headers ,
528+ ** auth_headers ,
517529 "OpenAI-Beta" : "realtime=v1" ,
518530 },
519531 self .__extra_headers ,
0 commit comments