A standalone implementation of an Anthropic conversation integration for Home Assistant that doesn't depend on the Home Assistant core package. This allows you to use Anthropic's Claude AI models in your own applications or integrate them into custom Home Assistant setups.
- Full conversation handling with Claude AI models
- Configuration flow support (UI-based setup)
- Conversation history management
- Support for all Claude models (3.5 Sonnet, 3.5 Haiku, etc.)
- Configurable parameters (temperature, max tokens, thinking budget)
- Standalone operation without Home Assistant core dependencies
- Install the required dependencies:
pip install -r requirements.txt- Set up your Anthropic API key:
export ANTHROPIC_API_KEY="your-api-key-here"import asyncio
from anthropic_standalone import StandaloneAnthropicIntegration
async def main():
# Initialize the integration
integration = StandaloneAnthropicIntegration(
api_key="your-api-key",
model="claude-3-5-sonnet-20241022",
max_tokens=1024,
temperature=0.7,
thinking_budget=20000
)
# Set up the integration
await integration.async_setup()
# Process messages
response = await integration.async_process_message(
"Hello! How can you help me today?",
conversation_id="my_conversation"
)
print(response)
# Clean up
await integration.async_close()
asyncio.run(main())python -m anthropic_standalone.example- api_key: Your Anthropic API key (required)
- model: Claude model to use (default: "claude-3-5-sonnet-20241022")
- max_tokens: Maximum tokens in response (default: 1024)
- temperature: Response creativity (0.0-1.0, default: 0.7)
- thinking_budget: Tokens for extended reasoning (default: 20000)
claude-3-5-sonnet-20241022(recommended)claude-3-5-haiku-20241022claude-3-opus-20240229claude-3-sonnet-20240229claude-3-haiku-20240307
anthropic_standalone/
├── __init__.py # Main integration setup and standalone runner
├── api_client.py # Anthropic API client wrapper
├── config_flow.py # Configuration flow for UI setup
├── conversation.py # Conversation entity handler
├── const.py # Constants and configuration keys
├── manifest.json # Integration metadata
├── strings.json # UI strings and translations
├── requirements.txt # Python dependencies
├── example.py # Usage example
└── README.md # This file
async_setup(): Initialize the integrationasync_process_message(message, conversation_id=None): Process a message and get responseclear_conversation(conversation_id=None): Clear conversation historyasync_close(): Clean up resources
-
Add to HACS Custom Repositories:
- Go to HACS → Integrations → ⋮ → Custom repositories
- URL:
https://github.com/ketan0/ha-anthropic-standalone - Category: Integration
-
Install & Configure:
- Search for "Anthropic Conversation (Standalone)" in HACS
- Download and restart Home Assistant
- Copy the
anthropic_standalonedirectory to yourcustom_componentsfolder - Restart Home Assistant
Add to your configuration.yaml:
# Basic configuration
anthropic_standalone:
api_key: "your-anthropic-api-key-here"
# Advanced configuration with all options
anthropic_standalone:
api_key: "your-anthropic-api-key-here"
model: "claude-3-5-sonnet-20241022"
max_tokens: 1024
temperature: 0.7
thinking_budget: 20000Configuration Parameters:
api_key(required): Your Anthropic API keymodel(optional): Claude model to use (default:claude-3-5-sonnet-20241022)max_tokens(optional): Maximum response tokens 1-8192 (default: 1024)temperature(optional): Response creativity 0.0-1.0 (default: 0.7)thinking_budget(optional): Extended reasoning tokens 1000-100000 (default: 20000)
- Go to Settings → Devices & Services → Add Integration
- Search for "Anthropic Conversation (Standalone)"
- Enter your configuration details in the UI form
The integration includes comprehensive error handling for:
- Invalid API keys
- Rate limiting
- Connection issues
- API errors
- Malformed responses
This implementation is designed to be compatible with Home Assistant's integration patterns while remaining standalone. It follows the same architectural principles as the official Home Assistant Anthropic integration.
- Python 3.11+
anthropiclibraryvoluptuousfor configuration validation- Valid Anthropic API key with billing enabled
- Conversation history is maintained per conversation ID
- History is automatically trimmed to the last 20 messages to manage memory
- The system message sets up Claude as a helpful assistant in a Home Assistant context
- All API interactions are asynchronous for better performance