api_claude 0.2.0

Claude API for accessing Anthropic's large language models (LLMs).
Documentation

Anthropic Claude API Client for Rust

experimental

Production-ready Rust client for Anthropic's Claude API with 83% feature coverage

A comprehensive, feature-rich HTTP client for interacting with Anthropic's Claude API. Built with safety, performance, and developer experience in mind.

โœจ Features

  • ๐Ÿ’ฌ Messages API - Full conversational interface support
  • ๐Ÿ’พ Prompt Caching - ~90% cost savings with Anthropic's caching
  • ๐Ÿ“ก Streaming - Server-Sent Events (SSE) streaming responses
  • ๐Ÿ› ๏ธ Tool Calling - Complete function calling and tool integration
  • ๐Ÿ–ผ๏ธ Vision Support - Image analysis capabilities
  • ๐Ÿ“Š Enterprise Ready - Rate limiting, retries, circuit breaker, failover
  • ๐Ÿ” Rich Diagnostics - Curl command generation and detailed error context
  • ๐Ÿ”„ Sync & Async APIs - Both synchronous and asynchronous interfaces

๐Ÿš€ Quick Start

Add to your Cargo.toml:

[dependencies]
api_claude = { version = "0.1.0", features = ["full"] }

Basic Usage

use api_claude::{ Client, Secret, CreateMessageRequest, Message, Role, Content };

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    // Create client with API key
    let secret = Secret::new("sk-ant-api03-your-key-here".to_string())?;
    let client = Client::new(secret);

    // Create a message request
    let request = CreateMessageRequest::builder()
        .model("claude-sonnet-4-5-20250929".to_string())
        .max_tokens(1000)
        .messages(vec![
            Message {
                role: Role::User,
                content: vec![Content::Text {
                    r#type: "text".to_string(),
                    text: "Hello, Claude! How are you?".to_string(),
                }],
                cache_control: None,
            }
        ])
        .build();

    // Send request and get response
    let response = client.create_message(request).await?;
    println!("Claude: {:?}", response.content);

    Ok(())
}

๐Ÿ”ง Configuration

Set your API key via environment variable:

export ANTHROPIC_API_KEY="sk-ant-api03-your-key-here"

Or use workspace secrets (see Secret Loading Guide).

๐Ÿ“š Documentation

๐Ÿ—๏ธ Project Structure

api_claude/
โ”œโ”€โ”€ src/          # Library source code
โ”œโ”€โ”€ tests/        # Comprehensive test suite (435 tests)
โ”œโ”€โ”€ examples/     # Usage demonstrations
โ”œโ”€โ”€ docs/         # Architecture and design documentation
โ””โ”€โ”€ spec.md       # Project specification

๐Ÿงช Testing

# Run all tests
cargo nextest run --all-features

# Run with linting
cargo clippy --all-targets --all-features -- -D warnings

# Documentation tests
cargo test --doc --all-features

โš ๏ธ Note: Integration tests require valid ANTHROPIC_API_KEY and use real API calls (NO MOCKING).

๐Ÿ”ง Building

# Build with all features
cargo build --all-features

# Build for release
cargo build --release --all-features

๐Ÿ“‹ Feature Flags

Fine-grained control via feature flags:

  • authentication - API key management
  • rate-limiting - Token bucket rate limiting
  • retry-logic - Request retry mechanisms
  • circuit-breaker - Circuit breaker pattern
  • streaming - SSE streaming support
  • full - All features enabled

See Cargo.toml for complete list.

๐Ÿ“ License

This project is licensed under the MIT License.

๐Ÿค Contributing

Contributions welcome! Please ensure all tests pass before submitting PR.