Skip to main content

oxi_ai/
lib.rs

1#![allow(unused_doc_comments)]
2#![warn(missing_docs)]
3#![warn(clippy::unwrap_used)]
4
5//! oxi-ai: Unified LLM API for oxi
6//!
7//! This crate provides a unified interface for interacting with multiple LLM providers.
8//! It handles streaming, tool calling, context management, and cross-provider handoffs.
9
10pub mod circuit_breaker;
11mod compaction;
12mod complexity_router;
13mod context;
14pub mod env_api_keys;
15mod error;
16mod high_level;
17mod messages;
18pub mod oauth;
19pub mod provider_pool;
20pub mod provider_registry;
21mod providers;
22
23#[allow(missing_docs)]
24pub mod register_builtins {
25    pub use crate::providers::register_builtins::*;
26}
27pub mod router;
28pub mod secret;
29mod tools;
30mod transform;
31pub mod types;
32pub mod utils;
33
34/// Standard imports for oxi-ai usage.
35pub mod prelude {
36    pub use crate::compaction::generate_branch_summary;
37    pub use crate::compaction::{
38        CompactedContext, CompactionManager, CompactionStrategy, Compactor, LlmCompactor,
39    };
40    pub use crate::context::Context;
41    pub use crate::error::{Error, Result};
42    pub use crate::messages::*;
43    pub use crate::providers::{Provider, ProviderEvent, StreamOptions};
44    pub use crate::tools::{validate_args, Tool};
45    pub use crate::types::*;
46}
47
48// Re-export main types
49
50/// Provider-specific error type for LLM operations.
51pub use crate::error::ProviderError;
52
53/// Shared conversation context.
54pub use context::Context;
55
56/// Result type alias for oxi-ai operations.
57pub use error::{Error, Result};
58
59/// Message types for constructing conversations.
60pub use messages::*;
61
62/// Cache retention control for provider requests.
63pub use providers::CacheRetention;
64
65/// Provider trait, streaming options, and provider registry.
66pub use providers::{
67    custom_provider_names, get_provider, get_provider_arc, register_provider, unregister_provider,
68    Provider, ProviderEvent, ProviderOptions, ProviderRegistry, StreamOptions,
69};
70
71/// Built-in provider helpers (re-exported from providers).
72pub use providers::register_builtins::{
73    create_builtin_provider, create_builtin_provider_with_options, get_all_provider_names,
74    get_builtin_provider, get_provider_env_key, get_provider_env_keys, is_builtin_provider,
75};
76
77/// OpenAI-compatible provider implementation.
78pub use providers::OpenAiProvider;
79
80/// Anthropic provider implementation.
81pub use providers::AnthropicProvider;
82/// Azure OpenAI provider implementation.
83pub use providers::AzureProvider;
84
85/// Model fetching utilities (async and blocking).
86pub use providers::model_fetch::{fetch_models_async, fetch_models_blocking};
87
88/// OpenAI Responses API provider.
89pub use providers::OpenAiResponsesProvider;
90
91/// AWS Bedrock provider implementation.
92pub use providers::BedrockProvider;
93/// Google (Gemini) provider implementation.
94pub use providers::GoogleProvider;
95/// Mistral provider implementation.
96pub use providers::MistralProvider;
97/// Google Vertex AI provider implementation.
98pub use providers::VertexProvider;
99
100/// Provider-specific message normalization (empty content filtering, tool ID
101/// scrubbing, reasoning injection, tool-use ordering fix).
102pub use providers::normalize_messages;
103
104/// Tool definition and argument validation.
105pub use tools::{progress_callback, validate_args, ProgressCallback, Tool, ToolValidationError};
106
107pub use compaction::generate_branch_summary;
108/// Core type definitions (tokens, cost, etc.).
109pub use types::*;
110
111// High-level API
112
113/// Token estimation and context usage helpers.
114pub use high_level::tokens::{context_usage, estimate, estimate_words};
115
116/// High-level completion and token estimation.
117pub use high_level::{complete, estimate_tokens};
118
119// Context compaction
120
121/// Compaction strategies and managers for long conversations.
122pub use compaction::{
123    CompactedContext, CompactionManager, CompactionStrategy, Compactor, LlmCompactor,
124};
125
126// Complexity-based routing
127
128/// Complexity-based model routing.
129pub use complexity_router::{ComplexityRouter, DefaultRouter};
130
131// Cross-provider message transformation
132
133/// Message transformation between provider formats.
134pub use transform::{
135    anthropic_to_google, anthropic_to_openai, google_to_openai, normalize_tool_call_id,
136    openai_to_anthropic, transform_messages, transform_messages_for_model, TransformOptions,
137};
138
139// Multi-provider routing
140
141/// MultiProvider for intelligent routing with fallback support.
142pub mod multi_provider;
143
144/// Re-exports for multi_provider convenience.
145pub use multi_provider::MultiProvider;
146
147// Model registry (runtime mutable registry)
148mod model_registry;
149
150/// Runtime model registry for dynamically registered models.
151///
152/// Unlike the static `model_db`, this supports adding/removing models at runtime.
153pub use model_registry::{
154    dynamic_models, get_model, get_models, get_providers, lookup_model, register_model,
155    unregister_model, ModelRegistry,
156};
157
158// Static model database (comprehensive)
159pub mod model_db;
160
161/// Static database of known models with cost and modality info.
162///
163/// Provides comprehensive model listings, filtering, and search capabilities.
164pub use model_db::{
165    get_all_models, get_cheapest_models, get_model_entry, get_provider_models,
166    get_reasoning_models, get_vision_models, model_count, search_models, ModelEntry,
167};
168
169// Fallback chain for ordered model failover
170pub mod fallback_chain;
171
172/// Ordered fallback chain for model failover on failure.
173pub use fallback_chain::{FallbackChain, FallbackChainError};
174
175// Partial response for stream recovery
176pub mod partial_response;
177
178/// Partial response accumulator for stream recovery.
179pub use partial_response::PartialResponse;
180
181// Circuit breaker for provider health tracking
182/// Per-provider circuit breaker for health tracking.
183pub use circuit_breaker::{CircuitBreakerConfig, CircuitOpenError, ProviderCircuitBreaker};
184
185/// Re-export AssistantMessage from messages
186pub use messages::AssistantMessage;
187
188// Environment-based API key resolution
189
190/// Utilities for discovering API keys from the environment.
191pub use env_api_keys::{find_env_keys, get_all_env_keys, get_env_api_key};
192
193// Provider authentication registry
194
195/// OAuth token and API key management for providers.
196pub use provider_registry::{OAuthTokenInfo, ProviderAuth, ProviderAuthRegistry};