From 3dd1c88df9fb7e698582a726aa433219c5bd6342 Mon Sep 17 00:00:00 2001 From: Robot Date: Thu, 26 Feb 2026 17:38:20 +0000 Subject: [PATCH] fix: use claude-3-haiku for validation ping; guard error.get() against string body from proxies --- custom_components/anthropic_custom/config_flow.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/custom_components/anthropic_custom/config_flow.py b/custom_components/anthropic_custom/config_flow.py index 349f0e0..7732c2a 100644 --- a/custom_components/anthropic_custom/config_flow.py +++ b/custom_components/anthropic_custom/config_flow.py @@ -110,7 +110,7 @@ async def validate_input(hass: HomeAssistant, data: dict[str, Any]) -> None: if exc.status_code == 404: # Proxy does not support models endpoint — validate via a tiny messages call await client.messages.create( - model="claude-haiku-4-5", + model="claude-3-haiku-20240307", max_tokens=1, messages=[{"role": "user", "content": "hi"}], timeout=10.0, @@ -184,12 +184,13 @@ class AnthropicConfigFlow(ConfigFlow, domain=DOMAIN): errors["base"] = "cannot_connect" except anthropic.APIStatusError as e: errors["base"] = "unknown" - if ( - isinstance(e.body, dict) - and (error := e.body.get("error")) - and error.get("type") == "authentication_error" - ): - errors["base"] = "authentication_error" + try: + body = e.body if isinstance(e.body, dict) else {} + error = body.get("error") + if isinstance(error, dict) and error.get("type") == "authentication_error": + errors["base"] = "authentication_error" + except Exception: + pass except Exception: _LOGGER.exception("Unexpected exception") errors["base"] = "unknown"