1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
//! # LLM Providers
//!
//! LLM provider clients for OpenAI, Anthropic (Claude), MiniMax, ZAI, Cerebras, OpenRouter, MLX-LM, and LMStudio.
//!
//! This module provides unified access to multiple LLM providers through
//! a common interface. Each provider has a client builder for configuration
//! and a completion model for making requests.
//!
//! ## Providers
//!
//! | Provider | Models | Key Feature |
//! |----------|--------|-------------|
//! | **OpenAI** | GPT-4, GPT-4o, GPT-3.5 | Industry standard, function calling |
//! | **Anthropic** | Claude 3 (Opus, Sonnet, Haiku) | Long context, tool use |
//! | **MiniMax** | MiniMax M2.x | Anthropic-compatible API, interleaved thinking |
//! | **ZAI** | GLM-4.6 | Thinking mode for extended reasoning |
//! | **Cerebras** | Llama models | Fast inference, string-only tool results |
//! | **OpenRouter** | Multi-model | Provider routing (whitelist/blacklist) |
//! | **MLX-LM** | Local MLX models | Apple Silicon, custom chat templates (Minimax) |
//! | **LMStudio** | Local models | Anti-repetition controls, server-side templates |
//! | **Ollama** | Local + cloud models | Native `/api/chat`, thinking traces, one provider for localhost and ollama.com |
//!
//! ## Environment Variables
//!
//! | Variable | Provider | Required |
//! |----------|----------|----------|
//! | `OPENAI_API_KEY` | OpenAI | Yes |
//! | `ANTHROPIC_API_KEY` | Anthropic | Yes |
//! | `MINIMAX_API_KEY` | MiniMax | Yes |
//! | `ZAI_API_KEY` | ZAI | Yes |
//! | `CEREBRAS_API_KEY` | Cerebras | Yes |
//! | `OPENROUTER_API_KEY` | OpenRouter | Yes |
//! | N/A | MLX-LM | No (local server) |
//! | N/A | LMStudio | No (local server) |
//! | `OLLAMA_API_KEY` | Ollama | No for local; yes for cloud (ollama.com) |
//!
//! ## Ollama (native, cloud + local)
//!
//! One provider serves both. Local needs no key; cloud points at
//! `https://ollama.com` with an API key.
//!
//! ```rust,no_run
//! use sombrax_agentic_core::providers::OllamaClientBuilder;
//!
//! // Local
//! let local = OllamaClientBuilder::new()
//! .base_url("http://localhost:11434")
//! .build();
//! let model = local.completion_model("llama3.2");
//!
//! // Cloud
//! let cloud = OllamaClientBuilder::new()
//! .base_url("https://ollama.com")
//! .api_key("your-ollama-api-key")
//! .enable_thinking(true)
//! .build();
//! let model = cloud.completion_model("gpt-oss:120b");
//! ```
//!
//! ## Quick Start
//!
//! ### OpenAI
//!
//! ```rust,no_run
//! use sombrax_agentic_core::providers::OpenAIClientBuilder;
//!
//! let client = OpenAIClientBuilder::new("your-api-key")
//! .temperature(0.7)
//! .build();
//!
//! let model = client.completion_model("gpt-4o");
//! ```
//!
//! ### Anthropic (Claude)
//!
//! ```rust,no_run
//! use sombrax_agentic_core::providers::AnthropicClientBuilder;
//!
//! let client = AnthropicClientBuilder::new("your-api-key")
//! .temperature(0.7)
//! .max_tokens(4096)
//! .build();
//!
//! let model = client.completion_model("claude-3-5-sonnet-20241022");
//! ```
//!
//! ### MiniMax (M2.1)
//!
//! MiniMax uses an Anthropic-compatible API and supports interleaved thinking blocks.
//!
//! ```rust,no_run
//! use sombrax_agentic_core::providers::MinimaxClientBuilder;
//!
//! let client = MinimaxClientBuilder::new("your-api-key")
//! .temperature(0.7)
//! .top_p(0.95)
//! .max_tokens(4096)
//! .build();
//!
//! let model = client.completion_model("minimax-m2.1");
//! ```
//!
//! For local development with MLX-LM server (OpenAI-compatible):
//!
//! ```rust,no_run
//! use sombrax_agentic_core::providers::{MlxLmClientBuilder, ChatTemplate};
//!
//! let client = MlxLmClientBuilder::new()
//! .base_url("http://localhost:1234/v1")
//! .chat_template(ChatTemplate::Minimax)
//! .temperature(0.4)
//! .top_p(0.95)
//! .top_k(20)
//! .build();
//!
//! let model = client.completion_model("MiniMax-M2.1-Q8");
//! ```
//!
//! ### ZAI with Thinking Mode
//!
//! ```rust,no_run
//! use sombrax_agentic_core::providers::ZaiClientBuilder;
//!
//! let client = ZaiClientBuilder::new("api-key")
//! .enable_thinking(true)
//! .build();
//!
//! let model = client.completion_model("glm-4.6");
//! ```
//!
//! ### OpenRouter with Provider Routing
//!
//! ```rust,no_run
//! use sombrax_agentic_core::providers::OpenRouterClientBuilder;
//!
//! let client = OpenRouterClientBuilder::new("api-key")
//! .whitelist(vec!["anthropic".to_string()])
//! .allow_fallbacks(false)
//! .build();
//! ```
//!
//! ## Error Handling
//!
//! All providers use [`ProviderError`] for consistent error handling:
//!
//! - `ProviderError::Authentication` - Invalid API key
//! - `ProviderError::RateLimited` - Rate limit exceeded (with retry hint)
//! - `ProviderError::Http` - HTTP errors with status code
//! - `ProviderError::InvalidResponse` - Malformed response from provider
//!
//! ## Agent Integration
//!
//! All providers can be used with the `Agent` framework via adapters:
//!
//! ```rust,no_run
//! use sombrax_agentic_core::providers::{ZaiClientBuilder, ZaiClientExt};
//! use sombrax_agentic_core::AgentBuilder;
//!
//! let client = ZaiClientBuilder::new("api-key").build();
//! // Get an adapter that implements CompletionModel
//! let model = client.completion_model_adapter("glm-4.6");
//!
//! // Use with Agent framework
//! let agent = AgentBuilder::new(model).build();
//! ```
// Re-export main types
pub use ProviderError;
// Re-export OpenAI
pub use ;
// Re-export Anthropic
pub use ;
// Re-export MiniMax
pub use ;
// Re-export ZAI
pub use ;
// Re-export Cerebras
pub use ;
// Re-export OpenRouter
pub use ;
// Re-export LMStudio
pub use ;
// Re-export Ollama (native /api/chat — cloud + local)
pub use ;
// Re-export MLX-LM
pub use ;
// Re-export adapters for CompletionModel trait support
pub use ;
// Re-export provider type and config
pub use LlmConfigLike;
pub use ;
// Re-export builder functions
pub use ;