anthropic-ai-sdk 0.0.2

An unofficial Rust SDK for Anthropic's Claude AI API
Documentation

Anthropic Rust SDK

Crates.io Documentation License: MIT

An unofficial Rust SDK for the Anthropic API.

Features

  • Full async/await support
  • Comprehensive error handling
  • Pagination support
  • Token counting utilities

Installation

Add this to your Cargo.toml:

toml
[dependencies]
anthropic-ai-sdk = "0.0.1"

Quick Start

use anthropic_ai_sdk::clients::AnthropicClient;
use anthropic_ai_sdk::types::model::ModelClient;
use std::env;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    // Initialize the client
    let client = AnthropicClient::new(
        env::var("ANTHROPIC_API_KEY")?,
        env::var("ANTHROPIC_API_VERSION").unwrap_or("2023-06-01".to_string()),
    )?;
    // List available models
    let models = client.list_models(None).await?;
    for model in models.data {
        println!("Model: {} ({})", model.display_name, model.id);
    }
    Ok(())
}

Examples

Check out the examples directory for more usage examples:

API Coverage

  • List Models
  • Create Message
  • Count Message Tokens
  • Stream Message
  • Upload Files
  • Delete Files

Development

Prerequisites

  • Rust 1.75 or later
  • An Anthropic API key

Running Tests

cargo test

Running Examples

Set your API key
export ANTHROPIC_API_KEY="your-api-key"
Run an example
cargo run --example list-models

Contributing

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.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Acknowledgments

Security

If you discover a security vulnerability within this package, please send an e-mail to the maintainers. All security vulnerabilities will be promptly addressed.

Support

For support questions, please use the GitHub Issues.