diff --git a/custom_components/ha_text_ai/coordinator.py b/custom_components/ha_text_ai/coordinator.py index 4b8e659..de3549e 100644 --- a/custom_components/ha_text_ai/coordinator.py +++ b/custom_components/ha_text_ai/coordinator.py @@ -103,15 +103,22 @@ class HATextAICoordinator(DataUpdateCoordinator): api_key=self.api_key ) else: # OpenAI + transport = httpx.AsyncHTTPTransport(retries=3) + limits = httpx.Limits(max_keepalive_connections=5, max_connections=10) + async_client = httpx.AsyncClient( base_url=self.endpoint, - timeout=httpx.Timeout(30.0) + timeout=httpx.Timeout(30.0), + transport=transport, + limits=limits, + follow_redirects=True ) self.client = AsyncOpenAI( api_key=self.api_key, base_url=self.endpoint, - http_client=async_client + http_client=async_client, + max_retries=3 ) except Exception as e: _LOGGER.error("Error initializing API client: %s", str(e))