1 """The Anthropic integration."""
3 from __future__
import annotations
13 from .const
import DOMAIN, LOGGER
15 PLATFORMS = (Platform.CONVERSATION,)
16 CONFIG_SCHEMA = cv.config_entry_only_config_schema(DOMAIN)
18 type AnthropicConfigEntry = ConfigEntry[anthropic.AsyncClient]
22 """Set up Anthropic from a config entry."""
23 client = anthropic.AsyncAnthropic(api_key=entry.data[CONF_API_KEY])
25 await client.messages.create(
26 model=
"claude-3-haiku-20240307",
28 messages=[{
"role":
"user",
"content":
"Hi"}],
31 except anthropic.AuthenticationError
as err:
32 LOGGER.error(
"Invalid API key: %s", err)
34 except anthropic.AnthropicError
as err:
37 entry.runtime_data = client
39 await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
45 """Unload Anthropic."""
46 return await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
bool async_setup_entry(HomeAssistant hass, AnthropicConfigEntry entry)
bool async_unload_entry(HomeAssistant hass, ConfigEntry entry)