fix: use claude-3-haiku for validation ping; guard error.get() against string body from proxies
This commit is contained in:
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:
|
if exc.status_code == 404:
|
||||||
# Proxy does not support models endpoint — validate via a tiny messages call
|
# Proxy does not support models endpoint — validate via a tiny messages call
|
||||||
await client.messages.create(
|
await client.messages.create(
|
||||||
model="claude-haiku-4-5",
|
model="claude-3-haiku-20240307",
|
||||||
max_tokens=1,
|
max_tokens=1,
|
||||||
messages=[{"role": "user", "content": "hi"}],
|
messages=[{"role": "user", "content": "hi"}],
|
||||||
timeout=10.0,
|
timeout=10.0,
|
||||||
@@ -184,12 +184,13 @@ class AnthropicConfigFlow(ConfigFlow, domain=DOMAIN):
|
|||||||
errors["base"] = "cannot_connect"
|
errors["base"] = "cannot_connect"
|
||||||
except anthropic.APIStatusError as e:
|
except anthropic.APIStatusError as e:
|
||||||
errors["base"] = "unknown"
|
errors["base"] = "unknown"
|
||||||
if (
|
try:
|
||||||
isinstance(e.body, dict)
|
body = e.body if isinstance(e.body, dict) else {}
|
||||||
and (error := e.body.get("error"))
|
error = body.get("error")
|
||||||
and error.get("type") == "authentication_error"
|
if isinstance(error, dict) and error.get("type") == "authentication_error":
|
||||||
):
|
errors["base"] = "authentication_error"
|
||||||
errors["base"] = "authentication_error"
|
except Exception:
|
||||||
|
pass
|
||||||
except Exception:
|
except Exception:
|
||||||
_LOGGER.exception("Unexpected exception")
|
_LOGGER.exception("Unexpected exception")
|
||||||
errors["base"] = "unknown"
|
errors["base"] = "unknown"
|
||||||
|
|||||||
Reference in new issue
Block a user