Skip to main content

Crate anthropic_tools

Crate anthropic_tools 

Source
Expand description

§Anthropic Tools

A Rust library for interacting with the Anthropic API.

§Features

  • Messages API with builder pattern
  • Tool/Function calling support
  • Vision/Multimodal support
  • Prompt caching support
  • Extended thinking support
  • Streaming support (planned)

§Configuration

Set the API key via environment variable or .env file:

# Environment variable
export ANTHROPIC_API_KEY="sk-ant-..."

# Or create .env file in project root
echo 'ANTHROPIC_API_KEY=sk-ant-...' > .env

Priority: Environment variable > .env file > Messages::with_api_key()

§Example

use anthropic_tools::prelude::*;

#[tokio::main]
async fn main() -> Result<()> {
    let mut client = Messages::new();
    client
        .model(Model::Sonnet4)  // Type-safe model selection
        .max_tokens(1024)
        .system("You are a helpful assistant.")
        .user("Hello, how are you?");

    let response = client.post().await?;
    println!("{}", response.get_text());
    Ok(())
}

Re-exports§

pub use common::AnthropicToolError;
pub use common::Result;
pub use common::Tool;
pub use common::Usage;
pub use messages::request::Messages;
pub use messages::response::Response;

Modules§

common
Common types and utilities for the Anthropic API client.
messages
Messages API client for Claude.
prelude
Commonly used types and traits