elizaOS Anthropic Plugin - Claude API client for text and object generation
Project description
elizaos-plugin-anthropic
Python implementation of the Anthropic Claude API client for elizaOS.
Features
- Text generation with Claude models
- Structured JSON object generation
- Strong types with Pydantic models
- Fail-fast error handling
- Async/await support with httpx
Installation
pip install elizaos-plugin-anthropic
Usage
Text Generation
import asyncio
from elizaos_plugin_anthropic import AnthropicClient, AnthropicConfig, TextGenerationParams
async def main():
config = AnthropicConfig.from_env()
async with AnthropicClient(config) as client:
# Simple prompt
response = await client.generate_text_large("What is the meaning of life?")
print(f"Response: {response.text}")
# With parameters
params = (
TextGenerationParams(prompt="Explain quantum computing")
.with_max_tokens(1024)
.with_temperature(0.7)
)
response = await client.generate_text_large(params)
print(f"Tokens used: {response.usage.total_tokens()}")
asyncio.run(main())
JSON Object Generation
import asyncio
from elizaos_plugin_anthropic import AnthropicClient, AnthropicConfig, ObjectGenerationParams
async def main():
config = AnthropicConfig.from_env()
async with AnthropicClient(config) as client:
# Simple prompt
response = await client.generate_object_small(
"Create a JSON object with name, age, and email fields"
)
print(f"Generated: {response.object}")
# With parameters
params = ObjectGenerationParams(
prompt="Create a user profile with nested address",
temperature=0.2,
)
response = await client.generate_object_large(params)
print(f"User: {response.object}")
asyncio.run(main())
Configuration
Environment variables:
| Variable | Required | Default | Description |
|---|---|---|---|
ANTHROPIC_API_KEY |
Yes | - | Your Anthropic API key |
ANTHROPIC_BASE_URL |
No | https://api.anthropic.com |
API base URL |
ANTHROPIC_SMALL_MODEL |
No | claude-3-5-haiku-20241022 |
Small model ID |
ANTHROPIC_LARGE_MODEL |
No | claude-sonnet-4-20250514 |
Large model ID |
ANTHROPIC_TIMEOUT_SECONDS |
No | 60 |
Request timeout |
Models
Available models:
| Model | Size | Description |
|---|---|---|
claude-3-5-haiku-20241022 |
Small | Fast and efficient |
claude-sonnet-4-20250514 |
Large | Most capable |
claude-3-5-sonnet-20241022 |
Large | Balanced performance |
claude-3-opus-20240229 |
Large | Previous flagship |
Testing
Install development dependencies:
pip install -e ".[dev]"
Run unit tests:
pytest -v
Run integration tests (requires API key):
# Create .env file with your API key
echo "ANTHROPIC_API_KEY=your-key" > .env
# Run integration tests
pytest -m integration
Type Checking
mypy elizaos_plugin_anthropic
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file elizaos_plugin_anthropic-2.0.0a4.tar.gz.
File metadata
- Download URL: elizaos_plugin_anthropic-2.0.0a4.tar.gz
- Upload date:
- Size: 11.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
da63616a9701be3358698ea1e9180dce1d2e18b925987f4f674242a7768de5b8
|
|
| MD5 |
8f631e148e0d5e4564e446f3c7d5219b
|
|
| BLAKE2b-256 |
057d98a9ac24da3431cd3abbc6903f2bff2bd870dc93976651b6e46676e85a1e
|
File details
Details for the file elizaos_plugin_anthropic-2.0.0a4-py3-none-any.whl.
File metadata
- Download URL: elizaos_plugin_anthropic-2.0.0a4-py3-none-any.whl
- Upload date:
- Size: 10.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a51538b537a3322cb7a709c9f714921ff1468f434a8aaa691ba7596dc9893e0f
|
|
| MD5 |
d2a2b1aed6dabd9f747f6a4ac39438a7
|
|
| BLAKE2b-256 |
02620de52477d45e6effbe1c76dc63faf678f1805712b53fe7c8380b115f2747
|