home-assistant/core · critical · HomeAssistantError
api_authentication_error
Error message
api_authentication_error
What it means
A HomeAssistantError with translation key 'api_authentication_error' raised in the conversation/entity path when the streaming messages.create call raises anthropic.AuthenticationError. Before raising, it triggers coordinator.async_request_refresh() so the coordinator independently confirms the auth failure and starts the reauth flow.
Source
Thrown at homeassistant/components/anthropic/entity.py:1223
new_messages, model_args["container"] = _convert_content(
[
content
async for content in chat_log.async_add_delta_content_stream(
self.entity_id,
AnthropicDeltaStream(
chat_log,
stream,
output_tool=structure_name or None,
),
)
]
)
cast(list[MessageParam], model_args["messages"]).extend(new_messages)
except anthropic.AuthenticationError as err:
# Trigger coordinator to confirm the auth failure
# and trigger the reauth flow.
await coordinator.async_request_refresh()
raise HomeAssistantError(
translation_domain=DOMAIN,
translation_key="api_authentication_error",
translation_placeholders={"message": err.message},
) from err
except anthropic.APIConnectionError as err:
LOGGER.info("Connection error while talking to Anthropic: %s", err)
coordinator.mark_connection_error()
raise HomeAssistantError(
translation_domain=DOMAIN,
translation_key="api_error",
translation_placeholders={"message": err.message},
) from err
except anthropic.AnthropicError as err:
# Non-connection error, mark connection as healthy
coordinator.async_set_updated_data(coordinator.data)
LOGGER.error("Error while talking to Anthropic: %s", err)
raise HomeAssistantError(
translation_domain=DOMAIN,View on GitHub (pinned to 58a3fdb3ea)
Solutions
- Complete the reauth flow that the coordinator refresh triggers, entering a current API key
- Validate the key independently via curl to the Anthropic models endpoint
- Check the Anthropic console for key status and organization membership
Defensive patterns
Strategy: try-catch
Try / catch
try:
async with client.messages.stream(**model_args) as stream:
...
except anthropic.AuthenticationError as err:
await coordinator.async_request_refresh()
raise HomeAssistantError(
translation_domain=DOMAIN,
translation_key="api_authentication_error",
translation_placeholders={"message": err.message},
) from err Prevention
- Refresh the coordinator before raising so reauth starts from one code path
- Rotate keys deliberately: update Home Assistant at the same time the key changes
When it happens
Trigger: Streaming a chat completion with an invalid API key (401): key revoked, replaced, or entered incorrectly; also possible after organization removal. The placeholder 'message' carries the API's error text.
Common situations: API key rotated in the Anthropic console after initial setup; billing lapse causing key deactivation; key pasted with whitespace/newline.
Understand the failure class
- Authentication and authorization failures — expired tokens, bad credentials, and missing scopes.
Related errors
- api_authentication_error
- invalid_api_key
- Unable to deactivate the owner
- System generated users cannot enable multi-factor auth modul
- update_error
AI-assisted analysis of home-assistant/core@58a3fdb3ea (2026-08-14).
Data as JSON: /api/errors/f7cb5d438bbc6abb.
Report an issue: GitHub.