1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
//! # Claude SDK for Rust
//!
//! [](https://crates.io/crates/claude-sdk)
//! [](https://docs.rs/claude-sdk)
//! [](https://opensource.org/licenses/MIT)
//!
//! A native Rust implementation of the Claude API client with full support for
//! streaming, tool execution, vision, batch processing, and more.
//!
//! ## Features
//!
//! - **Complete API Coverage**: Messages, streaming, tools, vision, batch processing
//! - **Multi-Platform**: Anthropic API and AWS Bedrock support
//! - **Type-Safe**: Comprehensive type definitions for all API structures
//! - **Async/Await**: Built on tokio for efficient async operations
//! - **Streaming**: Server-sent events (SSE) with typed event parsing
//! - **Tool Use**: Define tools and handle programmatic tool calls
//! - **Prompt Caching**: Cache system prompts and tools for cost savings
//! - **Extended Thinking**: Enable Claude's step-by-step reasoning
//! - **Token Counting**: Estimate token usage before API calls
//! - **Retry Logic**: Built-in exponential backoff for rate limits
//!
//! ## Quick Start
//!
//! Add to your `Cargo.toml`:
//!
//! ```toml
//! [dependencies]
//! claude-sdk = "1.0"
//! tokio = { version = "1", features = ["full"] }
//! ```
//!
//! Basic usage:
//!
//! ```rust,no_run
//! use claude_sdk::{ClaudeClient, MessagesRequest, Message};
//!
//! #[tokio::main]
//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
//! let client = ClaudeClient::anthropic(
//! std::env::var("ANTHROPIC_API_KEY")?
//! );
//!
//! let request = MessagesRequest::new(
//! "claude-sonnet-4-5-20250929",
//! 1024,
//! vec![Message::user("Hello, Claude!")],
//! );
//!
//! let response = client.send_message(request).await?;
//! println!("Response: {:?}", response);
//! Ok(())
//! }
//! ```
//!
//! ## Feature Flags
//!
//! The SDK uses feature flags to control optional functionality:
//!
//! | Feature | Default | Description |
//! |---------|---------|-------------|
//! | `anthropic` | Yes | Enable Anthropic API support |
//! | `bedrock` | No | Enable AWS Bedrock support |
//! | `repl` | No | Include interactive REPL binary |
//! | `full` | No | Enable all features |
//!
//! To enable AWS Bedrock support:
//!
//! ```toml
//! [dependencies]
//! claude-sdk = { version = "1.0", features = ["bedrock"] }
//! ```
//!
//! ## Streaming Responses
//!
//! Use streaming for real-time token generation:
//!
//! ```rust,no_run
//! use claude_sdk::{ClaudeClient, MessagesRequest, Message, StreamEvent, ContentDelta};
//! use futures::StreamExt;
//!
//! # async fn example() -> Result<(), Box<dyn std::error::Error>> {
//! let client = ClaudeClient::anthropic(std::env::var("ANTHROPIC_API_KEY")?);
//!
//! let request = MessagesRequest::new(
//! "claude-sonnet-4-5-20250929",
//! 1024,
//! vec![Message::user("Write a haiku about Rust.")],
//! );
//!
//! let mut stream = client.send_streaming(request).await?;
//!
//! while let Some(event) = stream.next().await {
//! match event? {
//! StreamEvent::ContentBlockDelta { delta, .. } => {
//! if let ContentDelta::TextDelta { text } = delta {
//! print!("{}", text);
//! }
//! }
//! StreamEvent::MessageStop => println!("\n--- Done ---"),
//! _ => {}
//! }
//! }
//! # Ok(())
//! # }
//! ```
//!
//! ## Tool Use
//!
//! Define and handle tool calls:
//!
//! ```rust,no_run
//! use claude_sdk::{ClaudeClient, MessagesRequest, Message, CustomTool, ContentBlock};
//! use serde_json::json;
//!
//! # async fn example() -> Result<(), Box<dyn std::error::Error>> {
//! let client = ClaudeClient::anthropic(std::env::var("ANTHROPIC_API_KEY")?);
//!
//! let weather_tool = CustomTool::new(
//! "get_weather",
//! "Get weather for a location",
//! json!({
//! "type": "object",
//! "properties": {
//! "location": { "type": "string" }
//! },
//! "required": ["location"]
//! }),
//! )
//! .programmatic();
//!
//! let request = MessagesRequest::new(
//! "claude-sonnet-4-5-20250929",
//! 1024,
//! vec![Message::user("What's the weather in Tokyo?")],
//! )
//! .with_custom_tools(vec![weather_tool]);
//!
//! let response = client.send_message(request).await?;
//!
//! // Handle tool use in response
//! for block in &response.content {
//! if let ContentBlock::ToolUse { id, name, input, .. } = block {
//! println!("Tool: {} ({})", name, id);
//! println!("Input: {}", input);
//! // Execute tool and return result...
//! }
//! }
//! # Ok(())
//! # }
//! ```
//!
//! ## AWS Bedrock
//!
//! Use Claude through AWS Bedrock (requires `bedrock` feature):
//!
//! ```rust,ignore
//! use claude_sdk::ClaudeClient;
//!
//! # async fn example() -> Result<(), Box<dyn std::error::Error>> {
//! // Uses AWS credentials from environment/config
//! let client = ClaudeClient::bedrock("us-east-1").await?;
//!
//! // Use the same API as Anthropic
//! // ...
//! # Ok(())
//! # }
//! ```
//!
//! ## Modules
//!
//! - [`client`] - API client for Anthropic and AWS Bedrock
//! - [`types`] - Request/response types and content blocks
//! - [`streaming`] - SSE streaming types and event parsing
//! - [`conversation`] - Multi-turn conversation builder
//! - [`batch`] - Batch processing API for bulk operations
//! - [`files`] - Files API for document uploads
//! - [`models`] - Model constants and metadata
//! - [`tokens`] - Token counting utilities
//! - [`retry`] - Retry logic with exponential backoff
//! - [`error`] - Error types and result aliases
//! - [`prompts`] - Pre-built system prompts
//! - [`structured`] - Structured output helpers
//!
//! ## Model Selection
//!
//! Use model constants for type-safe model selection:
//!
//! ```rust
//! use claude_sdk::models::{CLAUDE_SONNET_4_5, CLAUDE_OPUS_4_5, CLAUDE_HAIKU_4_5};
//!
//! // Latest models
//! let model = CLAUDE_SONNET_4_5;
//! println!("Using: {} ({})", model.name, model.anthropic_id);
//! println!("Max tokens: {}", model.max_output_tokens);
//! println!("Supports vision: {}", model.supports_vision);
//! ```
//!
//! ## Error Handling
//!
//! The SDK provides typed errors with retry information:
//!
//! ```rust,no_run
//! use claude_sdk::{ClaudeClient, MessagesRequest, Message, Error};
//!
//! # async fn example() -> Result<(), Box<dyn std::error::Error>> {
//! let client = ClaudeClient::anthropic(std::env::var("ANTHROPIC_API_KEY")?);
//! let request = MessagesRequest::new(
//! "claude-sonnet-4-5-20250929",
//! 1024,
//! vec![Message::user("Hello!")],
//! );
//!
//! match client.send_message(request).await {
//! Ok(response) => println!("Success!"),
//! Err(Error::RateLimit { retry_after, .. }) => {
//! println!("Rate limited. Retry after: {:?}s", retry_after);
//! }
//! Err(Error::Api { status, message, .. }) => {
//! println!("API error ({}): {}", status, message);
//! }
//! Err(e) => println!("Other error: {}", e),
//! }
//! # Ok(())
//! # }
//! ```
// Re-export main types for convenience
pub use ClaudeClient;
pub use ConversationBuilder;
pub use ;
pub use ;
pub use ;
pub use ;