Skip to main content

cognate_providers/
lib.rs

1//! Cognate Providers — concrete LLM provider implementations.
2//!
3//! # Providers
4//!
5//! | Provider | Struct | Chat | Stream | Tools | Embeddings |
6//! |----------|--------|------|--------|-------|------------|
7//! | OpenAI   | [`OpenAiProvider`] | ✓ | ✓ | ✓ | ✓ |
8//! | Anthropic | [`AnthropicProvider`] | ✓ | ✓ | ✓ | — |
9//!
10//! # Resilience
11//!
12//! * All providers have built-in exponential-backoff retry via [`RetryConfig`].
13//! * Token-bucket rate limiting is available on [`OpenAiProvider`] and
14//!   [`AnthropicProvider`].
15//! * [`FallbackProvider`] transparently retries with a secondary provider on
16//!   any retryable error.
17#![warn(missing_docs)]
18
19use std::time::Duration;
20
21pub mod anthropic;
22pub mod costs;
23pub mod fallback;
24pub mod openai;
25pub mod retry;
26pub mod sse;
27
28pub use anthropic::AnthropicProvider;
29pub use costs::ModelCost;
30pub use fallback::FallbackProvider;
31pub use openai::OpenAiProvider;
32pub use retry::{with_retry, RetryConfig};
33pub use sse::SseStream;
34
35/// Default request timeout applied when no explicit timeout is configured.
36pub const DEFAULT_TIMEOUT: Duration = Duration::from_secs(60);
37
38/// Build a `reqwest` client with standard Cognate defaults.
39pub fn create_http_client(timeout: Duration) -> cognate_core::Result<reqwest::Client> {
40    reqwest::Client::builder()
41        .timeout(timeout)
42        .build()
43        .map_err(|e| cognate_core::Error::Configuration(e.to_string()))
44}