anthropik

Crates.ioanthropik
lib.rsanthropik
version0.1.2
created_at2025-12-23 20:12:50.41183+00
updated_at2025-12-23 20:56:10.867947+00
descriptionAnthropic client for Rust.
homepage
repositoryhttps://github.com/chaynabors/anthropik
max_upload_size
id2002234
size86,034
Chay Nabors (chaynabors)

documentation

README

Anthropik

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

Crates.io Documentation License

Status

This library is functional and actively used in 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:

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

cargo add anthropik

Getting Started

cargo add anthropik
cargo add tokio --features full
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.

For Anthropic API details, see the official documentation.

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:

at your option.

Commit count: 0

cargo fmt