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 providers::CacheRetention;pub use compaction::generate_branch_summary;pub use compaction::CompactedContext;pub use compaction::CompactionManager;pub use compaction::CompactionStrategy;pub use compaction::Compactor;pub use compaction::ContextTransformer;pub use compaction::LlmCompactor;pub use compaction::NoopContextTransformer;pub use model_db::ModelEntry;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 roles::ModelRole;pub use roles::RoleColor;pub use roles::RoleInfo;pub use roles::RoleRegistry;pub use roles::builtin_role_info;pub use roles::builtin_visible_ids;pub use role_switcher::DEFAULT_LONG_CONTEXT_THRESHOLD;pub use role_switcher::RoleSignals;pub use role_switcher::decide_role;pub use role_switcher::resolve_role_to_model;pub use role_switcher::role_for_tool;pub use roles::live_role_registry;pub use roles::set_live_role_registry;pub use role_routing::RoleRoutingProvider;pub use partial_response::PartialResponse;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;pub use types::*;
Modules§
- catalog
- Stable since 0.63.0Built-in provider catalog loader.
- circuit_
breaker - Circuit-breaker behavior trait + SDK reference implementation.
- compaction
- Context compaction for long conversations
- compaction_
seam - Compaction trait seams — ported from grok-build
xai-grok-compaction/src/{item,sampler,token}.rs(Apache-2.0). - dialect
- Owned (in-band) tool-calling dialects — tool calls as text for models
without native tool support (omp
pi-ai/dialectport). Owned (in-band) tool-calling dialects. - env_
api_ keys - Environment variable-based API key resolution (LAST RESORT)
- model_
db - Comprehensive model database for oxi-ai
- oauth
- OAuth authentication system for oxi-ai
- partial_
response - Partial response accumulator for stream recovery.
- prelude
- Standard imports for oxi-ai usage.
- product_
env - Product home-directory resolution (
OXI_HOME/~/.oxi). Product home-directory resolution for oxi-ai. - provider_
registry - Provider authentication registry
- register_
builtins - role_
routing - Provider wrapper that routes each request to the role-selected model. Role-routing provider — plugs role switching into the main agent loop.
- role_
switcher - Role-switching decision engine (signals -> role -> model).
Role-switching decision engine — the “switching layer” on top of the
crate::rolesregistry. - roles
- Named model roles with
pi/<role>alias resolution. Model roles — named model assignments ported from omp’smodel-roles.ts. - router
- Model auto-routing for oxi.
- secret
- Wrapper type to prevent accidental exposure of sensitive data (e.g., API keys).
- types
- Core domain types for oxi-ai
- utils
- Utility modules for AI API handling
Structs§
- Anthropic
Provider - Anthropic provider implementation. Anthropic provider
- Assistant
Message - Re-export AssistantMessage from messages Assistant message returned by the model.
- Azure
Provider - Azure OpenAI provider implementation. Azure OpenAI provider
- Bedrock
Provider - AWS Bedrock provider implementation. Amazon Bedrock provider
- Context
- Stable since 0.63.0Shared conversation context. Conversation context for LLM interactions.
- Gemini
CliProvider - Google Gemini CLI transport — typed unsupported-provider error path.
Api::GoogleGeminiClidispatches here;stream()returnsProviderError::NotImplementedbecause no dedicated CLI transport exists in-tree (upstream collapsesgoogle-gemini-cli → google-generative-ai). Thin transport for thegoogle-gemini-clidialect. - Google
Provider - Google Generative AI (Gemini) provider implementation. Google Generative AI provider
- Http
Error Detail - Structured HTTP error detail (status/body/provider/request-id) carried by
ProviderError::HttpError. Re-exported so downstream crates (oxi-agent, oxi-cli) can construct/inspect structured errors. Structured HTTP error detail. - Image
Content - Stable since 0.63.0Message types for constructing conversations. Image content block (base64-encoded).
- Model
Registry - Runtime model registry for dynamically registered models.
- Ollama
Provider - Ollama (local NDJSON server) provider implementation. Ollama provider for local LLM inference.
- Open
AiProvider - OpenAI-compatible provider implementation. OpenAI-compatible provider
- Open
AiResponses Provider - OpenAI Responses API provider. OpenAI Responses API provider
- Provider
Options - Stable since 0.63.0Provider trait, streaming options, and provider registry. Per-provider options for fine-grained control.
- Provider
Registry - Stable since 0.63.0Provider trait, streaming options, and provider registry. Runtime registry for providers (custom + built-in resolution).
- Stream
Options - Stable since 0.63.0Provider trait, streaming options, and provider registry. Options for streaming requests
- Text
Content - Stable since 0.63.0Message types for constructing conversations. Text content block
- Thinking
Content - Stable since 0.63.0Message types for constructing conversations. Thinking content block (extended thinking / chain-of-thought output).
- Tool
- Stable since 0.63.0Tool definition and argument validation. Tool definition with JSON Schema parameters
- Tool
Call - Stable since 0.63.0Message types for constructing conversations. Tool call content block emitted by the model.
- Tool
Result Message - Stable since 0.63.0Message 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.
- User
Message - Stable since 0.63.0Message types for constructing conversations. User message sent to the model.
- Vertex
Provider - Google Vertex AI provider implementation. Google Vertex AI provider
Enums§
- Assistant
Role - Stable since 0.63.0Message types for constructing conversations. AssistantRole.
- Content
Block - Stable since 0.63.0Message 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 - Stable since 0.63.0Message types for constructing conversations. ImageContentType.
- Message
- Stable since 0.63.0Message types for constructing conversations. Message union tagged by role.
- Message
Content - Stable since 0.63.0Message types for constructing conversations. Message content – either a plain text string or a list of structured blocks.
- Provider
Error - Stable since 0.63.0Provider-specific error type for LLM operations. Provider-specific errors. `#[non_exhaustive]` — consumers MUST add a catch-all `_ =>` arm in their `match` expressions. Existing named variants are frozen; their meaning does not change between releases (see `docs/release-process.md`).
- Provider
Event - Stable since 0.63.0Provider trait, streaming options, and provider registry. Streaming events emitted by providers
- Text
Content Type - Stable since 0.63.0Message types for constructing conversations. TextContentType.
- Thinking
Content Type - Stable since 0.63.0Message types for constructing conversations. ThinkingContentType.
- Tool
Call Type - Stable since 0.63.0Message types for constructing conversations. ToolCallType.
- Tool
Result Role - Stable since 0.63.0Message types for constructing conversations. ToolResultRole.
- Tool
Validation Error - Stable since 0.63.0Tool definition and argument validation. Validation error
- User
Role - Stable since 0.63.0Message types for constructing conversations. UserRole.
Traits§
- Provider
- Stable since 0.63.0Provider 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.
- create_
builtin_ provider_ with_ options - Built-in provider helpers (re-exported from providers). Create a built-in provider with optional credential and base URL overrides.
- custom_
provider_ names - Stable since 0.63.0Provider trait, streaming options, and provider registry. Return the set of currently registered custom provider names (global registry).
- dynamic_
models - Runtime model registry for dynamically registered models.
- 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 - Stable since 0.63.0Provider trait, streaming options, and provider registry. Get a provider by name
- get_
provider_ arc - Stable since 0.63.0Provider trait, streaming options, and provider registry. Get a provider by name, returning Arc (for router delegation).
- 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_
messages - Provider-specific message normalization (empty content filtering, tool ID scrubbing, reasoning injection, tool-use ordering fix). Normalize messages for a specific provider.
- 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.
- product_
home_ dir - Product home-directory resolution (
OXI_HOME→~/.oxi). The product home directory. - progress_
callback - Stable since 0.63.0Tool definition and argument validation. Create a progress callback from a closure
- register_
model - Runtime model registry for dynamically registered models.
- register_
provider - Stable since 0.63.0Provider trait, streaming options, and provider registry. Register a custom provider at runtime (global registry).
- transform_
for_ provider - Stable since 0.63.0Message 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 - Stable since 0.63.0Provider trait, streaming options, and provider registry. Unregister a previously registered custom provider (global registry).
- validate_
args - Stable since 0.63.0Tool definition and argument validation. Validate tool arguments against a JSON Schema
Type Aliases§
- Progress
Callback - Stable since 0.63.0Tool definition and argument validation. Callback type for progress updates
- Result
- Result type alias for oxi-ai operations. Result type alias
- Stream
Result - Stable since 0.63.0Provider trait, streaming options, and provider registry. Stream result type alias