anthropic-tools
A Rust library for interacting with the Anthropic API.
Features
- Messages API - Builder pattern for creating and sending messages
- Type-safe Model Selection -
Modelenum with all Claude models - Tool/Function Calling - Define and use tools with JSON Schema
- Vision/Multimodal - Support for images and documents
- Extended Thinking - Enable Claude's internal reasoning for complex tasks
- Prompt Caching - Cache control for system prompts and tools
- Streaming - Server-Sent Events (SSE) streaming support
- Environment Configuration - Load API key from env var or
.envfile
Installation
Add to your Cargo.toml:
[]
= "1.0"
Quick Start
Configuration
Set your API key via environment variable or .env file:
# Environment variable
# Or create .env file in project root
Basic Usage
use *;
async
Extended Thinking
use *;
async
Tool Calling
use *;
async
Vision (Image Input)
use *;
async
Available Models
use Model;
// Claude 4.5 Family
Opus45 // claude-opus-4-5-20251101
// Claude 4 Family
Opus4 // claude-opus-4-20250514
Sonnet4 // claude-sonnet-4-20250514 (default)
// Claude 3 Family
Opus3 // claude-3-opus-20240229
Sonnet3 // claude-3-sonnet-20240229
Haiku3 // claude-3-haiku-20240307
// Custom/Future models
Other
Environment Variables
| Variable | Description |
|---|---|
ANTHROPIC_API_KEY |
Your Anthropic API key (required) |
Supports loading from .env file automatically.
Module Structure
anthropic-tools
├── common/
│ ├── errors.rs - Error types (AnthropicToolError)
│ ├── tool.rs - Tool definitions (Tool, JsonSchema)
│ └── usage.rs - Token usage tracking
└── messages/
├── request/
│ ├── mod.rs - Messages client
│ ├── body.rs - Request body, ThinkingConfig
│ ├── content.rs - Content blocks (text, image, tool_use, etc.)
│ ├── message.rs - Message and SystemPrompt types
│ ├── model.rs - Model enum
│ ├── role.rs - Role enum (User, Assistant)
│ └── mcp.rs - MCP server configuration
├── response.rs - API response types
└── streaming.rs - SSE streaming types
License
MIT