diff --git a/custom_components/anthropic_custom/__init__.py b/custom_components/anthropic_custom/__init__.py index ac2c001..aeac9b4 100644 --- a/custom_components/anthropic_custom/__init__.py +++ b/custom_components/anthropic_custom/__init__.py @@ -49,6 +49,22 @@ async def async_setup_entry(hass: HomeAssistant, entry: AnthropicConfigEntry) -> await client.models.list(timeout=10.0) except anthropic.AuthenticationError as err: raise ConfigEntryAuthFailed(err) from err + except anthropic.APIStatusError as err: + if err.status_code == 404: + # Proxy doesn't support models endpoint — do a minimal ping instead + try: + await client.messages.create( + model=entry.data.get(CONF_CHAT_MODEL) or "claude-3-haiku-20240307", + max_tokens=1, + messages=[{"role": "user", "content": "hi"}], + timeout=10.0, + ) + except anthropic.AuthenticationError as auth_err: + raise ConfigEntryAuthFailed(auth_err) from auth_err + except anthropic.AnthropicError as ping_err: + raise ConfigEntryNotReady(ping_err) from ping_err + else: + raise ConfigEntryNotReady(err) from err except anthropic.AnthropicError as err: raise ConfigEntryNotReady(err) from err