Comprehensive Rust client for Anthropic's Claude API with enterprise reliability features.
This API crate is designed as a stateless HTTP client with zero persistence requirements. It provides:
- Direct HTTP calls to the Anthropic Claude API
- In-memory operation state only (resets on restart)
- No external storage dependencies (databases, files, caches)
- No configuration persistence beyond environment variables
This ensures lightweight, containerized deployments and eliminates operational complexity.
Expose all server-side functionality transparently while maintaining zero client-side intelligence or automatic behaviors.
Key principles:
- API Transparency: One-to-one mapping with Claude API endpoints
- Zero Automatic Behavior: No implicit decision-making or magic thresholds
- Explicit Control: Developer decides when, how, and why operations occur
- Configurable Reliability: Enterprise features available through explicit configuration
- Messages API (conversational interface)
- Server-Sent Events streaming
- Tool/function calling
- Vision support (image analysis)
- Prompt caching (~90% cost savings)
- Token counting
- System prompts and safety settings
- Enterprise reliability (retry, circuit breaker, rate limiting, failover, health checks)
- Synchronous API wrapper
- Batch operations
- Embeddings (not offered by Anthropic)
- Audio processing (not available in Claude API)
- WebSocket streaming (Claude uses SSE only)
- Model tuning/deployment (managed service only)
Core Capabilities:
- Messages API with full conversational support
- SSE streaming responses with tool calling integration
- Complete function/tool calling with validation
- Vision support for image analysis
- Prompt caching for cost optimization
Enterprise Reliability:
- Retry logic with exponential backoff and jitter
- Circuit breaker for failure threshold management
- Rate limiting with token bucket algorithm
- Multi-endpoint failover (4 strategies)
- Health checks with endpoint monitoring
Client Enhancements:
- Sync API wrapper for blocking operations
- CURL diagnostics for debugging
- Dynamic configuration with file watching
- Enterprise quota management
- HTTP compression support
Add to your Cargo.toml:
[dependencies]
api_claude = { version = "0.1.0", features = ["full"] }use api_claude::{ Client, Secret, CreateMessageRequest, Message, Role, Content };
#[ tokio::main ]
async fn main() -> Result< (), Box< dyn std::error::Error > >
{
let secret = Secret::new( "sk-ant-api03-your-key-here".to_string() )?;
let client = Client::new( secret );
let request = CreateMessageRequest::builder()
.model( "claude-sonnet-4-5-20250929".to_string() )
.max_tokens( 1000 )
.messages( vec![
Message
{
role : Role::User,
content : vec![ Content::Text
{
r#type : "text".to_string(),
text : "Hello, Claude!".to_string(),
} ],
cache_control : None,
}
] )
.build();
let response = client.create_message( request ).await?;
println!( "Claude: {:?}", response.content );
Ok( () )
}use api_claude::{ Client, Secret, CreateMessageRequest, Message, Role, Content };
use futures_util::StreamExt;
#[ tokio::main ]
async fn main() -> Result< (), Box< dyn std::error::Error > >
{
let client = Client::from_workspace()?;
let request = CreateMessageRequest::builder()
.model( "claude-sonnet-4-5-20250929".to_string() )
.max_tokens( 1000 )
.stream( true )
.messages( vec![ Message::user( "Tell me a story" ) ] )
.build();
let mut stream = client.create_message_stream( request ).await?;
while let Some( event ) = stream.next().await
{
let event = event?;
if let Some( text ) = event.delta_text()
{
print!( "{}", text );
}
}
Ok( () )
}Create secret/-secrets.sh in your workspace root:
#!/bin/bash
export ANTHROPIC_API_KEY="sk-ant-api03-your-key-here"use api_claude::Client;
let client = Client::from_workspace()?;export ANTHROPIC_API_KEY="sk-ant-api03-your-key-here"use api_claude::Client;
let client = Client::from_env()?;use api_claude::{ Client, Secret };
let secret = Secret::new( "sk-ant-api03-your-key-here".to_string() )?;
let client = Client::new( secret );See Secret Loading Guide for complete authentication options.
enabled- Master switch for core functionalitystreaming- SSE streaming supporttools- Function calling and toolsvision- Image understanding capabilities
retry-logic- Exponential backoff retrycircuit-breaker- Circuit breaker patternrate-limiting- Token bucket rate limitingfailover- Multi-endpoint failoverhealth-checks- Health monitoring
sync-api- Synchronous wrapperscurl-diagnostics- Debug utilitiescompression- HTTP compressionenterprise-quota- Usage trackingdynamic-config- Runtime configuration
full- All features enabled
- 540 tests (37 unit + 503 integration requiring API credentials)
- Real API integration tests
- No-mockup policy: all integration tests use real API calls
| Model | Context Window | Capabilities |
|---|---|---|
| claude-sonnet-4-5-20250929 | 200k tokens | Full capabilities |
| claude-3-5-sonnet-latest | 200k tokens | Fast, cost-effective |
| claude-3-opus-latest | 200k tokens | Highest capability |
| claude-3-haiku-latest | 200k tokens | Fastest |
- API Reference - Complete API documentation
- Examples - Real-world usage examples
- Secret Loading - Authentication and secret management
- Testing Guide - Testing organization and NO MOCKING policy
- reqwest: HTTP client with async support
- tokio: Async runtime
- serde: Serialization/deserialization
- workspace_tools: Secret management
- error_tools: Unified error handling
- secrecy: Secure credential handling
All dependencies workspace-managed for consistency.
- Follow established patterns in existing code
- Use 2-space indentation consistently
- Add tests for new functionality
- Update documentation for public APIs
- Ensure zero clippy warnings:
cargo clippy -- -D warnings - Follow zero-tolerance mock policy (real API integration only)
- Follow the "Thin Client, Rich API" principle
MIT
This section documents all files and directories in the crate root, ensuring Complete Entity Coverage per organizational_principles.rulebook.md.
| Path | Purpose |
|---|---|
src/ |
Source code implementation - client, Messages API, streaming, tools, error handling |
tests/ |
Comprehensive test suite with 540 tests, strict NO MOCKING ALLOWED policy |
examples/ |
API usage examples demonstrating Claude API features and capabilities |
docs/ |
Technical documentation organized in design collections (operation/) |
task/ |
Implementation task tracking — tsk-compliant work items for this crate |
Cargo.toml |
Crate metadata, dependencies, and feature configuration |
readme.md |
Crate overview, quick start, API documentation, and this Responsibility Table |
license |
MIT license text |
- Anthropic Console - Get your API key
- Claude API Documentation - Official API docs
- Examples - Comprehensive usage examples