Skip to main content

agentik_sdk/
lib.rs

1//! # Anthropic SDK for Rust
2//!
3//! This crate provides a Rust SDK for the Anthropic API, offering feature parity
4//! with the official TypeScript SDK.
5//!
6//! ## Quick Start
7//!
8//! ```rust,no_run
9//! # async fn example() -> Result<(), Box<dyn std::error::Error>> {
10//! use agentik_sdk::Anthropic;
11//!
12//! // Create client from environment variable ANTHROPIC_API_KEY
13//! let client = Anthropic::from_env()?;
14//!
15//! // Or create with explicit API key
16//! let client = Anthropic::new("your-api-key")?;
17//!
18//! // Test the connection
19//! client.test_connection().await?;
20//! # Ok(())
21//! # }
22//! ```
23//!
24//! ## Features
25//!
26//! - **Messages API**: Create and stream Claude conversations
27//! - **Authentication**: Automatic API key management
28//! - **Error Handling**: Comprehensive error types
29//! - **Logging**: Configurable tracing support
30//! - **Async/Await**: Built on tokio for high performance
31//!
32
33pub mod client;
34pub mod config;
35pub mod types;
36pub mod http;
37pub mod utils;
38pub mod resources;
39pub mod streaming;
40pub mod tools;
41pub mod files;
42pub mod tokens;
43
44// Re-exports for public API
45pub use client::Anthropic;
46pub use config::{ClientConfig, LogLevel};
47pub use types::{
48    AnthropicError, Result, RequestId, Usage,
49    Message, Role, ContentBlock, ImageSource, StopReason,
50    MessageCreateParams, MessageParam, MessageContent, ContentBlockParam,
51    MessageCreateBuilder, Model,
52    // Streaming types
53    MessageStreamEvent, MessageDelta, MessageDeltaUsage,
54    ContentBlockDelta, TextCitation,
55    // Tool types
56    Tool, ToolBuilder, ToolChoice, ToolUse, ToolResult, ToolResultContent,
57    ToolValidationError, ServerTool, WebSearchParameters,
58    // Batch types (Beta)
59    MessageBatch, BatchStatus, BatchRequestCounts, BatchRequest, BatchRequestBuilder,
60    BatchResult, BatchResponse, BatchResponseBody, BatchError,
61    BatchCreateParams, BatchListParams, BatchList,
62    // Files API types (Beta)
63    FileObject, FilePurpose, FileStatus, FileUploadParams, FileListParams, FileList,
64    FileOrder, UploadProgress, StorageInfo, FileDownload,
65    // Models API types
66    ModelObject, ModelListParams, ModelList, ModelCapabilities, ModelCapability,
67    ModelPricing, PricingTier, ModelComparison, ModelPerformance, ComparisonSummary,
68    ModelRequirements, ModelUsageRecommendations, ModelRecommendation,
69    RecommendedParameters, PerformanceExpectations, CostRange, QualityLevel,
70    CostEstimation, CostBreakdown,
71};
72pub use tools::{
73    ToolRegistry, ToolExecutor, ToolConversation, ToolFunction,
74    ToolExecutionConfig, ConversationConfig, ToolError,
75};
76pub use resources::{
77    MessagesResource, BatchesResource, FilesResource, ModelsResource,
78};
79pub use files::{
80    File, FileData, FileSource, FileConstraints, FileBuilder, FileError, to_file,
81};
82pub use tokens::{
83    TokenCounter, UsageStats, ModelUsage, RequestUsage, ModelPrice,
84    UsageSummary,
85};
86pub use http::{
87    RetryPolicy, RetryCondition, RetryExecutor, RetryResult, default_retry, api_retry,
88};
89pub use streaming::MessageStream;
90pub use http::auth::AuthMethod;
91
92/// Version information
93pub const VERSION: &str = env!("CARGO_PKG_VERSION");
94
95/// User-Agent string for HTTP requests
96pub const USER_AGENT: &str = concat!("agentik-sdk/", env!("CARGO_PKG_VERSION"));
97
98// Convenient type aliases
99pub type Error = AnthropicError;
100
101// Module re-exports for organized access
102pub use types as types_module;