Skip to main content

Catalog

Struct Catalog 

Source
pub struct Catalog { /* private fields */ }
Expand description

Model facts by provider and model id. Cloning is cheap: the rows are shared, and a change copies only the list of handles to them.

Implementations§

Source§

impl Catalog

Source

pub fn facts(&self, provider: ProviderId, model: &str) -> ModelFacts

The facts of provider’s model from this catalog: its entry by Self::get’s rule, bound to model as written, and this catalog for every other model a request names. A model the catalog does not list binds nothing.

Source§

impl Catalog

Source

pub fn from_overrides( json: &str, base: &Catalog, ) -> Result<Catalog, OverrideErrors>

Read a user’s override file, laid over base afterwards with Self::with_overrides. The file is in the shape of Self::from_models_dev’s, with each section holding only models, and each row only the keys rig reads plus its hand-entered facts under rig.

base is the catalog the file will be laid over. A row for a model base does not list exactly adds that model, so it must set reasoning, tool_call and modalities, which an absent key would otherwise turn into “the model does not”. That catches a misspelt model id, and a dated snapshot id whose row would hide its base model’s facts.

§Errors

OverrideErrors holding every mistake found, each with its path: an unknown vendor key or field, with the closest known one; a new model that leaves out a needed key, with the closest listed id; and a value of the wrong type. Text that is not a JSON object is one error with an empty path.

Source

pub fn from_models_dev( json: &str, ) -> Result<(Catalog, Vec<Skipped>), CatalogError>

Read models.dev’s api.json, or a file in its shape: an object of provider keys, each with a models object keyed by model id. A provider key is a models.dev key (google, amazon-bedrock) or a rig vendor name (gcp.gemini). Keys rig does not read are ignored, and a provider rig does not know, or a section or row that does not read, is skipped and listed, so the rest of the file still loads.

A row may carry rig’s hand-entered facts under rig, among them format, the protocol family the model is reached by when that is not its vendor’s own (see ProviderId::catalog).

§Errors

CatalogError::Json when the text is not a JSON object.

Source§

impl Catalog

Source

pub fn builtin() -> &'static Catalog

The catalog this build ships.

§Panics

Panics on first use if the data compiled into this build does not parse whole. The data is checked in and a unit test parses it, so a build that passed its tests never panics here.

Source

pub fn generated_at() -> SystemTime

When the models.dev data behind Self::builtin was read. Lay a fetched copy on only when it is newer, so an old cache never hides what this rig shipped.

Source

pub fn get(&self, provider: ProviderId, model: &str) -> Option<Resolved<'_>>

The model provider serves as model, by the one rule every lookup in rig follows: the id as listed, or else the longest listed id that model extends with -20 and a year, a dated snapshot of it (claude-sonnet-4-5-20250929, gpt-5-2025-08-07, claude-opus-5-5-20260601-v1:0). Any selection of a vendor finds that vendor’s models.

Source

pub fn get_exact(&self, provider: ProviderId, model: &str) -> Option<&ModelSpec>

The model provider lists as exactly model, for a caller that must not read a snapshot as its base model.

Source

pub fn resolve(&self, reference: &str) -> Result<Resolved<'_>, NotFound>

The model a reference names, by Self::get’s rule. A reference is vendor/model, split at the first /, so the model id keeps any / and : of its own (openrouter/anthropic/claude-sonnet-4.5, ollama/qwen3:4b). The older vendor/format:model spelling is still read; its format plays no part in the lookup.

§Errors

NotFound when the reference names no listed model, with up to five close references to models that are not deprecated, or else the closest ones of its vendor.

Source

pub fn iter(&self) -> impl Iterator<Item = &ModelSpec>

Every model, by vendor then id.

Source

pub fn with_overrides(&self, overrides: &Catalog) -> Catalog

This catalog with overrides laid over it, field by field. A model in both keeps every field the override leaves out; a model only in overrides is added. self is unchanged, and the result shares every row the override does not touch.

Every field the override sets wins, including the facts rig reviewed by hand, so lay a fetched copy of models.dev on with Self::with_models_dev instead.

Source

pub fn with_models_dev(&self, fetched: &Catalog) -> Catalog

This catalog with fetched, a newer copy of models.dev read with Self::from_models_dev, laid over it as Self::with_overrides lays an override, except for the fields of a row that rig’s own data pins. The built-in data pins the fields rig reviewed by hand and the ones its generator joins from another row (a gateway’s Claude row takes Anthropic’s reasoning options), so a refresh updates prices and limits models.dev changes but keeps those. A model only in fetched is added as models.dev lists it.

Source

pub fn insert(&mut self, spec: ModelSpec)

Add spec, replacing any model of the same vendor and id whole. A later Self::with_overrides lays an override on it field by field, as on any other row.

Source§

impl Catalog

Source

pub fn connect<'a>( &self, model: impl Into<ModelSelector<'a>>, ) -> Result<DynModel<Completion>, ConnectError>

Available on crate feature reqwest only.

The completion model model selects, with the key from the environment, on the shared reqwest client. See Self::connect_with.

use rig_core::catalog::Catalog;

let catalog = Catalog::builtin();
let model = catalog.connect("anthropic/claude-opus-5-5")?; // ANTHROPIC_API_KEY
let spec = catalog.resolve("openai/gpt-5.5")?.spec;
let other = catalog.connect(spec)?; // OPENAI_API_KEY
Source

pub fn connect_with<'a>( &self, model: impl Into<ModelSelector<'a>>, options: ConnectOptions, ) -> Result<DynModel<Completion>, ConnectError>

The completion model model selects, connected as options say.

A reference is read as Self::resolve reads it, and the model id is sent as written. A model this catalog does not list still connects, on a vendor it knows. The family is options’s, else the one the older vendor/format:model spelling names, else the one the catalog row (or the spec) is reached by, else the vendor’s primary. Unless options give a key, it is read from the first of the vendor’s api_key_envs set to a non-empty value, along with the base URL and other settings its dialect reads from the environment. An account options name replaces the one the dialect reads.

The model encodes and prices with this catalog’s facts: the spec it was connected from, and this catalog for any other model a request names, so the catalog’s overrides reach its requests and reported cost.

§Errors

ConnectError::Malformed for a reference that is not vendor/model, ConnectError::NotFound for an unknown vendor, ConnectError::CatalogOnly for a provider a companion crate serves, ConnectError::Selection for a family the vendor is not registered for, ConnectError::MissingKey when no key is given or set, and ConnectError::NoHttpClient without the reqwest feature and an HTTP client.

Trait Implementations§

Source§

impl Clone for Catalog

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Catalog

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Catalog

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WasmCompatSend for T
where T: Send,

Source§

impl<T> WasmCompatSync for T
where T: Sync,

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more