From 549ebe6c0e957765f382e10fe2f513e1ac00a818 Mon Sep 17 00:00:00 2001 From: Denis Shulyaka Date: Thu, 8 Oct 2026 12:08:18 +0300 Subject: [PATCH] Remove HTTPX compatibility casts for openai client (#184751) --- homeassistant/components/litellm/config_flow.py | 5 ++--- homeassistant/components/litellm/coordinator.py | 5 ++--- homeassistant/components/llama_cpp/api.py | 3 +-- homeassistant/components/open_router/__init__.py | 5 +---- homeassistant/components/openai_conversation/__init__.py | 4 +--- .../components/openai_conversation/config_flow.py | 7 +++---- homeassistant/components/ovhcloud_ai_endpoints/__init__.py | 5 +---- 7 files changed, 11 insertions(+), 23 deletions(-) diff --git a/homeassistant/components/litellm/config_flow.py b/homeassistant/components/litellm/config_flow.py index 148c12bff88a..9e0a55725be9 100644 --- a/homeassistant/components/litellm/config_flow.py +++ b/homeassistant/components/litellm/config_flow.py @@ -1,7 +1,7 @@ """Config flow for LiteLLM integration.""" import logging -from typing import Any, cast, override +from typing import Any, override from openai import AsyncOpenAI, AuthenticationError, OpenAIError, PermissionDeniedError import probatio @@ -68,8 +68,7 @@ async def _get_models(hass: HomeAssistant, url: str, api_key: str | None) -> lis client = AsyncOpenAI( base_url=url, api_key=api_key or PLACEHOLDER_API_KEY, - # Legacy HTTPX clients are supported at runtime only. - http_client=cast(Any, get_async_client(hass)), + http_client=get_async_client(hass), ) try: return [ diff --git a/homeassistant/components/litellm/coordinator.py b/homeassistant/components/litellm/coordinator.py index 47cba3f72539..ecd856bf6fd8 100644 --- a/homeassistant/components/litellm/coordinator.py +++ b/homeassistant/components/litellm/coordinator.py @@ -1,7 +1,7 @@ """Coordinator for the LiteLLM integration.""" from datetime import timedelta -from typing import Any, cast, override +from typing import override from openai import AsyncOpenAI, AuthenticationError, OpenAIError, PermissionDeniedError @@ -40,8 +40,7 @@ class LiteLLMDataUpdateCoordinator(DataUpdateCoordinator[None]): self.client = AsyncOpenAI( base_url=config_entry.data[CONF_URL], api_key=config_entry.data.get(CONF_API_KEY) or PLACEHOLDER_API_KEY, - # Legacy HTTPX clients are supported at runtime only. - http_client=cast(Any, get_async_client(hass)), + http_client=get_async_client(hass), ) @override diff --git a/homeassistant/components/llama_cpp/api.py b/homeassistant/components/llama_cpp/api.py index 5ee7f95014b6..bf2c7bfa3959 100644 --- a/homeassistant/components/llama_cpp/api.py +++ b/homeassistant/components/llama_cpp/api.py @@ -62,8 +62,7 @@ async def async_create_client( client = openai.AsyncOpenAI( api_key=api_key, base_url=config_entry_data[CONF_BASE_URL], - # Legacy HTTPX clients are supported at runtime only. - http_client=cast(Any, get_async_client(hass)), + http_client=get_async_client(hass), ) # Cache current platform data which gets added to each request # (caching done by library) diff --git a/homeassistant/components/open_router/__init__.py b/homeassistant/components/open_router/__init__.py index e09406740745..e25ab075383d 100644 --- a/homeassistant/components/open_router/__init__.py +++ b/homeassistant/components/open_router/__init__.py @@ -1,7 +1,5 @@ """The OpenRouter integration.""" -from typing import Any, cast - from openai import AsyncOpenAI, AuthenticationError, OpenAIError from homeassistant.config_entries import ConfigEntry @@ -22,8 +20,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: OpenRouterConfigEntry) - client = AsyncOpenAI( base_url="https://openrouter.ai/api/v1", api_key=entry.data[CONF_API_KEY], - # Legacy HTTPX clients are supported at runtime only. - http_client=cast(Any, get_async_client(hass)), + http_client=get_async_client(hass), ) # Cache current platform data which gets added to each request diff --git a/homeassistant/components/openai_conversation/__init__.py b/homeassistant/components/openai_conversation/__init__.py index 5f6b19b641a1..7790c25caac8 100644 --- a/homeassistant/components/openai_conversation/__init__.py +++ b/homeassistant/components/openai_conversation/__init__.py @@ -1,7 +1,6 @@ """The OpenAI Conversation integration.""" from types import MappingProxyType -from typing import Any, cast import openai @@ -49,8 +48,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: OpenAIConfigEntry) -> bo """Set up OpenAI Conversation from a config entry.""" client = openai.AsyncOpenAI( api_key=entry.data[CONF_API_KEY], - # Legacy HTTPX clients are supported at runtime only. - http_client=cast(Any, get_async_client(hass)), + http_client=get_async_client(hass), ) # Cache current platform data which gets added to each request diff --git a/homeassistant/components/openai_conversation/config_flow.py b/homeassistant/components/openai_conversation/config_flow.py index 83cc900aa178..e21cccdf6b7a 100644 --- a/homeassistant/components/openai_conversation/config_flow.py +++ b/homeassistant/components/openai_conversation/config_flow.py @@ -3,7 +3,7 @@ from collections.abc import Mapping import json import logging -from typing import Any, cast, override +from typing import Any, override import openai import probatio @@ -118,8 +118,7 @@ async def validate_input(hass: HomeAssistant, data: dict[str, Any]) -> None: """ client = openai.AsyncOpenAI( api_key=data[CONF_API_KEY], - # Legacy HTTPX clients are supported at runtime only. - http_client=cast(Any, get_async_client(hass)), + http_client=get_async_client(hass), ) await client.models.list(timeout=10.0) @@ -669,7 +668,7 @@ class OpenAISubentryFlowHandler(ConfigSubentryFlow): if zone_home is not None: client = openai.AsyncOpenAI( api_key=self._get_entry().data[CONF_API_KEY], - http_client=cast(Any, get_async_client(self.hass)), + http_client=get_async_client(self.hass), ) location_schema = probatio.Schema( { diff --git a/homeassistant/components/ovhcloud_ai_endpoints/__init__.py b/homeassistant/components/ovhcloud_ai_endpoints/__init__.py index 83667c6c367d..54f225060787 100644 --- a/homeassistant/components/ovhcloud_ai_endpoints/__init__.py +++ b/homeassistant/components/ovhcloud_ai_endpoints/__init__.py @@ -1,7 +1,5 @@ """The OVHcloud AI Endpoints integration.""" -from typing import Any, cast - from openai import ( AsyncOpenAI, AuthenticationError, @@ -29,8 +27,7 @@ def _create_client(hass: HomeAssistant, api_key: str) -> AsyncOpenAI: return AsyncOpenAI( base_url=BASE_URL, api_key=api_key, - # Legacy HTTPX clients are supported at runtime only. - http_client=cast(Any, get_async_client(hass)), + http_client=get_async_client(hass), )