Skip to main content

Model

Enum Model 

Source
pub enum Model {
    OpenAI(OpenAIModel),
    Anthropic(AnthropicModel),
    OpenRouter(OpenRouterModel),
    OpenAICompatible(OpenAICompatibleModel),
}
Expand description

Unified AI model selection across providers.

Each variant wraps a provider-specific model enum, which is what makes the provider unambiguous: picking a model also picks the API it is sent to.

Serializes as an internally tagged value with a provider tag and a model payload, so a selection can be round-tripped through configuration files.

§Examples

use rai_sdk::{Model, OpenAIModel, ProviderKind};

let model = Model::OpenAI(OpenAIModel::Gpt5);
assert_eq!(model.as_str(), "gpt-5");
assert_eq!(model.provider(), ProviderKind::OpenAI);

Variants§

§

OpenAI(OpenAIModel)

A model served by OpenAI’s API.

§

Anthropic(AnthropicModel)

A model served by Anthropic’s Messages API.

§

OpenRouter(OpenRouterModel)

A model served through OpenRouter’s aggregating API.

§

OpenAICompatible(OpenAICompatibleModel)

A model served by the client’s configured OpenAI-compatible endpoint.

Implementations§

Source§

impl Model

Source

pub fn as_str(&self) -> &str

The wire identifier sent to the provider, e.g. "gpt-4o-mini".

Source

pub fn provider(&self) -> ProviderKind

The provider that will serve this model.

Source

pub fn gpt4o() -> Self

Select OpenAIModel::Gpt4o (gpt-4o).

Source

pub fn gpt4o_mini() -> Self

Select OpenAIModel::Gpt4oMini (gpt-4o-mini).

Source

pub fn gpt4_1() -> Self

Select OpenAIModel::Gpt4_1 (gpt-4.1).

Source

pub fn o3_mini() -> Self

Select OpenAIModel::O3Mini (o3-mini).

Source

pub fn o3() -> Self

Select OpenAIModel::O3 (o3).

Source

pub fn o4_mini() -> Self

Select OpenAIModel::O4Mini (o4-mini).

Source

pub fn gpt5() -> Self

Select OpenAIModel::Gpt5 (gpt-5).

Source

pub fn gpt5_mini() -> Self

Select OpenAIModel::Gpt5Mini (gpt-5-mini).

Source

pub fn gpt5_nano() -> Self

Select OpenAIModel::Gpt5Nano (gpt-5-nano).

Source

pub fn gpt5_codex() -> Self

Select OpenAIModel::Gpt5Codex (gpt-5-codex).

Source

pub fn gpt_5_1() -> Self

Select OpenAIModel::Gpt5_1 (gpt-5.1).

Source

pub fn gpt_5_2() -> Self

Select OpenAIModel::Gpt5_2 (gpt-5.2).

Source

pub fn gpt_5_2_pro() -> Self

Select OpenAIModel::Gpt5_2Pro (gpt-5.2-pro).

Source

pub fn gpt_5_3_chat() -> Self

Select OpenAIModel::Gpt5_3Chat (gpt-5.3-chat).

Source

pub fn gpt_5_3_instant() -> Self

Select OpenAIModel::Gpt5_3Instant (gpt-5.3-instant).

Source

pub fn gpt_5_4() -> Self

Select OpenAIModel::Gpt5_4 (gpt-5.4).

Source

pub fn gpt_5_4_mini() -> Self

Select OpenAIModel::Gpt5_4Mini (gpt-5.4-mini).

Source

pub fn gpt_5_4_nano() -> Self

Select OpenAIModel::Gpt5_4Nano (gpt-5.4-nano).

Source

pub fn gpt_5_5() -> Self

Select OpenAIModel::Gpt5_5 (gpt-5.5).

Source

pub fn claude_fable_5() -> Self

Select AnthropicModel::ClaudeFable5 (claude-fable-5).

Source

pub fn claude_opus_48() -> Self

