Expand description
§anthropic-client-rs
A Rust client for the Anthropic Messages API — streaming SSE, tool use, extended thinking, and prompt caching. Compatible with Claude, MiniMax, DeepSeek-anthropic, and any Anthropic-compatible provider.
§Features
- Sync (default) — lightweight
ureq - Async — optional
reqwest+tokio(features = ["async"]) - Messages API — streaming SSE with content block deltas
- Tool use — parallel tool calling with partial JSON accumulation
- Extended thinking — thinking blocks with reasoning support
- Vision — image inputs (base64, URL)
- System prompts — top-level
systemparameter - Prompt caching — cache_control breakpoints
- Auto-retry — exponential backoff with jitter
- Token counting — approximate message token estimation
- Multi-provider — Anthropic, MiniMax, DeepSeek
§Quick start
use anthropic_client_rs::{AnthropicClient, ChatMessage};
let client = AnthropicClient::new("sk-ant-xxx", "claude-sonnet-4-20250514");
let resp = client.messages_create(
&[ChatMessage::user("Hello!")],
Some("You are helpful."), None, 1024, None,
).unwrap();
println!("{}", resp.text);Re-exports§
pub use cache::CacheConfig;pub use error::AnthropicError;pub use error::ApiError;pub use error::Result;pub use request::MessageRequest;pub use request::Metadata;pub use request::ThinkingConfig;pub use request::ThinkingDisplay;pub use retry::RetryConfig;pub use types::ChatMessage;pub use types::ContentBlock;pub use types::CountTokensResponse;pub use types::DocumentSource;pub use types::ImageSource;pub use types::LlmResponse;pub use types::MessageResponse;pub use types::OutputTokensDetails;pub use types::ServerToolUse;pub use types::SimplifiedToolCall;pub use types::StreamEvent;pub use types::Tool;pub use types::ToolCall;pub use types::ToolChoice;pub use types::Usage;
Modules§
- api_
common - Shared API logic used by both sync and async clients.
- async_
messages - Async messages API for Anthropic.
- async_
sse - Async SSE reader for Anthropic streams, spec-compliant.
- cache
- Prompt caching support for Anthropic API.
- error
- request
- Request builder for Anthropic Messages API.
- retry
- Automatic retry with exponential backoff for anthropic-rs.
- sse
- Minimal Server-Sent-Events (SSE) line framing, spec-compliant.
- tokens
- Token counting utility for Anthropic models.
- types
- Shared types for the Anthropic API: chat messages, tool calls, content blocks, etc.
Structs§
- Anthropic
Async Client - An async Anthropic-compatible API client using
reqwest. - Anthropic
Client - An Anthropic-compatible API client.
- Stream
Event Stream - Iterator over raw, typed
StreamEvents from a streamed response.
Functions§
- parse_
anthropic_ stream - Parse an Anthropic SSE stream from any reader.