66
77from __future__ import annotations
88
9- from typing import TYPE_CHECKING , Any
9+ from collections .abc import Iterable
10+ from typing import TYPE_CHECKING , TypedDict
1011
11- import httpx
12+ from httpx import (
13+ AsyncHTTPTransport as _AsyncHTTPTransport ,
14+ HTTPTransport as _HTTPTransport ,
15+ )
16+ from typing_extensions import NotRequired , Unpack
1217
1318
1419if TYPE_CHECKING :
20+ from ssl import SSLContext
21+
22+ from httpx import Limits , Request , Response
23+ from httpx ._types import CertTypes , ProxyTypes
24+
1525 from crewai .llms .hooks .base import BaseInterceptor
1626
1727
18- class HTTPTransport (httpx .HTTPTransport ):
28+ class HTTPTransportKwargs (TypedDict ):
29+ """Typed dictionary for httpx.HTTPTransport initialization parameters.
30+
31+ These parameters configure the underlying HTTP transport behavior including
32+ SSL verification, proxies, connection limits, and low-level socket options.
33+ """
34+
35+ verify : bool | str | SSLContext
36+ cert : NotRequired [CertTypes | None ]
37+ trust_env : bool
38+ http1 : bool
39+ http2 : bool
40+ limits : Limits
41+ proxy : NotRequired [ProxyTypes | None ]
42+ uds : NotRequired [str | None ]
43+ local_address : NotRequired [str | None ]
44+ retries : int
45+ socket_options : NotRequired [
46+ Iterable [
47+ tuple [int , int , int ]
48+ | tuple [int , int , bytes | bytearray ]
49+ | tuple [int , int , None , int ]
50+ ]
51+ | None
52+ ]
53+
54+
55+ class HTTPTransport (_HTTPTransport ):
1956 """HTTP transport that uses an interceptor for request/response modification.
2057
2158 This transport is used internally when a user provides a BaseInterceptor.
@@ -25,19 +62,19 @@ class HTTPTransport(httpx.HTTPTransport):
2562
2663 def __init__ (
2764 self ,
28- interceptor : BaseInterceptor [httpx . Request , httpx . Response ],
29- ** kwargs : Any ,
65+ interceptor : BaseInterceptor [Request , Response ],
66+ ** kwargs : Unpack [ HTTPTransportKwargs ] ,
3067 ) -> None :
3168 """Initialize transport with interceptor.
3269
3370 Args:
3471 interceptor: HTTP interceptor for modifying raw request/response objects.
35- **kwargs: Additional arguments passed to httpx.HTTPTransport .
72+ **kwargs: HTTPTransport configuration parameters (verify, cert, proxy, etc.) .
3673 """
3774 super ().__init__ (** kwargs )
3875 self .interceptor = interceptor
3976
40- def handle_request (self , request : httpx . Request ) -> httpx . Response :
77+ def handle_request (self , request : Request ) -> Response :
4178 """Handle request with interception.
4279
4380 Args:
@@ -51,7 +88,7 @@ def handle_request(self, request: httpx.Request) -> httpx.Response:
5188 return self .interceptor .on_inbound (response )
5289
5390
54- class AsyncHTTPransport ( httpx . AsyncHTTPTransport ):
91+ class AsyncHTTPTransport ( _AsyncHTTPTransport ):
5592 """Async HTTP transport that uses an interceptor for request/response modification.
5693
5794 This transport is used internally when a user provides a BaseInterceptor.
@@ -61,19 +98,19 @@ class AsyncHTTPransport(httpx.AsyncHTTPTransport):
6198
6299 def __init__ (
63100 self ,
64- interceptor : BaseInterceptor [httpx . Request , httpx . Response ],
65- ** kwargs : Any ,
101+ interceptor : BaseInterceptor [Request , Response ],
102+ ** kwargs : Unpack [ HTTPTransportKwargs ] ,
66103 ) -> None :
67104 """Initialize async transport with interceptor.
68105
69106 Args:
70107 interceptor: HTTP interceptor for modifying raw request/response objects.
71- **kwargs: Additional arguments passed to httpx.AsyncHTTPTransport .
108+ **kwargs: HTTPTransport configuration parameters (verify, cert, proxy, etc.) .
72109 """
73110 super ().__init__ (** kwargs )
74111 self .interceptor = interceptor
75112
76- async def handle_async_request (self , request : httpx . Request ) -> httpx . Response :
113+ async def handle_async_request (self , request : Request ) -> Response :
77114 """Handle async request with interception.
78115
79116 Args:
0 commit comments