anthropik 0.1.2

Anthropic client for Rust.
Documentation
# Anthropik

A Rust client for the Anthropic API, named for my love of pikpik carrots.

[![Crates.io](https://img.shields.io/crates/v/anthropik.svg)](https://crates.io/crates/anthropik)
[![Documentation](https://docs.rs/anthropik/badge.svg)](https://docs.rs/anthropik)
[![License](https://img.shields.io/crates/l/anthropik.svg)](LICENSE)

## Status

This library is functional and actively used in [strands-rs](https://github.com/chaynabors/strands-rs), which I develop for fun. If there's interest or need, I'm happy to productionize it further. Open an issue if this would be useful to you.

## Why This Library?

I wrote this because existing Anthropic clients for Rust lack active maintainers with serious Rust experience, and a client is straightforward to implement and maintain properly.

**Alternatives considered:**

- [anthropic]https://crates.io/crates/anthropic - Last updated over a year ago
- [anthropic-sdk-rust]https://crates.io/crates/anthropic-sdk-rust - 7 months since last update
- [anthropic_client]https://crates.io/crates/anthropic_client - Over a year old
- [genai]https://crates.io/crates/genai - Multi-provider, actively developed

## Features

- All Claude models (Sonnet 4.5, Haiku 4.5, Opus 4, legacy models)
- Streaming and non-streaming responses
- Tool use (function calling)
- Vision support (images and PDFs)
- Extended thinking mode
- Prompt caching
- MCP server integration
- Type-safe with non-exhaustive structs for forward compatibility

## Installation

```bash
cargo add anthropik
```

## Getting Started

```bash
cargo add anthropik
cargo add tokio --features full
```

```rust
use anthropik::{
    AnthropicClient, Content, InputMessage, MessagesRequest,
    MessagesRequestBody, Model, Role,
};

#[tokio::main]
async fn main() -> anyhow::Result<()> {
    let client = AnthropicClient::new();

    let response = client
        .messages(&MessagesRequest {
            x_api_key: std::env::var("ANTHROPIC_API_KEY")?.into(),
            body: MessagesRequestBody {
                model: Model::ClaudeSonnet4_5,
                messages: vec![InputMessage {
                    role: Role::User,
                    content: Content::String("Hello, Claude!".to_string()),
                    ..Default::default()
                }],
                max_tokens: 1024,
                ..Default::default()
            },
            ..Default::default()
        })
        .await?;

    println!("Response: {:?}", response);

    Ok(())
}
```

For streaming, use `messages_stream()` and set `stream: true` in the request body.

## Documentation

Full API documentation is available on [docs.rs](https://docs.rs/anthropik).

For Anthropic API details, see the [official documentation](https://docs.anthropic.com/).

## Design Notes

Most structs are marked `#[non_exhaustive]` to prevent breakage when new API fields are added. This trades some ergonomics (requiring `..Default::default()`) for stability as the library approaches 1.0.

## Contributing

Contributions welcome. Open an issue or submit a PR.

## License

Licensed under either of:

- MIT License ([LICENSE-MIT]LICENSE-MIT)
- Apache License, Version 2.0 ([LICENSE-APACHE]LICENSE-APACHE)

at your option.