| Crates.io | claude-client |
| lib.rs | claude-client |
| version | 0.3.1 |
| created_at | 2025-02-25 15:53:28.955399+00 |
| updated_at | 2025-02-25 16:08:23.709658+00 |
| description | A Rust client for the Anthropic Claude API |
| homepage | |
| repository | https://github.com/thesurlydev/claude-client |
| max_upload_size | |
| id | 1569264 |
| size | 55,761 |
A Rust client for the Claude API. This client provides a simple interface to interact with Claude's API, including sending messages and listing available models.
To build the project:
cargo build
The test suite includes both unit tests and integration tests. The integration tests require a valid Anthropic API key to be set in the environment:
# Set your API key
export ANTHROPIC_API_KEY="your_api_key_here"
# Run all tests
cargo test
# Run only unit tests
cargo test --lib
# Run only integration tests
cargo test --test integration_test
If no API key is set, the integration tests will be skipped automatically.
First, set your Anthropic API key as an environment variable:
export ANTHROPIC_API_KEY="your_api_key_here"
use claude_client::claude::ClaudeClient;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Initialize the client
let client = ClaudeClient::new()?;
// Send a message using the default model (claude-3-7-sonnet-20250219)
let response = client
.send_message(
None,
"You are a helpful assistant.",
"What is the capital of France?"
)
.await?;
println!("Response: {}", response);
Ok(())
}
use claude_client::claude::ClaudeClient;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let client = ClaudeClient::new()?;
// Send a message using a specific model
let response = client
.send_message(
Some("claude-3-opus-20240229"),
"You are a helpful assistant.",
"What is the capital of France?"
)
.await?;
println!("Response: {}", response);
Ok(())
}
use claude_client::claude::ClaudeClient;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let client = ClaudeClient::new()?;
// Get a list of available models
let models = client.list_models().await?;
// Print model information
for model in models {
println!("Model ID: {}", model.id);
println!("Display Name: {}", model.display_name);
println!("Created At: {}", model.created_at);
println!("---");
}
Ok(())
}
The client uses Rust's Result type for error handling. All errors are wrapped in a Box<dyn std::error::Error>. Common errors include:
Contributions are welcome! Please feel free to submit a Pull Request.