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 secret;
28mod tools;
29mod transform;
30mod types;
31pub mod utils;
32
33/// Standard imports for oxi-ai usage.
34pub mod prelude {
35    pub use crate::compaction::{
36        CompactedContext, CompactionManager, CompactionStrategy, Compactor, LlmCompactor,
37    };
38    pub use crate::context::Context;
39    pub use crate::error::{Error, Result};
40    pub use crate::messages::*;
41    pub use crate::providers::{Provider, ProviderEvent, StreamOptions};
42    pub use crate::tools::{validate_args, Tool};
43    pub use crate::types::*;
44}
45
46// Re-export main types
47
48/// Provider-specific error type for LLM operations.
49pub use crate::error::ProviderError;
50
51/// Shared conversation context.
52pub use context::Context;
53
54/// Result type alias for oxi-ai operations.
55pub use error::{Error, Result};
56
57/// Message types for constructing conversations.
58pub use messages::*;
59
60/// Cache retention control for provider requests.
61pub use providers::CacheRetention;
62
63/// Provider trait, streaming options, and provider registry.
64pub use providers::{
65    custom_provider_names, get_provider, register_provider, unregister_provider, Provider,
66    ProviderEvent, ProviderRegistry, StreamOptions,
67};
68
69/// Built-in provider helpers (re-exported from providers).
70pub use providers::register_builtins::{
71    create_builtin_provider, get_all_provider_names, get_builtin_provider, get_provider_env_key,
72    get_provider_env_keys, is_builtin_provider,
73};
74
75/// OpenAI-compatible provider implementation.
76pub use providers::OpenAiProvider;
77
78/// Model fetching utilities (async and blocking).
79pub use providers::model_fetch::{fetch_models_async, fetch_models_blocking};
80
81/// OpenAI Responses API provider.
82pub use providers::OpenAiResponsesProvider;
83
84/// Tool definition and argument validation.
85pub use tools::{progress_callback, validate_args, ProgressCallback, Tool, ToolValidationError};
86
87/// Core type definitions (tokens, cost, etc.).
88pub use types::*;
89
90// High-level API
91
92/// Token estimation and context usage helpers.
93pub use high_level::tokens::{context_usage, estimate, estimate_words};
94
95/// High-level completion and token estimation.
96pub use high_level::{complete, estimate_tokens};
97
98// Context compaction
99
100/// Compaction strategies and managers for long conversations.
101pub use compaction::{
102    CompactedContext, CompactionManager, CompactionStrategy, Compactor, LlmCompactor,
103};
104
105// Complexity-based routing
106
107/// Complexity-based model routing.
108pub use complexity_router::{ComplexityRouter, DefaultRouter};
109
110// Cross-provider message transformation
111
112/// Message transformation between provider formats.
113pub use transform::{
114    anthropic_to_google, anthropic_to_openai, google_to_openai, normalize_tool_call_id,
115    openai_to_anthropic, transform_messages, transform_messages_for_model, TransformOptions,
116};
117
118// Multi-provider routing
119
120/// MultiProvider for intelligent routing with fallback support.
121pub mod multi_provider;
122
123/// Re-exports for multi_provider convenience.
124pub use multi_provider::MultiProvider;
125
126// Model registry (runtime mutable registry)
127mod model_registry;
128
129/// Runtime model registry for dynamically registered models.
130///
131/// Unlike the static `model_db`, this supports adding/removing models at runtime.
132pub use model_registry::{
133    get_model, get_models, get_providers, lookup_model, register_model, unregister_model,
134    ModelRegistry,
135};
136
137// Static model database (comprehensive)
138pub mod model_db;
139
140/// Static database of known models with cost and modality info.
141///
142/// Provides comprehensive model listings, filtering, and search capabilities.
143pub use model_db::{
144    get_all_models, get_cheapest_models, get_model_entry, get_provider_models,
145    get_reasoning_models, get_vision_models, model_count, search_models, ModelEntry,
146};
147
148// Fallback chain for ordered model failover
149pub mod fallback_chain;
150
151/// Ordered fallback chain for model failover on failure.
152pub use fallback_chain::{FallbackChain, FallbackChainError};
153
154// Partial response for stream recovery
155pub mod partial_response;
156
157/// Partial response accumulator for stream recovery.
158pub use partial_response::PartialResponse;
159
160// Circuit breaker for provider health tracking
161/// Per-provider circuit breaker for health tracking.
162pub use circuit_breaker::{CircuitBreakerConfig, CircuitOpenError, ProviderCircuitBreaker};
163
164/// Re-export AssistantMessage from messages
165pub use messages::AssistantMessage;
166
167// Environment-based API key resolution
168
169/// Utilities for discovering API keys from the environment.
170pub use env_api_keys::{find_env_keys, get_all_env_keys, get_env_api_key};
171
172// Provider authentication registry
173
174/// OAuth token and API key management for providers.
175pub use provider_registry::{OAuthTokenInfo, ProviderAuth, ProviderAuthRegistry};