From b2d046694a360805f3add55a109dd510798520da Mon Sep 17 00:00:00 2001 From: Robot Date: Thu, 26 Feb 2026 17:33:56 +0000 Subject: [PATCH] fix: fallback to messages.create when proxy returns 404 on models endpoint; add version to manifest --- .../anthropic_custom/config_flow.py | 16 +++++++++++++++- custom_components/anthropic_custom/manifest.json | 16 ++++++++++++---- 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/custom_components/anthropic_custom/config_flow.py b/custom_components/anthropic_custom/config_flow.py index c754da6..e4a6b56 100644 --- a/custom_components/anthropic_custom/config_flow.py +++ b/custom_components/anthropic_custom/config_flow.py @@ -102,7 +102,21 @@ async def validate_input(hass: HomeAssistant, data: dict[str, Any]) -> None: base_url=data.get(CONF_BASE_URL) or None, http_client=get_async_client(hass) ) - await client.models.list(timeout=10.0) + # Use a minimal messages call instead of models.list so that + # proxies which don't implement GET /v1/models still validate correctly. + try: + await client.models.list(timeout=10.0) + except anthropic.APIStatusError as exc: + 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", + max_tokens=1, + messages=[{"role": "user", "content": "hi"}], + timeout=10.0, + ) + else: + raise async def get_model_list(client: anthropic.AsyncAnthropic) -> list[SelectOptionDict]: diff --git a/custom_components/anthropic_custom/manifest.json b/custom_components/anthropic_custom/manifest.json index c1da10a..ca21090 100644 --- a/custom_components/anthropic_custom/manifest.json +++ b/custom_components/anthropic_custom/manifest.json @@ -1,13 +1,21 @@ { "domain": "anthropic_custom", "name": "Anthropic (Custom Base URL)", - "after_dependencies": ["assist_pipeline", "intent"], + "after_dependencies": [ + "assist_pipeline", + "intent" + ], "codeowners": [], "config_flow": true, - "dependencies": ["conversation"], + "dependencies": [ + "conversation" + ], "documentation": "https://github.com/robot/ha-anthropic-custom", "integration_type": "service", "iot_class": "cloud_polling", "quality_scale": "bronze", - "requirements": ["anthropic==0.83.0"] -} + "requirements": [ + "anthropic==0.83.0" + ], + "version": "1.0.0" +} \ No newline at end of file