Crates.io | anthropic-ai-sdk |
lib.rs | anthropic-ai-sdk |
version | 0.0.17 |
source | src |
created_at | 2025-01-14 21:38:55.103734 |
updated_at | 2025-02-02 07:26:01.417751 |
description | An unofficial Rust SDK for Anthropic's Claude AI API |
homepage | |
repository | https://github.com/e-bebe/anthropic-sdk-rs/tree/main/anthropic-ai-sdk |
max_upload_size | |
id | 1516711 |
size | 48,999 |
An unofficial Rust SDK for the Anthropic API.
cargo add anthropic-ai-sdk
use anthropic_ai_sdk::clients::AnthropicClient;
use anthropic_ai_sdk::types::message::{
CreateMessageParams, Message, MessageClient, MessageError, RequiredMessageParams, Role,
};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let anthropic_api_key = std::env::var("ANTHROPIC_API_KEY").unwrap();
let client = AnthropicClient::new::<MessageError>(anthropic_api_key, "2023-06-01").unwrap();
let body = CreateMessageParams::new(RequiredMessageParams {
model: "claude-3-5-sonnet-20240620".to_string(),
messages: vec![Message::new_text(Role::User, "Hello, Claude")],
max_tokens: 1024,
});
match client.create_message(Some(&body)).await {
Ok(message) => {
println!("Successfully created message: {:?}", message.content);
}
Err(e) => {
println!("Error: {}", e);
}
}
Ok(())
}
Check out the examples directory for more usage examples:
cargo test
Set your API key
export ANTHROPIC_API_KEY="your-api-key"
Run an example
cd examples/models/list-models
cargo run
Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.
Please make sure to update tests as appropriate.
This project is licensed under the MIT License - see the LICENSE file for details.
If you discover a security vulnerability within this package, please send an e-mail to the maintainers. All security vulnerabilities will be promptly addressed.
For support questions, please use the GitHub Issues.