@@ -960,6 +960,9 @@ def request(
960960            if  self .custom_auth  is  not None :
961961                kwargs ["auth" ] =  self .custom_auth 
962962
963+             if  options .follow_redirects  is  not None :
964+                 kwargs ["follow_redirects" ] =  options .follow_redirects 
965+ 
963966            log .debug ("Sending HTTP Request: %s %s" , request .method , request .url )
964967
965968            response  =  None 
@@ -1068,7 +1071,14 @@ def _process_response(
10681071    ) ->  ResponseT :
10691072        origin  =  get_origin (cast_to ) or  cast_to 
10701073
1071-         if  inspect .isclass (origin ) and  issubclass (origin , BaseAPIResponse ):
1074+         if  (
1075+             inspect .isclass (origin )
1076+             and  issubclass (origin , BaseAPIResponse )
1077+             # we only want to actually return the custom BaseAPIResponse class if we're 
1078+             # returning the raw response, or if we're not streaming SSE, as if we're streaming 
1079+             # SSE then `cast_to` doesn't actively reflect the type we need to parse into 
1080+             and  (not  stream  or  bool (response .request .headers .get (RAW_RESPONSE_HEADER )))
1081+         ):
10721082            if  not  issubclass (origin , APIResponse ):
10731083                raise  TypeError (f"API Response types must subclass { APIResponse } { origin }  )
10741084
@@ -1279,6 +1289,24 @@ def __init__(self, **kwargs: Any) -> None:
12791289        super ().__init__ (** kwargs )
12801290
12811291
1292+ try :
1293+     import  httpx_aiohttp 
1294+ except  ImportError :
1295+ 
1296+     class  _DefaultAioHttpClient (httpx .AsyncClient ):
1297+         def  __init__ (self , ** _kwargs : Any ) ->  None :
1298+             raise  RuntimeError ("To use the aiohttp client you must have installed the package with the `aiohttp` extra" )
1299+ else :
1300+ 
1301+     class  _DefaultAioHttpClient (httpx_aiohttp .HttpxAiohttpClient ):  # type: ignore 
1302+         def  __init__ (self , ** kwargs : Any ) ->  None :
1303+             kwargs .setdefault ("timeout" , DEFAULT_TIMEOUT )
1304+             kwargs .setdefault ("limits" , DEFAULT_CONNECTION_LIMITS )
1305+             kwargs .setdefault ("follow_redirects" , True )
1306+ 
1307+             super ().__init__ (** kwargs )
1308+ 
1309+ 
12821310if  TYPE_CHECKING :
12831311    DefaultAsyncHttpxClient  =  httpx .AsyncClient 
12841312    """An alias to `httpx.AsyncClient` that provides the same defaults that this SDK 
@@ -1287,8 +1315,12 @@ def __init__(self, **kwargs: Any) -> None:
12871315    This is useful because overriding the `http_client` with your own instance of 
12881316    `httpx.AsyncClient` will result in httpx's defaults being used, not ours. 
12891317    """ 
1318+ 
1319+     DefaultAioHttpClient  =  httpx .AsyncClient 
1320+     """An alias to `httpx.AsyncClient` that changes the default HTTP transport to `aiohttp`.""" 
12901321else :
12911322    DefaultAsyncHttpxClient  =  _DefaultAsyncHttpxClient 
1323+     DefaultAioHttpClient  =  _DefaultAioHttpClient 
12921324
12931325
12941326class  AsyncHttpxClientWrapper (DefaultAsyncHttpxClient ):
@@ -1460,6 +1492,9 @@ async def request(
14601492            if  self .custom_auth  is  not None :
14611493                kwargs ["auth" ] =  self .custom_auth 
14621494
1495+             if  options .follow_redirects  is  not None :
1496+                 kwargs ["follow_redirects" ] =  options .follow_redirects 
1497+ 
14631498            log .debug ("Sending HTTP Request: %s %s" , request .method , request .url )
14641499
14651500            response  =  None 
@@ -1568,7 +1603,14 @@ async def _process_response(
15681603    ) ->  ResponseT :
15691604        origin  =  get_origin (cast_to ) or  cast_to 
15701605
1571-         if  inspect .isclass (origin ) and  issubclass (origin , BaseAPIResponse ):
1606+         if  (
1607+             inspect .isclass (origin )
1608+             and  issubclass (origin , BaseAPIResponse )
1609+             # we only want to actually return the custom BaseAPIResponse class if we're 
1610+             # returning the raw response, or if we're not streaming SSE, as if we're streaming 
1611+             # SSE then `cast_to` doesn't actively reflect the type we need to parse into 
1612+             and  (not  stream  or  bool (response .request .headers .get (RAW_RESPONSE_HEADER )))
1613+         ):
15721614            if  not  issubclass (origin , AsyncAPIResponse ):
15731615                raise  TypeError (f"API Response types must subclass { AsyncAPIResponse } { origin }  )
15741616
0 commit comments