anthropic_async/lib.rs
1#![deny(warnings)]
2#![deny(clippy::all)]
3#![deny(missing_docs)]
4
5//! # `anthropic-async`
6//!
7//! A production-ready Anthropic API client for Rust with prompt caching support.
8//!
9//! ## Quick Start
10//!
11//! ```no_run
12//! use anthropic_async::{Client, types::{content::*, messages::*}};
13//!
14//! # async fn example() -> Result<(), Box<dyn std::error::Error>> {
15//! let client = Client::new();
16//!
17//! let req = MessagesCreateRequest {
18//! model: "claude-3-5-sonnet".into(),
19//! max_tokens: 100,
20//! messages: vec![MessageParam {
21//! role: MessageRole::User,
22//! content: "Hello!".into(),
23//! }],
24//! system: None,
25//! temperature: None,
26//! stop_sequences: None,
27//! top_p: None,
28//! top_k: None,
29//! metadata: None,
30//! tools: None,
31//! tool_choice: None,
32//! stream: None,
33//! output_format: None,
34//! };
35//!
36//! let response = client.messages().create(req).await?;
37//! # Ok(())
38//! # }
39//! ```
40//!
41//! ## Authentication
42//!
43//! The client supports API key and bearer token authentication.
44//! See [`AnthropicConfig`] for configuration options.
45//!
46//! ## Prompt Caching
47//!
48//! Use [`CacheControl`](types::common::CacheControl) to cache prompts and reduce costs.
49
50/// HTTP client implementation
51pub mod client;
52/// Configuration types for the client
53pub mod config;
54/// Error types
55pub mod error;
56/// API resource implementations
57pub mod resources;
58/// Retry logic utilities
59pub mod retry;
60/// Server-sent events (streaming) support
61#[cfg(feature = "streaming")]
62pub mod sse;
63/// Hidden SSE module when streaming is not enabled
64#[cfg(not(feature = "streaming"))]
65pub(crate) mod sse;
66/// Test support utilities (for use in tests)
67#[doc(hidden)]
68pub mod test_support;
69/// Request and response types
70pub mod types;
71
72pub use crate::client::Client;
73pub use crate::config::{AnthropicAuth, AnthropicConfig, BetaFeature};
74pub use crate::error::{AnthropicError, ApiErrorObject};
75
76/// Streaming types (requires `streaming` feature)
77#[cfg(feature = "streaming")]
78pub mod streaming {
79 pub use crate::sse::streaming::{
80 Accumulator, ContentBlockDeltaData, ContentBlockStartData, Event, EventError, EventStream,
81 MessageDeltaPayload, MessageDeltaUsage, MessageStartPayload, MessageStartUsage, SSEDecoder,
82 SseFrame, event_stream_from_response,
83 };
84}
85
86/// Prelude module for convenient imports
87pub mod prelude {
88 pub use crate::types::common::*;
89 pub use crate::types::messages::*;
90 pub use crate::types::models::*;
91 pub use crate::{AnthropicConfig, Client};
92}