diff --git a/portkey_ai/api_resources/base_client.py b/portkey_ai/api_resources/base_client.py index 19d370e8..c2582b42 100644 --- a/portkey_ai/api_resources/base_client.py +++ b/portkey_ai/api_resources/base_client.py @@ -20,7 +20,11 @@ import platform from portkey_ai.api_resources.apis.create_headers import createHeaders -from .global_constants import PORTKEY_HEADER_PREFIX, DEFAULT_CONNECTION_LIMITS +from .global_constants import ( + DEFAULT_TIMEOUT_CONFIG, + PORTKEY_HEADER_PREFIX, + DEFAULT_CONNECTION_LIMITS, +) from .utils import remove_empty_values, Options, set_base_url from .exceptions import ( APIStatusError, @@ -178,12 +182,19 @@ def __init__( ) self.allHeaders = self._build_headers(Options.construct()) + + if self.request_timeout: + timeout = httpx.Timeout(self.request_timeout, connect=5.0) + else: + timeout = DEFAULT_TIMEOUT_CONFIG + self._client = http_client or httpx.Client( base_url=self.base_url, headers={ "Accept": "application/json", }, limits=DEFAULT_CONNECTION_LIMITS, + timeout=timeout, ) self.response_headers: httpx.Headers | None = None @@ -891,12 +902,19 @@ def __init__( ) self.allHeaders = self._build_headers(Options.construct()) + + if self.request_timeout: + timeout = httpx.Timeout(self.request_timeout, connect=5.0) + else: + timeout = DEFAULT_TIMEOUT_CONFIG + self._client = http_client or AsyncHttpxClientWrapper( base_url=self.base_url, headers={ "Accept": "application/json", }, limits=DEFAULT_CONNECTION_LIMITS, + timeout=timeout, ) self.response_headers: httpx.Headers | None = None diff --git a/portkey_ai/api_resources/global_constants.py b/portkey_ai/api_resources/global_constants.py index c9e95f60..a9bf9005 100644 --- a/portkey_ai/api_resources/global_constants.py +++ b/portkey_ai/api_resources/global_constants.py @@ -49,4 +49,5 @@ DEFAULT_CONNECTION_LIMITS = httpx.Limits( max_connections=1000, max_keepalive_connections=100 ) +DEFAULT_TIMEOUT_CONFIG = httpx.Timeout(timeout=600, connect=5.0) AUDIO_FILE_DURATION_HEADER = "x-portkey-audio-file-duration"