llmkit_tower/lib.rs
1//! Tower-style middleware for `llmkit-rs`.
2//!
3//! Each layer wraps an [`llmkit_core::LlmProvider`] and is itself a provider, so
4//! they compose into a single `Arc<dyn LlmProvider>` without `Service<Request>`
5//! generics or sprawling `where` clauses. Layers:
6//!
7//! - [`RetryLayer`] — exponential backoff over retryable errors
8//! - [`RateLimitLayer`] — token-bucket throttling per provider
9//! - [`CostTrackingLayer`] — per-request + cumulative cost, optional budget cap
10//! - [`TracingLayer`] — structured spans with latency and token counts
11//!
12//! [`FallbackProvider`] chains providers primary → secondary on failure.
13
14#![forbid(unsafe_code)]
15#![deny(missing_docs)]
16
17mod cost;
18mod fallback;
19mod layer;
20mod rate_limit;
21mod retry;
22mod tracing;
23
24pub use cost::{CostTracking, CostTrackingLayer, SessionCost};
25pub use fallback::FallbackProvider;
26pub use layer::LlmLayer;
27pub use rate_limit::{RateLimit, RateLimitLayer};
28pub use retry::{Retry, RetryLayer};
29pub use tracing::{Tracing, TracingLayer};