Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

refactor(core): use registry for default pricing

Steven Enamakel01ce6a3cf398
diff --git a/crates/openhuman-core/src/config/schema/identity_cost.rs b/crates/openhuman-core/src/config/schema/identity_cost.rs
index bd0a3bfdd0..b46f020888 100644
--- a/crates/openhuman-core/src/config/schema/identity_cost.rs
+++ b/crates/openhuman-core/src/config/schema/identity_cost.rs
@@ -213,35 +213,23 @@ fn default_alert_threshold() -> f64 {
impl Default for CostConfig {
fn default() -> Self {
+ let prices = crate::inference::registry::provider_default_pricing(
+ crate::inference::provider::factory::PROVIDER_OPENHUMAN,
+ )
+ .map(|(model, input, output)| {
+ HashMap::from([(model, ModelPricing { input, output })])
+ })
+ .unwrap_or_default();
Self {
enabled: default_cost_enabled(),
monthly_limit_usd: default_monthly_limit(),
- prices: get_default_pricing(),
+ prices,
dashboard: CostDashboardConfig::default(),
budgets: Vec::new(),
}
}
}
-/// Default pricing for the managed default model (USD per 1M tokens).
-///
-/// DeepSeek V4 Flash through the managed OpenRouter passthrough. Other catalog
-/// models the user pins are priced from the catalog the backend serves
-/// (`inference_list_models`), not from here.
-fn get_default_pricing() -> HashMap<String, ModelPricing> {
- use super::types::MODEL_MANAGED_DEFAULT;
-
- let mut prices = HashMap::new();
- prices.insert(
- MODEL_MANAGED_DEFAULT.into(),
- ModelPricing {
- input: 0.0886,
- output: 0.1772,
- },
- );
- prices
-}
-
#[cfg(test)]
#[path = "identity_cost_tests.rs"]
mod tests;
diff --git a/crates/openhuman-core/src/inference/registry.rs b/crates/openhuman-core/src/inference/registry.rs
index 21ee472233..94ae050a28 100644
--- a/crates/openhuman-core/src/inference/registry.rs
+++ b/crates/openhuman-core/src/inference/registry.rs
@@ -96,6 +96,8 @@ pub struct ProviderModelHooks {
pub resolve_model: Arc<dyn Fn(&str, &Config, Option<&str>) -> Option<String> + Send + Sync>,
/// The default model's static context window, if the provider knows it.
pub context_window: Arc<dyn Fn(&str) -> Option<u64> + Send + Sync>,
+ /// Provider default pricing as (model id, input USD/1M, output USD/1M).
+ pub default_pricing: Arc<dyn Fn() -> Option<(String, f64, f64)> + Send + Sync>,
}
/// A provider-neutral semantic category for a backend error.
@@ -196,6 +198,53 @@ pub fn provider_default_model(provider_id: &str) -> Option<String> {
(hooks.default_model)()
}
+/// Default pricing supplied by the registered provider, if any.
+pub fn provider_default_pricing(provider_id: &str) -> Option<(String, f64, f64)> {
+ let hooks = provider_model_hooks(provider_id)?;
+ (hooks.default_pricing)()
+}
+
+/// The workload role assigned to a provider-specific model alias.
+pub fn provider_model_role(provider_id: &str, model: &str) -> Option<String> {
+ let hooks = provider_model_hooks(provider_id)?;
+ (hooks.role_for_model)(model)
+}
+
+/// Whether the provider recognizes `model` as an abstract alias.
+pub fn provider_model_is_alias(provider_id: &str, model: &str) -> bool {
+ provider_model_hooks(provider_id)
+ .is_some_and(|hooks| (hooks.is_alias)(model))
+}
+
+/// Whether the provider regards `model` as a concrete id for pass-through.
+pub fn provider_model_is_raw(provider_id: &str, model: &str) -> bool {
+ provider_model_hooks(provider_id)
+ .is_none_or(|hooks| (hooks.is_raw_model)(model))
+}
+
+/// Whether the provider says `model` supports image input.
+pub fn provider_model_supports_vision(provider_id: &str, model: &str) -> bool {
+ provider_model_hooks(provider_id)
+ .is_some_and(|hooks| (hooks.supports_vision)(model))
+}
+
+/// Provider-specific resolution of a role alias, configured default, or pin.
+pub fn resolve_provider_model(
+ provider_id: &str,
+ role: &str,
+ config: &Config,
+ model_override: Option<&str>,
+) -> Option<String> {
+ let hooks = provider_model_hooks(provider_id)?;
+ (hooks.resolve_model)(role, config, model_override)
+}
+
+/// The provider's model-specific context window, if known.
+pub fn provider_model_context_window(provider_id: &str, model: &str) -> Option<u64> {
+ let hooks = provider_model_hooks(provider_id)?;
+ (hooks.context_window)(model)
+}
+
/// Registers a generic config normalizer, such as a provider-owned migration
/// that must also run after the config schema reaches its current version.
pub type ConfigNormalizer = Arc<dyn Fn(&mut Config) -> bool + Send + Sync>;