From a1adbda3c335c0d2e2f95d16bb40eb7145e20f1a Mon Sep 17 00:00:00 2001 From: csgulati09 Date: Mon, 9 Jun 2025 20:12:34 +0530 Subject: [PATCH 1/2] feat: default timeout set to 5 mins --- portkey_ai/api_resources/base_client.py | 8 +++++++- portkey_ai/api_resources/global_constants.py | 1 + 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/portkey_ai/api_resources/base_client.py b/portkey_ai/api_resources/base_client.py index 19d370e8..c5680cb4 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, @@ -184,6 +188,7 @@ def __init__( "Accept": "application/json", }, limits=DEFAULT_CONNECTION_LIMITS, + timeout=DEFAULT_TIMEOUT_CONFIG, ) self.response_headers: httpx.Headers | None = None @@ -897,6 +902,7 @@ def __init__( "Accept": "application/json", }, limits=DEFAULT_CONNECTION_LIMITS, + timeout=DEFAULT_TIMEOUT_CONFIG, ) 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" From 0d32532975212cc00fd270d985c1848ede84e9d4 Mon Sep 17 00:00:00 2001 From: csgulati09 Date: Tue, 10 Jun 2025 17:02:48 +0530 Subject: [PATCH 2/2] feat: checking user passed timeout value --- portkey_ai/api_resources/base_client.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/portkey_ai/api_resources/base_client.py b/portkey_ai/api_resources/base_client.py index c5680cb4..c2582b42 100644 --- a/portkey_ai/api_resources/base_client.py +++ b/portkey_ai/api_resources/base_client.py @@ -182,13 +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=DEFAULT_TIMEOUT_CONFIG, + timeout=timeout, ) self.response_headers: httpx.Headers | None = None @@ -896,13 +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=DEFAULT_TIMEOUT_CONFIG, + timeout=timeout, ) self.response_headers: httpx.Headers | None = None