pub struct EngineApi { /* private fields */ }Expand description
Engine API facade — model catalog introspection + config writes + routing.
Holds a shared reference to the live config (behind RwLock) and the
path to config.toml so write operations can persist to disk.
Routing stats are shared with AgentRuntime via Arc<RoutingStats>.
When config writes change the model or API key, EngineApi rebuilds
OxiosEngine via [EngineHandle] so the runtime picks up the change
on the next agent execution (hot-swap, no restart required).
Implementations§
Source§impl EngineApi
impl EngineApi
Sourcepub fn new(
config: Arc<RwLock<OxiosConfig>>,
config_path: PathBuf,
routing_stats: Arc<RoutingStats>,
engine_handle: Arc<EngineHandle>,
) -> Self
pub fn new( config: Arc<RwLock<OxiosConfig>>, config_path: PathBuf, routing_stats: Arc<RoutingStats>, engine_handle: Arc<EngineHandle>, ) -> Self
Create a new EngineApi.
config— shared config store (backed by RwLock)config_path— path to config.toml for persistencerouting_stats— shared stats tracker (shared with AgentRuntime)engine_handle— hot-swap handle for live engine replacement
Sourcepub fn routing_stats(&self) -> Arc<RoutingStats> ⓘ
pub fn routing_stats(&self) -> Arc<RoutingStats> ⓘ
Get the shared RoutingStats reference (for AgentRuntime wiring).
Sourcepub fn engine_handle(&self) -> &Arc<EngineHandle> ⓘ
pub fn engine_handle(&self) -> &Arc<EngineHandle> ⓘ
Get a reference to the engine handle.
Sourcepub fn providers(&self) -> Vec<ProviderInfo>
pub fn providers(&self) -> Vec<ProviderInfo>
List all available providers from the oxi-sdk catalog.
Filters out hidden/internal providers (those flagged with
hidden: true in [PROVIDER_META]) and augments each entry
with credential status, display name, and description.
Providers without a [PROVIDER_META] entry are shown by
default — a new provider landing in oxi-sdk should be
available to users even before its metadata is added here.
Sourcepub fn models(&self, provider: &str, query: Option<&str>) -> Vec<ModelInfo>
pub fn models(&self, provider: &str, query: Option<&str>) -> Vec<ModelInfo>
List models for a given provider, optionally filtered by a query.
Sourcepub fn search_models(&self, query: &str) -> Vec<ModelInfo>
pub fn search_models(&self, query: &str) -> Vec<ModelInfo>
Search models across all providers.
Sourcepub fn config(&self) -> EngineConfigResponse
pub fn config(&self) -> EngineConfigResponse
Get the current engine configuration + credential status + routing.
Sourcepub fn routing_stats_snapshot(&self) -> RoutingStatsSnapshot
pub fn routing_stats_snapshot(&self) -> RoutingStatsSnapshot
Get routing stats snapshot (for Web dashboard).
Sourcepub fn fallback_history(&self, limit: usize) -> Vec<FallbackEvent>
pub fn fallback_history(&self, limit: usize) -> Vec<FallbackEvent>
Get recent fallback history.
Sourcepub fn set_model(&self, model_id: &str) -> Result<()>
pub fn set_model(&self, model_id: &str) -> Result<()>
Set the default model in config.toml.
Updates both the in-memory config and the on-disk file, then hot-swaps the runtime engine so the next agent execution uses the new model.
Sourcepub fn set_api_key(&self, provider: &str, key: &str) -> Result<()>
pub fn set_api_key(&self, provider: &str, key: &str) -> Result<()>
Set an API key for a provider.
Stores the key via CredentialStore (→ ~/.oxi/auth.json) and also
updates config.toml’s [engine].api_key when the provider matches
the current default model. Hot-swaps the runtime engine afterward.
Sourcepub fn set_provider_options(&self, opts: &ProviderOptions) -> Result<()>
pub fn set_provider_options(&self, opts: &ProviderOptions) -> Result<()>
Update provider options in config.toml.
Persists the options and makes them available for the next agent run.
They are passed through to AgentLoopConfig::provider_options.
Sourcepub fn set_routing(&self, update: RoutingUpdate) -> Result<()>
pub fn set_routing(&self, update: RoutingUpdate) -> Result<()>
Update routing configuration in config.toml.
Only the fields provided in update are changed; others are left untouched.
Changes are persisted to disk immediately.
Sourcepub fn validate_key(&self, provider: &str, api_key: &str) -> ValidateKeyResult
pub fn validate_key(&self, provider: &str, api_key: &str) -> ValidateKeyResult
Validate an API key by making a simple test call.
Creates a lightweight provider and attempts a minimal request. Returns the validation result.