fix: use claude-3-haiku for validation ping; guard error.get() against string body from proxies

This commit is contained in:
Robot committed 2026-02-26 17:38:20 +00:00
1 parent 8deb3febdb
commit 3dd1c88df9
1 file changed
+8 -7
@@ -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"