Skip to main content

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//!     ..Default::default()
25//! };
26//!
27//! let response = client.messages().create(req).await?;
28//! # Ok(())
29//! # }
30//! ```
31//!
32//! ## Authentication
33//!
34//! The client supports API key and bearer token authentication.
35//! See [`AnthropicConfig`] for configuration options.
36//!
37//! ## Prompt Caching
38//!
39//! Use [`CacheControl`](types::common::CacheControl) to cache prompts and reduce costs.
40
41/// HTTP client implementation
42pub mod client;
43/// Configuration types for the client
44pub mod config;
45/// Error types
46pub mod error;
47/// API resource implementations
48pub mod resources;
49/// Retry logic utilities
50pub mod retry;
51/// Server-sent events (streaming) support
52#[cfg(feature = "streaming")]
53pub mod sse;
54/// Hidden SSE module when streaming is not enabled
55#[cfg(not(feature = "streaming"))]
56pub(crate) mod sse;
57/// Test support utilities (for use in tests)
58#[doc(hidden)]
59pub mod test_support;
60/// Request and response types
61pub mod types;
62
63pub use crate::client::Client;
64pub use crate::config::{AnthropicAuth, AnthropicConfig, BetaFeature};
65pub use crate::error::{AnthropicError, ApiErrorObject};
66
67/// Streaming types (requires `streaming` feature)
68#[cfg(feature = "streaming")]
69pub mod streaming {
70    pub use crate::sse::streaming::{
71        Accumulator, ContentBlockDeltaData, ContentBlockStartData, Event, EventError, EventStream,
72        MessageDeltaPayload, MessageDeltaUsage, MessageStartPayload, MessageStartUsage, SSEDecoder,
73        SseFrame, event_stream_from_response,
74    };
75}
76
77/// Prelude module for convenient imports
78pub mod prelude {
79    pub use crate::types::common::*;
80    pub use crate::types::messages::*;
81    pub use crate::types::models::*;
82    pub use crate::{AnthropicConfig, Client};
83}