Claudius
Claudius is a Rust SDK for the Anthropic API, providing a clean, idiomatic interface to interact with Claude, Anthropic's powerful AI assistant. This library enables seamless integration with all of Claude's capabilities, including chat completions, streaming responses, and advanced features.
Quick Example
use ;
use tokio;
async
Features
- Complete API Coverage: Access all of Anthropic's AI capabilities through Claude
- Streaming Support: Real-time streaming for conversational applications
- Strongly Typed: Take advantage of Rust's type system for predictable API interactions
- Async First: Built with async/await for efficient I/O operations
- Error Handling: Comprehensive error types for robust application development
- Extensible: Modular design with builder patterns for flexible configuration
Installation
Add Claudius to your Cargo.toml:
[]
= "0.2.0"
Authentication
Claudius uses the Anthropic API key for authentication. You can provide it in two ways:
- Set the
ANTHROPIC_API_KEYenvironment variable:
- Provide it directly when creating the client:
let client = new?;
Usage
Basic Chat
// Create a client
let client = new?; // Uses CLAUDIUS_API_KEY env var and falls back to ANTHROPIC_API_KEY
// Create a user message
let message = new_with_string;
// Set up request parameters
let params = new
.with_system_string;
// Send the request and get the response
let response = client.send.await?;
// Process the response
for content in response.content
Streaming Responses
// Create streaming request parameters
let params = new_streaming;
// Get a stream of events
let stream = client.stream.await?;
// Pin the stream so it can be polled
use StreamExt;
use pin;
pin!;
// Process the stream events
while let Some = stream.next.await
Model Selection
Claudius supports all Anthropic models via a typed enum:
// Use a known model (latest version)
let model = Known;
// Use a specific model version
let model = Known;
// Use a custom model identifier
let model = Custom;
Advanced Configuration
// Customize the client
let client = new?
.with_base_url
.with_timeout;
// Configure request parameters
let params = new
.with_system_string
.with_temperature
.with_top_p
.with_top_k
.with_stop_sequences;
Error Handling
Claudius provides a robust error system:
match client.send.await
Examples
The repository includes several examples:
basic_chat.rs: Simple request and response with Claudestreaming.rs: Streaming response handling
Run examples with:
# Set your API key
# Run the basic chat example
# Run the streaming example
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
This project is licensed under the Apache License 2.0 - see the LICENSE file for details.
Acknowledgments
- Thanks to Anthropic for creating Claude and providing the API that powers this SDK
- This project is not officially affiliated with Anthropic