providers_kit/config/mod.rs
1//! Provider credentials, endpoints, and shared transport policy.
2//!
3//! Build a [`ProviderConfig`] from one [`ProviderKind`] and [`TransportConfig`].
4//! Configuration constructors are passive; [`crate::Provider::from_config`] builds
5//! the selected clients, and subsequent operations check real service behavior.
6//! [`ApiKey`] rejects invalid HTTP-header values and redacts its Debug output.
7//! [`RetryPolicy`] applies only to operations whose existing semantics permit replay.
8
9mod anthropic;
10mod credentials;
11mod gemini;
12mod ollama;
13mod openai;
14mod retry;
15mod transport;
16
17pub use anthropic::AnthropicConfig;
18pub(crate) use anthropic::DEFAULT_ANTHROPIC_VERSION;
19pub use credentials::ApiKey;
20pub use gemini::{GeminiConfig, GeminiServiceTier};
21pub use ollama::OllamaConfig;
22pub use openai::OpenAiConfig;
23pub use retry::RetryPolicy;
24pub use transport::TransportConfig;
25
26/// Concrete provider configuration selected for [`ProviderConfig`].
27///
28/// ```
29/// let kind = providers_kit::config::ProviderKind::Ollama(
30/// providers_kit::config::OllamaConfig::local(),
31/// );
32/// assert!(matches!(kind, providers_kit::config::ProviderKind::Ollama(_)));
33/// ```
34#[derive(Clone)]
35pub enum ProviderKind {
36 /// OpenAI API configuration.
37 OpenAi(OpenAiConfig),
38 /// Anthropic API configuration.
39 Anthropic(AnthropicConfig),
40 /// Gemini API configuration.
41 Gemini(GeminiConfig),
42 /// Ollama local or cloud configuration.
43 Ollama(OllamaConfig),
44}
45
46/// Provider construction input.
47///
48/// Model selection is intentionally absent. Callers select an exact
49/// [`crate::ModelId`] after constructing the provider.
50///
51/// ```
52/// let config = providers_kit::ProviderConfig::new(
53/// providers_kit::config::ProviderKind::Ollama(
54/// providers_kit::config::OllamaConfig::local(),
55/// ),
56/// providers_kit::config::TransportConfig::default(),
57/// );
58/// let _ = config;
59/// ```
60#[derive(Clone)]
61pub struct ProviderConfig {
62 kind: ProviderKind,
63 transport: TransportConfig,
64}
65
66impl ProviderConfig {
67 /// Combines one concrete provider config with shared transport policy.
68 ///
69 /// See [`crate::ProviderConfig`] for a complete example.
70 #[must_use]
71 pub fn new(kind: ProviderKind, transport: TransportConfig) -> Self {
72 Self { kind, transport }
73 }
74
75 pub(crate) fn into_parts(self) -> (ProviderKind, TransportConfig) {
76 (self.kind, self.transport)
77 }
78}