pub struct ModelRegistry { /* private fields */ }model-discovery only.Expand description
A layered model resolver: user override → feed cache → static table.
Construct one with new, optionally seed user overrides, then
refresh it from a ModelCatalogSource to populate the
feed cache. resolve walks the layers in priority order
and always returns a ResolvedModel (empty + ResolvedSource::Unknown
when nothing matched).
Implementations§
Source§impl ModelRegistry
impl ModelRegistry
Sourcepub fn new() -> ModelRegistry
pub fn new() -> ModelRegistry
Create an empty registry (no overrides, no feed loaded).
Sourcepub fn with_override(
self,
provider: impl AsRef<str>,
model: impl AsRef<str>,
entry: CatalogEntry,
) -> ModelRegistry
pub fn with_override( self, provider: impl AsRef<str>, model: impl AsRef<str>, entry: CatalogEntry, ) -> ModelRegistry
Builder-style: add a user override that wins over feed and static data.
Sourcepub fn register(
&mut self,
provider: impl AsRef<str>,
model: impl AsRef<str>,
entry: CatalogEntry,
)
pub fn register( &mut self, provider: impl AsRef<str>, model: impl AsRef<str>, entry: CatalogEntry, )
Register (or replace) a user override in place.
Sourcepub async fn refresh(
&self,
source: &dyn ModelCatalogSource,
) -> Result<usize, Error>
pub async fn refresh( &self, source: &dyn ModelCatalogSource, ) -> Result<usize, Error>
Fetch from source and replace the feed cache. Returns the entry count.
§Errors
Returns an error if the source fails to fetch or parse, or if the cache lock is poisoned.
Sourcepub fn resolve(&self, provider: &str, model: &str) -> ResolvedModel
pub fn resolve(&self, provider: &str, model: &str) -> ResolvedModel
Resolve a provider/model through the layers: override → feed → static.
Sourcepub fn resolve_dynamic(
&self,
provider: &str,
model: &str,
) -> Option<ResolvedModel>
pub fn resolve_dynamic( &self, provider: &str, model: &str, ) -> Option<ResolvedModel>
Resolve through the dynamic layers only — user override → feed cache
— reporting None when neither carries the pair.
Unlike resolve this never falls back to the static
table, which lets a caller that owns its own static lookup keep the two
sources apart. That distinction matters when the key a model is filed
under differs per source: a caller can then ask this catalog about
every key the feeds might use before letting the static table answer
under the (narrower) set of keys it is built from, instead of having
the first key that happens to hit the static layer short-circuit the
search.
Sourcepub fn resolve_override(
&self,
provider: &str,
model: &str,
) -> Option<ResolvedModel>
pub fn resolve_override( &self, provider: &str, model: &str, ) -> Option<ResolvedModel>
Resolve through the override layer only — a user-registered override —
reporting None when the pair has none.
An override is authoritative: the caller uses it in preference to any
feed row, so it is probed on its own. See
estimate_override_cost_usd.
Sourcepub fn estimate_override_cost_usd(
&self,
provider: &str,
model: &str,
usage: &Usage,
) -> Option<f64>
pub fn estimate_override_cost_usd( &self, provider: &str, model: &str, usage: &Usage, ) -> Option<f64>
Estimate cost from the override layer only (never feed or static),
with tier selection. None when the pair has no override.
Sourcepub fn estimate_override_base_cost_usd(
&self,
provider: &str,
model: &str,
usage: &Usage,
) -> Option<f64>
pub fn estimate_override_base_cost_usd( &self, provider: &str, model: &str, usage: &Usage, ) -> Option<f64>
Estimate cost from the override layer only, at the base band (a summed
usage). None when the pair has no override.
Sourcepub fn resolve_feed(&self, provider: &str, model: &str) -> Option<ResolvedModel>
pub fn resolve_feed(&self, provider: &str, model: &str) -> Option<ResolvedModel>
Resolve through the feed layer only — the refreshable cache — skipping
both the override and the static table. None when the feed has none.
A caller that scopes override authority by candidate specificity needs the feed price at a key independently of any override on the same key, which the layered lookups (which let an override shadow the feed) cannot give it.
Sourcepub fn estimate_feed_cost_usd(
&self,
provider: &str,
model: &str,
usage: &Usage,
) -> Option<f64>
pub fn estimate_feed_cost_usd( &self, provider: &str, model: &str, usage: &Usage, ) -> Option<f64>
Estimate cost from the feed layer only (never override or static), with
tier selection. None when the feed has no row for the pair.
Sourcepub fn estimate_feed_base_cost_usd(
&self,
provider: &str,
model: &str,
usage: &Usage,
) -> Option<f64>
pub fn estimate_feed_base_cost_usd( &self, provider: &str, model: &str, usage: &Usage, ) -> Option<f64>
Estimate cost from the feed layer only, at the base band (a summed
usage). None when the feed has no row for the pair.
Sourcepub fn estimate_cost_usd(
&self,
provider: &str,
model: &str,
usage: &Usage,
) -> Option<f64>
pub fn estimate_cost_usd( &self, provider: &str, model: &str, usage: &Usage, ) -> Option<f64>
Estimate request cost in USD using the layered pricing (override → feed → static), if any.
Reports None — “this catalog cannot price the call” — rather than a
partial figure when the resolved pricing is missing a rate for a usage
component with a nonzero token count (e.g. a feed row that lists an
input rate but no output rate). A caller can then fall back to another
pricing source instead of billing those tokens at zero.
A call whose context exceeds a published tier threshold is billed at that tier’s rates, not the base rates.
Sourcepub fn estimate_dynamic_cost_usd(
&self,
provider: &str,
model: &str,
usage: &Usage,
) -> Option<f64>
pub fn estimate_dynamic_cost_usd( &self, provider: &str, model: &str, usage: &Usage, ) -> Option<f64>
Estimate request cost in USD from the dynamic layers only (override →
feed), never the static table. See resolve_dynamic.
Declines partial pricing, and selects the tier the call falls in,
exactly as estimate_cost_usd does.
usage must describe a SINGLE provider call: tier selection reads its
input-token count as the call’s context size. To price a summed usage,
use estimate_dynamic_base_cost_usd.
Sourcepub fn estimate_dynamic_base_cost_usd(
&self,
provider: &str,
model: &str,
usage: &Usage,
) -> Option<f64>
pub fn estimate_dynamic_base_cost_usd( &self, provider: &str, model: &str, usage: &Usage, ) -> Option<f64>
Estimate cost from the dynamic layers at the BASE band, ignoring any long-context tiers.
For a summed usage — a thread’s cumulative tokens, not one call — the input-token count is not a context size: ten 50K-token calls sum to 500K without any single call ever reaching a 272K threshold. Selecting a tier from that sum would reprice the whole history at long-context rates a call never paid, so aggregate repricing stays on the base band.
Trait Implementations§
Source§impl Clone for ModelRegistry
impl Clone for ModelRegistry
Source§fn clone(&self) -> ModelRegistry
fn clone(&self) -> ModelRegistry
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl CostEstimator for ModelRegistry
impl CostEstimator for ModelRegistry
Source§fn estimate_aggregate_cost_usd(
&self,
provider: &str,
model: &str,
usage: &Usage,
) -> Option<f64>
fn estimate_aggregate_cost_usd( &self, provider: &str, model: &str, usage: &Usage, ) -> Option<f64>
usage — a thread’s cumulative
tokens rather than one call. Read moreSource§fn estimate_override_cost_usd(
&self,
provider: &str,
model: &str,
usage: &Usage,
) -> Option<f64>
fn estimate_override_cost_usd( &self, provider: &str, model: &str, usage: &Usage, ) -> Option<f64>
provider/model resolves through a
source layer the caller must treat as authoritative over the others — a
user-registered override. Read moreSource§fn estimate_override_aggregate_cost_usd(
&self,
provider: &str,
model: &str,
usage: &Usage,
) -> Option<f64>
fn estimate_override_aggregate_cost_usd( &self, provider: &str, model: &str, usage: &Usage, ) -> Option<f64>
estimate_override_cost_usd.Source§fn estimate_feed_cost_usd(
&self,
provider: &str,
model: &str,
usage: &Usage,
) -> Option<f64>
fn estimate_feed_cost_usd( &self, provider: &str, model: &str, usage: &Usage, ) -> Option<f64>
Source§fn estimate_feed_aggregate_cost_usd(
&self,
provider: &str,
model: &str,
usage: &Usage,
) -> Option<f64>
fn estimate_feed_aggregate_cost_usd( &self, provider: &str, model: &str, usage: &Usage, ) -> Option<f64>
estimate_feed_cost_usd.