api_claude
Comprehensive Rust client for Anthropic's Claude API with enterprise reliability features.
🎯 Architecture: Stateless HTTP Client
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.
🏛️ Governing Principle: "Thin Client, Rich API"
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
Scope
In Scope
- 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
Out of Scope
- Embeddings (not offered by Anthropic)
- Audio processing (not available in Claude API)
- WebSocket streaming (Claude uses SSE only)
- Model tuning/deployment (managed service only)
Features
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
Installation
Add to your Cargo.toml:
[]
= { = "0.1.0", = ["full"] }
Quick Start
Basic Usage
use ;
async
Streaming Response
use ;
use StreamExt;
async
Authentication
Option 1: Workspace Secret (Recommended)
Create secret/-secrets.sh in your workspace root:
#!/bin/bash
use Client;
let client = from_workspace?;
Option 2: Environment Variable
use Client;
let client = from_env?;
Option 3: Direct Configuration
use ;
let secret = new?;
let client = new;
See Secret Loading Guide for complete authentication options.
Feature Flags
Core Features
enabled- Master switch for core functionalitystreaming- SSE streaming supporttools- Function calling and toolsvision- Image understanding capabilities
Enterprise Reliability
retry-logic- Exponential backoff retrycircuit-breaker- Circuit breaker patternrate-limiting- Token bucket rate limitingfailover- Multi-endpoint failoverhealth-checks- Health monitoring
Client Enhancements
sync-api- Synchronous wrapperscurl-diagnostics- Debug utilitiescompression- HTTP compressionenterprise-quota- Usage trackingdynamic-config- Runtime configuration
Presets
full- All features enabled
Testing
Test Coverage
- 435 tests passing (100%)
- Real API integration tests
- No-mockup policy: all integration tests use real API calls
Supported Models
| 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 |
Documentation
- API Reference - Complete API documentation
- Examples - Real-world usage examples
- Secret Loading - Authentication and secret management
- Testing Guide - Testing organization and NO MOCKING policy
- Specification - Detailed project specification
Dependencies
- 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.
Contributing
- 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
License
MIT
Links
- Anthropic Console - Get your API key
- Claude API Documentation - Official API docs
- Examples - Comprehensive usage examples
- Specification - Technical specification