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"