Expand description
oxi-ai: Unified LLM API for oxi
This crate provides a unified interface for interacting with multiple LLM providers. It handles streaming, tool calling, context management, and cross-provider handoffs.
Re-exports§
pub use multi_provider::MultiProvider;pub use model_db::get_all_models;pub use model_db::get_cheapest_models;pub use model_db::get_model_entry;pub use model_db::get_provider_models;pub use model_db::get_reasoning_models;pub use model_db::get_vision_models;pub use model_db::model_count;pub use model_db::search_models;pub use model_db::ModelEntry;pub use fallback_chain::FallbackChain;pub use fallback_chain::FallbackChainError;pub use partial_response::PartialResponse;pub use circuit_breaker::CircuitBreakerConfig;pub use circuit_breaker::CircuitOpenError;pub use circuit_breaker::ProviderCircuitBreaker;pub use env_api_keys::find_env_keys;pub use env_api_keys::get_all_env_keys;pub use env_api_keys::get_env_api_key;pub use provider_registry::OAuthTokenInfo;pub use provider_registry::ProviderAuth;pub use provider_registry::ProviderAuthRegistry;
Modules§
- circuit_
breaker - Per-provider circuit breaker implementation.
- env_
api_ keys - Environment variable-based API key resolution (LAST RESORT)
- fallback_
chain - Fallback chain for ordered model failover.
- model_
db - Comprehensive model database for oxi-ai
- multi_
provider - MultiProvider for intelligent routing with fallback support. MultiProvider — intelligent routing with fallback
- oauth
- OAuth authentication system for oxi-ai
- partial_
response - Partial response accumulator for stream recovery.
- prelude
- Standard imports for oxi-ai usage.
- provider_
pool - Provider pool — rate limiting and concurrency control for provider calls.
- provider_
registry - Provider authentication registry
- register_
builtins - secret
- Wrapper type to prevent accidental exposure of sensitive data (e.g., API keys).
- utils
- Utility modules for AI API handling
Structs§
- Assistant
Message - Re-export AssistantMessage from messages Assistant message returned by the model.
- Compacted
Context - Compaction strategies and managers for long conversations. Result of context compaction
- Compaction
Manager - Compaction strategies and managers for long conversations. Context manager that handles compaction automatically
- Compat
Settings - Core type definitions (tokens, cost, etc.). Compatibility settings for OpenAI-compatible APIs.
- Context
- Shared conversation context. Conversation context for LLM interactions.
- Cost
- Core type definitions (tokens, cost, etc.). Cost structure – prices per million tokens.
- Default
Router - Complexity-based model routing. Default implementation of ComplexityRouter.
- Image
Content - Message types for constructing conversations. Image content block (base64-encoded).
- LlmCompactor
- Compaction strategies and managers for long conversations. LLM-based compactor that uses the model itself to summarize
- Model
- Core type definitions (tokens, cost, etc.). LLM model definition.
- Model
Registry - Runtime model registry for dynamically registered models.
- Open
AiProvider - OpenAI-compatible provider implementation. OpenAI-compatible provider
- Open
AiResponses Provider - OpenAI Responses API provider. OpenAI Responses API provider
- Provider
Registry - Provider trait, streaming options, and provider registry. Runtime registry for providers (custom + built-in resolution).
- Stream
Options - Provider trait, streaming options, and provider registry. Options for streaming requests
- Text
Content - Message types for constructing conversations. Text content block
- Thinking
Content - Message types for constructing conversations. Thinking content block (extended thinking / chain-of-thought output).
- Tool
- Tool definition and argument validation. Tool definition with JSON Schema parameters
- Tool
Call - Message types for constructing conversations. Tool call content block emitted by the model.
- Tool
Result - Core type definitions (tokens, cost, etc.). Tool result returned by agent tool execution.
- Tool
Result Message - Message types for constructing conversations. Tool result message carrying the output of a tool invocation.
- Transform
Options - Message transformation between provider formats. Options that control how messages are transformed between providers.
- Usage
- Core type definitions (tokens, cost, etc.). Token usage statistics.
- User
Message - Message types for constructing conversations. User message sent to the model.
Enums§
- Api
- Core type definitions (tokens, cost, etc.). Provider API identifier.
- Assistant
Role - Message types for constructing conversations. AssistantRole.
- Cache
Retention - Cache retention control for provider requests. Core type definitions (tokens, cost, etc.). Cache retention preference
- Compaction
Strategy - Compaction strategies and managers for long conversations. Compaction strategy determining when to compact
- Complexity
- Core type definitions (tokens, cost, etc.). Task complexity level for routing decisions.
- Content
Block - Message types for constructing conversations. Content block union (untagged for flexibility).
- Error
- Result type alias for oxi-ai operations. Unified error type for oxi-ai
- Image
Content Type - Message types for constructing conversations. ImageContentType.
- Input
Modality - Core type definitions (tokens, cost, etc.). Input modalities
- MaxTokens
Field - Core type definitions (tokens, cost, etc.). Which JSON field to use for the maximum output token count.
- Message
- Message types for constructing conversations. Message union tagged by role.
- Message
Content - Message types for constructing conversations. Message content – either a plain text string or a list of structured blocks.
- Provider
Error - Provider-specific error type for LLM operations. Provider-specific errors
- Provider
Event - Provider trait, streaming options, and provider registry. Streaming events emitted by providers
- Stop
Reason - Core type definitions (tokens, cost, etc.). Stop reason – why the model finished generating.
- Text
Content Type - Message types for constructing conversations. TextContentType.
- Thinking
Content Type - Message types for constructing conversations. ThinkingContentType.
- Thinking
Format - Core type definitions (tokens, cost, etc.). Provider-specific wire format for extended thinking.
- Thinking
Level - Core type definitions (tokens, cost, etc.). Model thinking/reasoning level
- Tool
Call Type - Message types for constructing conversations. ToolCallType.
- Tool
Result Role - Message types for constructing conversations. ToolResultRole.
- Tool
Validation Error - Tool definition and argument validation. Validation error
- User
Role - Message types for constructing conversations. UserRole.
Traits§
- Compactor
- Compaction strategies and managers for long conversations. Trait for context compaction implementations
- Complexity
Router - Complexity-based model routing. Routes tasks to models based on estimated complexity.
- Provider
- Provider trait, streaming options, and provider registry. LLM provider trait
Functions§
- anthropic_
to_ google - Message transformation between provider formats. Convert Anthropic-format messages to Google format.
- anthropic_
to_ openai - Message transformation between provider formats. Convert Anthropic-format messages to OpenAI format.
- complete
- High-level completion and token estimation. High-level complete function that collects all streaming events and returns the final assistant message.
- context_
usage - Token estimation and context usage helpers. Calculate context length usage percentage.
- create_
builtin_ provider - Built-in provider helpers (re-exported from providers). Create a built-in provider by name.
- custom_
provider_ names - Provider trait, streaming options, and provider registry. Return the set of currently registered custom provider names (global registry).
- estimate
- Token estimation and context usage helpers. Estimate token count using a hybrid algorithm that combines character-based and word-based heuristics.
- estimate_
tokens - High-level completion and token estimation. Estimate token count using a hybrid algorithm that combines character-based and word-based heuristics.
- estimate_
words - Token estimation and context usage helpers. Estimate tokens based on word count.
- fetch_
models_ async - Model fetching utilities (async and blocking).
Fetch the model list from an OpenAI-compatible
/v1/modelsendpoint asynchronously. - fetch_
models_ blocking - Model fetching utilities (async and blocking).
Fetch the model list from an OpenAI-compatible
/v1/modelsendpoint using the sharedreqwest::blockingclient. - get_
all_ provider_ names - Built-in provider helpers (re-exported from providers). Get all provider names (primary names only).
- get_
builtin_ provider - Built-in provider helpers (re-exported from providers). Look up a built-in provider by name or alias.
- get_
model - Runtime model registry for dynamically registered models.
- get_
models - Runtime model registry for dynamically registered models.
- get_
provider - Provider trait, streaming options, and provider registry. Get a provider by name
- get_
provider_ env_ key - Built-in provider helpers (re-exported from providers). Get the environment variable name for a provider.
- get_
provider_ env_ keys - Built-in provider helpers (re-exported from providers). Get all environment variable names for a provider (primary + extras).
- get_
providers - Runtime model registry for dynamically registered models.
- google_
to_ openai - Message transformation between provider formats. Convert Google-format messages to OpenAI format.
- is_
builtin_ provider - Built-in provider helpers (re-exported from providers). Check if a provider name or alias is a known built-in.
- lookup_
model - Runtime model registry for dynamically registered models.
- normalize_
tool_ call_ id - Message transformation between provider formats. Normalize a tool call ID for cross-provider compatibility.
- openai_
to_ anthropic - Message transformation between provider formats. Convert OpenAI-format messages to Anthropic format.
- progress_
callback - Tool definition and argument validation. Create a progress callback from a closure
- register_
model - Runtime model registry for dynamically registered models.
- register_
provider - Provider trait, streaming options, and provider registry. Register a custom provider at runtime (global registry).
- transform_
for_ provider - Message types for constructing conversations. Transform messages for cross-provider compatibility.
- transform_
messages - Message transformation between provider formats.
Transform a slice of
Messages from one provider API to another. - transform_
messages_ for_ model - Message transformation between provider formats. Transform messages for a target model, handling:
- unregister_
model - Runtime model registry for dynamically registered models.
- unregister_
provider - Provider trait, streaming options, and provider registry. Unregister a previously registered custom provider (global registry).
- validate_
args - Tool definition and argument validation. Validate tool arguments against a JSON Schema
Type Aliases§
- Progress
Callback - Tool definition and argument validation. Callback type for progress updates
- Result
- Result type alias for oxi-ai operations. Result type alias