plugins/plugin-anthropic/README.md
Anthropic Claude API client for elizaOS, providing text generation, streaming, image description, and structured JSON object generation capabilities.
any or unknown types, full type safetyimport { anthropicPlugin } from "@elizaos/plugin-anthropic";
import { AgentRuntime, ModelType } from "@elizaos/core";
// Register the plugin
const runtime = new AgentRuntime({
plugins: [anthropicPlugin],
});
// Generate text
const text = await runtime.useModel(ModelType.TEXT_LARGE, {
prompt: "Explain quantum computing in simple terms",
});
// Generate JSON object via TEXT_LARGE with a responseSchema (native tool calling)
const result = await runtime.useModel(ModelType.TEXT_LARGE, {
prompt: "Create a user profile with name, email, and age",
responseSchema: { type: "object" },
});
npm install @elizaos/plugin-anthropic
# or
bun add @elizaos/plugin-anthropic
All implementations use the same 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-haiku-4-5-20251001 | Small model ID |
ANTHROPIC_LARGE_MODEL | No | claude-sonnet-4-6 | Large model ID |
ANTHROPIC_TIMEOUT_SECONDS | No | 60 | Request timeout |
ANTHROPIC_EXPERIMENTAL_TELEMETRY | No | false | Enable telemetry (TS only) |
ANTHROPIC_COT_BUDGET | No | 0 | Chain-of-thought token budget (TS only) |
| Model ID | Size | Description |
|---|---|---|
claude-haiku-4-5-20251001 | Small | Fastest current Claude model |
claude-sonnet-4-6 | Large | Default large model |
claude-opus-4-7 | Large | Most capable current model |
TEXT_SMALL - Text generation with small model (supports tools, toolChoice, responseSchema for structured output via native tool calling)TEXT_LARGE - Text generation with large model (supports tools, toolChoice, responseSchema for structured output via native tool calling)IMAGE_DESCRIPTION - Image analysis with title and description output| Parameter | Type | Description |
|---|---|---|
prompt | string | The prompt to generate from |
messages | array? | Multi-turn message history (supersedes prompt when both supplied) |
system | string? | Optional system prompt |
maxTokens | number? | Maximum tokens to generate |
temperature | number? | Randomness (0-1, can't use with topP) |
topP | number? | Nucleus sampling (can't use with temperature) |
stopSequences | string[]? | Stop generation at these sequences |
stream | boolean? | Return a streaming text result when true |
tools | ToolSet? | Native Anthropic tool definitions for tool calling |
toolChoice | object? | Tool selection hint (auto, required, none, or named tool) |
responseSchema | object? | JSON Schema for structured output (routes through native tool calling) |
plugin-anthropic/
โโโ typescript/ # TypeScript implementation
โ โโโ index.ts # Main entry point
โ โโโ models/ # Model handlers
โ โโโ providers/ # Anthropic client factories
โ โโโ types/ # Type definitions
โ โโโ utils/ # Utilities (config, JSON parsing)
โ โโโ __tests__/ # Unit and integration tests
โโโ rust/ # Rust implementation
โ โโโ src/ # Source code
โ โ โโโ lib.rs # Library entry
โ โ โโโ client.rs # API client
โ โ โโโ config.rs # Configuration
โ โ โโโ models.rs # Model definitions
โ โ โโโ types.rs # Type definitions
โ โ โโโ error.rs # Error types
โ โโโ tests/ # Integration tests
โโโ python/ # Python implementation
โ โโโ elizaos_plugin_anthropic/
โ โ โโโ __init__.py # Package entry
โ โ โโโ client.py # API client
โ โ โโโ config.py # Configuration
โ โ โโโ models.py # Model definitions
โ โ โโโ types.py # Type definitions
โ โ โโโ errors.py # Error types
โ โโโ tests/ # Integration tests
โโโ package.json # npm package config
โโโ README.md # This file
cd typescript
npx vitest
# With integration tests (requires API key)
ANTHROPIC_API_KEY=your-key npx vitest
# TypeScript
bun run build