Select AnthropicModel::ClaudeOpus48 (claude-opus-4-8).

Source

pub fn claude_opus_47() -> Self

Select AnthropicModel::ClaudeOpus47 (claude-opus-4-7).

Source

pub fn claude_sonnet_46() -> Self

Select AnthropicModel::ClaudeSonnet46 (claude-sonnet-4-6).

Source

pub fn claude_opus_46() -> Self

Select AnthropicModel::ClaudeOpus46 (claude-opus-4-6).

Source

pub fn claude_sonnet_4() -> Self

Select AnthropicModel::ClaudeSonnet4 (claude-sonnet-4-0).

Source

pub fn claude_opus_4() -> Self

Select AnthropicModel::ClaudeOpus4 (claude-opus-4-0).

Source

pub fn claude_opus_41() -> Self

Select AnthropicModel::ClaudeOpus41 (claude-opus-4-1).

Source

pub fn claude_sonnet_45() -> Self

Select AnthropicModel::ClaudeSonnet45 (claude-sonnet-4-5).

Source

pub fn claude_opus_45() -> Self

Select AnthropicModel::ClaudeOpus45 (claude-opus-4-5).

Source

pub fn claude_haiku_45() -> Self

Select AnthropicModel::ClaudeHaiku45 (claude-haiku-4-5).

Source

pub fn claude_35_sonnet() -> Self

Select AnthropicModel::Claude35Sonnet (claude-3-5-sonnet-20241022).

Source

pub fn claude_35_haiku() -> Self

Select AnthropicModel::Claude35Haiku (claude-3-5-haiku-20241022).

Source

pub fn openai_custom(name: impl Into<String>) -> Self

Create a model from a custom OpenAI model string.

Source

pub fn anthropic_custom(name: impl Into<String>) -> Self

Create a model from a custom Anthropic model string.

Source

pub fn openrouter_custom(name: impl Into<String>) -> Self

Create a model from a custom OpenRouter model string.

Source

pub fn openai_compatible(name: impl Into<String>) -> Self

Name a model served by the client’s OpenAI-compatible endpoint.

There is no catalog to pick from: the identifier is whatever the endpoint calls the model, such as llama3.1:8b on Ollama or a filesystem path on vLLM. Which endpoint serves it is a property of the client — see ClientBuilder::openai_compatible_base_url.

§Examples
use rai_sdk::{Model, ProviderKind};

let model = Model::openai_compatible("llama3.1:8b");
assert_eq!(model.as_str(), "llama3.1:8b");
assert_eq!(model.provider(), ProviderKind::OpenAICompatible);
Source

pub fn openrouter_auto() -> Self

Select OpenRouterModel::Auto (openrouter/auto).

Source

pub fn openrouter_gpt5() -> Self

Select OpenRouterModel::Gpt5 (openai/gpt-5).

Source

pub fn openrouter_claude_sonnet_4_5() -> Self

Select OpenRouterModel::ClaudeSonnet4_5 (anthropic/claude-sonnet-4.5).

Source

pub fn openrouter_gemini_25_flash() -> Self

Select OpenRouterModel::Gemini25Flash (google/gemini-2.5-flash).

Source

pub fn openrouter_deepseek_r1() -> Self

Select OpenRouterModel::DeepseekR1 (deepseek/deepseek-r1).

Source

pub fn openrouter_qwen3_coder() -> Self

Select OpenRouterModel::Qwen3Coder (qwen/qwen3-coder).

Trait Implementations§

Source§

impl Clone for Model

Source§

fn clone(&self) -> Model

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 Model

Source§

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

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

impl<'de> Deserialize<'de> for Model

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Serialize for Model

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

§

impl Freeze for Model

§

impl RefUnwindSafe for Model

§

impl Send for Model

§

impl Sync for Model

§

impl Unpin for Model

§

impl UnsafeUnpin for Model

§

impl UnwindSafe for Model

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> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

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> 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> 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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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<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