Skip to main content

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

elizaos_plugin_anthropic-2.0.0a5.tar.gz (11.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

elizaos_plugin_anthropic-2.0.0a5-py3-none-any.whl (10.5 kB view details)

Uploaded Python 3

File details

Details for the file elizaos_plugin_anthropic-2.0.0a5.tar.gz.

File metadata

File hashes

Hashes for elizaos_plugin_anthropic-2.0.0a5.tar.gz
Algorithm Hash digest
SHA256 c917d2cc1b71551400986de3f3b33bf73cf87c01a6a9ca8566f1579d64dca6c5
MD5 20b18a9ccc7225be45a2c6bee48955bc
BLAKE2b-256 d0817a823eb802052d08314c5540fe62acee250ef34b4b017a4305acde3205f4

See more details on using hashes here.

File details

Details for the file elizaos_plugin_anthropic-2.0.0a5-py3-none-any.whl.

File metadata

File hashes

Hashes for elizaos_plugin_anthropic-2.0.0a5-py3-none-any.whl
Algorithm Hash digest
SHA256 cb83d04134e2be40598ef6c4cc3a47ceef003551fdabbbfc970c2b14cf1d7b44
MD5 6d62f703544d7874ab957ae69b542600
BLAKE2b-256 611978617a91d59207593b65676d308560c17f07ea5a9a5aab83e8cc2c6f9b81

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page