Skip to main content

aimux_providers/
lib.rs

1//! # aimux-providers
2//!
3//! LLM provider implementations for aimux.
4//!
5//! Each provider implements the `LanguageModel` trait from `aimux-core`.
6
7/// One required `Provider` method that this vendor does not offer: returns
8/// `NoSuchModel` with the AI SDK `modelType`.
9#[doc(hidden)]
10#[macro_export]
11macro_rules! __unsupported_required_model {
12    ($method:ident, $trait:ident, $model_type:literal) => {
13        fn $method(
14            &self,
15            id: &str,
16        ) -> ::std::result::Result<
17            ::std::sync::Arc<dyn ::aimux_core::$trait>,
18            ::aimux_core::AiMuxError,
19        > {
20            ::std::result::Result::Err(::aimux_core::AiMuxError::no_such_model(id, $model_type))
21        }
22    };
23}
24
25/// Emit `impl Provider for $ty` for a vendor that offers exactly one modality.
26///
27/// The first argument after the type names the `Provider` method to wire
28/// (`language_model`, `embedding_model`, `image_model`, `transcription_model`,
29/// `speech_model`, `reranking_model`, `video_model` or `search_model`); the
30/// closure-like tail binds the provider and the model id and evaluates to the
31/// (infallible) concrete model. The two other required methods return
32/// `NoSuchModel`; the other optional ones keep their `None` default.
33///
34/// ```ignore
35/// impl_single_modality_provider!(VllmProvider, language_model, |p, id| p.model(id));
36/// impl_single_modality_provider!(SerperProvider, search_model, |p, _id| p.search_model());
37/// ```
38#[macro_export]
39macro_rules! impl_single_modality_provider {
40    ($ty:ty, language_model, |$p:ident, $id:ident| $build:expr) => {
41        impl ::aimux_core::Provider for $ty {
42            fn language_model(
43                &self,
44                $id: &str,
45            ) -> ::std::result::Result<
46                ::std::sync::Arc<dyn ::aimux_core::LanguageModel>,
47                ::aimux_core::AiMuxError,
48            > {
49                let $p = self;
50                ::std::result::Result::Ok(::std::sync::Arc::new($build))
51            }
52            $crate::__unsupported_required_model!(
53                embedding_model,
54                EmbeddingModel,
55                "embeddingModel"
56            );
57            $crate::__unsupported_required_model!(image_model, ImageModel, "imageModel");
58        }
59    };
60    ($ty:ty, embedding_model, |$p:ident, $id:ident| $build:expr) => {
61        impl ::aimux_core::Provider for $ty {
62            $crate::__unsupported_required_model!(language_model, LanguageModel, "languageModel");
63            fn embedding_model(
64                &self,
65                $id: &str,
66            ) -> ::std::result::Result<
67                ::std::sync::Arc<dyn ::aimux_core::EmbeddingModel>,
68                ::aimux_core::AiMuxError,
69            > {
70                let $p = self;
71                ::std::result::Result::Ok(::std::sync::Arc::new($build))
72            }
73            $crate::__unsupported_required_model!(image_model, ImageModel, "imageModel");
74        }
75    };
76    ($ty:ty, image_model, |$p:ident, $id:ident| $build:expr) => {
77        impl ::aimux_core::Provider for $ty {
78            $crate::__unsupported_required_model!(language_model, LanguageModel, "languageModel");
79            $crate::__unsupported_required_model!(
80                embedding_model,
81                EmbeddingModel,
82                "embeddingModel"
83            );
84            fn image_model(
85                &self,
86                $id: &str,
87            ) -> ::std::result::Result<
88                ::std::sync::Arc<dyn ::aimux_core::ImageModel>,
89                ::aimux_core::AiMuxError,
90            > {
91                let $p = self;
92                ::std::result::Result::Ok(::std::sync::Arc::new($build))
93            }
94        }
95    };
96    ($ty:ty, $method:ident, |$p:ident, $id:ident| $build:expr) => {
97        impl ::aimux_core::Provider for $ty {
98            $crate::__unsupported_required_model!(language_model, LanguageModel, "languageModel");
99            $crate::__unsupported_required_model!(
100                embedding_model,
101                EmbeddingModel,
102                "embeddingModel"
103            );
104            $crate::__unsupported_required_model!(image_model, ImageModel, "imageModel");
105            $crate::__optional_model!($method, |$p, $id| $build);
106        }
107    };
108}
109
110/// One optional `Provider` method wired to a concrete model (see
111/// [`impl_single_modality_provider!`]).
112#[doc(hidden)]
113#[macro_export]
114macro_rules! __optional_model {
115    (transcription_model, |$p:ident, $id:ident| $build:expr) => {
116        $crate::__optional_model!(@emit transcription_model, TranscriptionModel, |$p, $id| $build);
117    };
118    (speech_model, |$p:ident, $id:ident| $build:expr) => {
119        $crate::__optional_model!(@emit speech_model, SpeechModel, |$p, $id| $build);
120    };
121    (reranking_model, |$p:ident, $id:ident| $build:expr) => {
122        $crate::__optional_model!(@emit reranking_model, RerankingModel, |$p, $id| $build);
123    };
124    (video_model, |$p:ident, $id:ident| $build:expr) => {
125        $crate::__optional_model!(@emit video_model, VideoModel, |$p, $id| $build);
126    };
127    (search_model, |$p:ident, $id:ident| $build:expr) => {
128        $crate::__optional_model!(@emit search_model, SearchModel, |$p, $id| $build);
129    };
130    (@emit $method:ident, $trait:ident, |$p:ident, $id:ident| $build:expr) => {
131        fn $method(
132            &self,
133            $id: &str,
134        ) -> ::std::option::Option<
135            ::std::result::Result<
136                ::std::sync::Arc<dyn ::aimux_core::$trait>,
137                ::aimux_core::AiMuxError,
138            >,
139        > {
140            let $p = self;
141            ::std::option::Option::Some(::std::result::Result::Ok(::std::sync::Arc::new($build)))
142        }
143    };
144}
145
146pub mod replay;
147pub use preset::{AuthMode, PresetDescriptor, PresetEntry, PresetSettings};
148pub use replay::{rebuild_decision_provider, rebuild_provider};
149
150pub mod catalogue;
151pub use catalogue::{Catalogue, get_model_specs};
152
153pub mod anthropic;
154pub mod anthropic_aws;
155pub mod azure;
156pub mod bedrock;
157pub mod cohere;
158pub mod deepseek;
159mod default_providers;
160pub mod google;
161pub mod groq;
162pub mod jev;
163pub use jev::{JevConfig, JevDecisionModel, JevProvider};
164pub mod mistral;
165pub mod openai;
166pub mod openai_compatible;
167pub use default_providers::{
168    create_provider, default_providers, provider_api_key_env, provider_default_base_url,
169    provider_names,
170};
171pub mod preset;
172pub(crate) mod shared;
173pub(crate) mod stream;
174pub mod vertex;
175pub mod voyage;
176
177pub mod codex;
178pub mod xai;
179
180pub mod huggingface;
181
182// Speech-only providers (TTS).
183pub mod cartesia;
184pub mod elevenlabs;
185pub mod hume;
186pub mod lmnt;
187
188// Transcription-only providers (STT).
189pub mod assemblyai;
190pub mod deepgram;
191pub mod fal;
192pub mod gladia;
193pub mod revai;
194
195// Image-only providers.
196pub mod black_forest_labs;
197pub mod luma;
198pub mod prodia;
199pub mod replicate;
200
201// Video-only providers.
202pub mod klingai;
203
204// Generic Responses API wrapper.
205pub mod open_responses;
206
207// Unified logging entry point (RFC-0014) — re-export from provider-utils so
208// Rust consumers and the FFI layer share one implementation.
209pub use aimux_provider_utils::logging::init_logging;
210
211pub use anthropic::{
212    AnthropicMessagesModel, AnthropicProvider, AnthropicProviderSettings, create_anthropic,
213};
214pub use anthropic_aws::{
215    AnthropicAwsAuth, AnthropicAwsProvider, AnthropicAwsProviderSettings, create_anthropic_aws,
216};
217pub use azure::{
218    AzureChatModel, AzureOpenAIProvider, AzureOpenAIProviderSettings, AzureOpenAITools,
219    AzureResponsesModel, azure, create_azure,
220};
221pub use bedrock::{
222    AmazonBedrockProvider, AmazonBedrockProviderSettings, BedrockEmbeddingModel, BedrockImageModel,
223    BedrockModel, BedrockRerankingModel, amazon_bedrock, create_amazon_bedrock,
224};
225pub use cohere::{
226    CohereEmbeddingModel, CohereModel, CohereProvider, CohereProviderSettings,
227    CohereRerankingModel, cohere, create_cohere,
228};
229pub use google::{
230    GoogleEmbeddingModel, GoogleFiles, GoogleImageModel, GoogleImageSettings, GoogleModel,
231    GoogleProvider, GoogleProviderSettings, GoogleSpeechModel, GoogleTranscriptionModel,
232    GoogleVideoModel, create_google, google,
233};
234pub use mistral::{
235    MistralEmbeddingModel, MistralModel, MistralProvider, MistralProviderSettings,
236    MistralSpeechModel, MistralTranscriptionModel, create_mistral, mistral,
237};
238pub use openai::{
239    OpenAIDecisionModel, OpenAIEmbeddingModel, OpenAIImageModel, OpenAIProvider,
240    OpenAIProviderSettings, OpenAIResponsesModel, OpenAISpeechModel, OpenAITranscriptionModel,
241    create_openai,
242};
243pub use vertex::{
244    GoogleAuthOptions, GoogleAuthScopes, VertexAnthropicModel, VertexAnthropicProvider,
245    VertexAnthropicProviderSettings, VertexEmbeddingModel, VertexImageModel,
246    VertexMaasProviderSettings, VertexModel, VertexPartnerProviderSettings, VertexProvider,
247    VertexProviderSettings, VertexTranscriptionModel, VertexVideoModel, VertexXaiProvider,
248    VertexXaiProviderSettings, create_google_vertex, create_google_vertex_anthropic,
249    create_google_vertex_maas, create_google_vertex_xai, google_vertex, google_vertex_anthropic,
250    google_vertex_maas, google_vertex_xai,
251};
252pub use voyage::{
253    VoyageEmbeddingModel, VoyageProvider, VoyageProviderSettings, VoyageRerankingModel,
254    create_voyage, voyage,
255};
256
257pub use codex::{
258    CODEX_API_BASE_URL, CODEX_API_KEY_ENV_VAR, CODEX_OAUTH_TOKEN_URL, CODEX_SUBSCRIPTION_BASE_URL,
259    CodexMode, CodexModel, CodexProvider, CodexProviderSettings, CodexTokens, codex, codex_refresh,
260    codex_refresh_at, create_codex,
261};
262pub use xai::{
263    XAIProvider, XAIProviderSettings, XaiResponsesModel, XaiSpeechModel, XaiTranscriptionModel,
264    XaiVideoModel, create_xai, xai,
265};
266
267pub use cartesia::{
268    CartesiaProvider, CartesiaProviderSettings, CartesiaSpeechModel, CartesiaTranscriptionModel,
269    cartesia, create_cartesia,
270};
271pub use elevenlabs::{
272    ElevenLabsProvider, ElevenLabsProviderSettings, ElevenLabsSpeechModel,
273    ElevenLabsTranscriptionModel, create_elevenlabs, elevenlabs,
274};
275pub use huggingface::{
276    HuggingFaceProvider, HuggingFaceProviderSettings, HuggingFaceResponsesModel,
277    create_huggingface, huggingface,
278};
279pub use hume::{HumeProvider, HumeProviderSettings, HumeSpeechModel, create_hume, hume};
280pub use lmnt::{LMNTProvider, LMNTProviderSettings, LMNTSpeechModel, create_lmnt, lmnt};
281
282pub use assemblyai::{
283    AssemblyAIProvider, AssemblyAIProviderSettings, AssemblyAITranscriptionModel, assemblyai,
284    create_assemblyai,
285};
286pub use deepgram::{
287    DeepgramProvider, DeepgramProviderSettings, DeepgramTranscriptionModel, create_deepgram,
288    deepgram,
289};
290pub use fal::{
291    FalImageModel, FalProvider, FalProviderSettings, FalTranscriptionModel, FalVideoModel,
292    create_fal, fal,
293};
294
295// Image-only provider re-exports.
296pub use black_forest_labs::{
297    BlackForestLabsImageModel, BlackForestLabsProvider, BlackForestLabsProviderSettings,
298    black_forest_labs, create_black_forest_labs,
299};
300pub use gladia::{
301    GladiaProvider, GladiaProviderSettings, GladiaTranscriptionModel, create_gladia, gladia,
302};
303pub use klingai::{
304    KlingAIProvider, KlingAIProviderSettings, KlingAIVideoModel, create_klingai, klingai,
305};
306pub use luma::{LumaImageModel, LumaProvider, LumaProviderSettings, create_luma, luma};
307pub use prodia::{
308    ProdiaImageModel, ProdiaProvider, ProdiaProviderSettings, ProdiaVideoModel, create_prodia,
309    prodia,
310};
311pub use replicate::{
312    ReplicateImageModel, ReplicateProvider, ReplicateProviderSettings, ReplicateVideoModel,
313    create_replicate, replicate,
314};
315pub use revai::{
316    RevaiProvider, RevaiProviderSettings, RevaiTranscriptionModel, create_revai, revai,
317};
318
319pub use open_responses::{
320    OpenResponsesModel, OpenResponsesProvider, OpenResponsesProviderSettings, create_open_responses,
321};
322
323// Modality-specific providers (non-language, e.g. rerank-only).
324pub mod jina_ai;
325pub use jina_ai::{
326    JinaAiProvider, JinaAiProviderSettings, JinaAiRerankingModel, create_jina_ai, jina_ai,
327};
328
329// AWS Polly speech (TTS) provider — SigV4 authenticated, speech modality only.
330pub mod aws_polly;
331pub use aws_polly::{
332    AwsPollyProvider, AwsPollyProviderSettings, AwsPollySpeechModel, aws_polly, create_aws_polly,
333};
334
335// Recraft image provider (OpenAI Images-compatible + Recraft extension fields).
336pub mod recraft;
337pub use recraft::{
338    RecraftImageModel, RecraftProvider, RecraftProviderSettings, create_recraft, recraft,
339};
340
341// Stability image provider (image modality only).
342pub mod stability;
343pub use stability::{
344    StabilityImageModel, StabilityProvider, StabilityProviderSettings, create_stability, stability,
345};
346
347// Video-only provider (runwayml).
348pub mod runwayml;
349pub use runwayml::{
350    RunwaymlProvider, RunwaymlProviderSettings, RunwaymlVideoModel, create_runwayml, runwayml,
351};
352
353// Search-only providers (web search modality).
354pub mod dataforseo;
355pub mod exa_ai;
356pub mod firecrawl;
357pub mod google_pse;
358pub mod linkup;
359pub mod parallel_ai;
360pub mod searxng;
361pub mod serper;
362pub mod tavily;
363pub mod tinyfish;
364pub mod you_com;
365
366pub use dataforseo::{
367    DataforseoProvider, DataforseoProviderSettings, DataforseoSearchModel, create_dataforseo,
368    dataforseo,
369};
370pub use exa_ai::{ExaAiProvider, ExaAiProviderSettings, ExaAiSearchModel, create_exa_ai, exa_ai};
371pub use firecrawl::{
372    FirecrawlProvider, FirecrawlProviderSettings, FirecrawlSearchModel, create_firecrawl, firecrawl,
373};
374pub use google_pse::{
375    GooglePseProvider, GooglePseProviderSettings, GooglePseSearchModel, create_google_pse,
376    google_pse,
377};
378pub use linkup::{
379    LinkupProvider, LinkupProviderSettings, LinkupSearchModel, create_linkup, linkup,
380};
381pub use parallel_ai::{
382    ParallelAiProvider, ParallelAiProviderSettings, ParallelAiSearchModel, create_parallel_ai,
383    parallel_ai,
384};
385pub use searxng::{
386    SearxngProvider, SearxngProviderSettings, SearxngSearchModel, create_searxng, searxng,
387};
388pub use serper::{
389    SerperProvider, SerperProviderSettings, SerperSearchModel, create_serper, serper,
390};
391pub use tavily::{
392    TavilyProvider, TavilyProviderSettings, TavilySearchModel, create_tavily, tavily,
393};
394pub use tinyfish::{
395    TinyfishProvider, TinyfishProviderSettings, TinyfishSearchModel, create_tinyfish, tinyfish,
396};
397pub use you_com::{
398    YouComProvider, YouComProviderSettings, YouComSearchModel, create_you_com, you_com,
399};
400
401mod decision_scoring;
402mod decision_support;
403pub use decision_support::DecisionProbabilitySource;
404mod runtime_decision;
405mod systemone;
406
407#[cfg(test)]
408mod test_support;