Skip to main content

Error

Enum Error 

Source
pub enum Error {
Show 19 variants Auth { provider: ProviderKind, message: String, }, Request { provider: ProviderKind, message: String, }, RateLimit { provider: ProviderKind, message: String, }, InvalidRequest(String), ModelNotAvailable { provider: ProviderKind, model: String, }, ProviderNotConfigured(ProviderKind), ProviderNotEnabled(ProviderKind), CapabilityUnsupported { provider: ProviderKind, capability: Capability, base_url: String, message: String, }, ContentFiltered { provider: ProviderKind, reason: String, }, Config(String), Serialization(Error), Http(Error), Stream(String), Timeout { provider: ProviderKind, }, ToolProviderUnsupported { provider: ProviderKind, }, ToolArguments { name: String, message: String, issues: Vec<ToolArgumentIssue>, }, ToolNotFound { name: String, }, ToolLoopLimitExceeded { max_rounds: usize, }, StructuredOutput { provider: ProviderKind, model: String, message: String, },
}
Expand description

Errors that can occur when using the AI SDK.

Every fallible operation in this crate returns this type through Result. Rather than matching each variant, prefer the classification helpers when you only care about the category of failure.

§Examples

use rai_sdk::{Error, ProviderKind};

let error = Error::RateLimit {
    provider: ProviderKind::OpenAI,
    message: "slow down".to_string(),
};

assert!(error.is_rate_limit());
assert!(error.is_retryable());
assert_eq!(error.kind_str(), "rate_limit");
assert_eq!(error.provider(), Some(ProviderKind::OpenAI));

Variants§

§

Auth

Authentication failed (invalid API key, expired token, etc.)

Fields

§provider: ProviderKind

Provider that rejected the credentials.

§message: String

Message reported by the provider.

§

Request

The API request failed.

Used for provider errors that do not map to a more specific variant, including malformed provider responses.

Fields

§provider: ProviderKind

Provider that produced the failure.

§message: String

Message reported by the provider, or a description of what was wrong with its response.

§

RateLimit

Rate limit exceeded.

Retryable: see Error::is_retryable.

Fields

§provider: ProviderKind

Provider that throttled the request.

§message: String

Message reported by the provider.

§

InvalidRequest(String)

Invalid request (bad parameters, etc.)

§

ModelNotAvailable

The requested model is not available or not supported.

Fields

§provider: ProviderKind

Provider the model was requested from.

§model: String

Model identifier that was rejected.

§

ProviderNotConfigured(ProviderKind)

Provider not configured (missing API key, etc.)

§

ProviderNotEnabled(ProviderKind)

Provider feature not enabled.

§

CapabilityUnsupported

The endpoint does not implement a part of the API the request needed.

Raised for OpenAI-compatible endpoints, which share OpenAI’s wire format without necessarily sharing its feature set. It is deliberately distinct from Error::Request and Error::InvalidRequest so a caller can degrade gracefully — retry without tools, or parse free-form text instead of asking for a schema — rather than pattern-matching an HTTP error body.

Produced either up front, when EndpointCapabilities says the endpoint lacks the capability, or from the endpoint’s own rejection of a request that used it.

Fields

§provider: ProviderKind

Provider that could not serve the request.

§capability: Capability

Capability the request needed.

§base_url: String

Base URL of the endpoint that could not serve it.

§message: String

Why the capability is unavailable: the endpoint’s own message, or a note that it was declared unsupported.

§

ContentFiltered

Content was filtered/blocked by the provider.

Fields

§provider: ProviderKind

Provider that filtered the content.

§reason: String

Reason the provider gave for filtering.

§

Config(String)

Configuration error.

§

Serialization(Error)

Serialization/deserialization error.

§

Http(Error)

HTTP client error.

§

Stream(String)

Stream error.

§

Timeout

Timeout.

Retryable: see Error::is_retryable.

Fields

§provider: ProviderKind

Provider whose request timed out.

§

ToolProviderUnsupported

Tool calling is not supported for the selected provider.

Fields

§provider: ProviderKind

Provider that does not support tool calling.

§

ToolArguments

Tool arguments failed validation.

Surfaced to the model as a tool error message rather than aborting the tool loop, so it can retry with corrected arguments.

Fields

§name: String

Name of the tool whose arguments were rejected.

§message: String

Summary of the validation failures.

§issues: Vec<ToolArgumentIssue>

Per-violation diagnostics, sorted and deduplicated.

§

ToolNotFound

A requested tool is not registered.

Fields

§name: String

Tool name the model tried to call.

§

ToolLoopLimitExceeded

Tool execution exceeded the configured loop limit.

The limit comes from GenerationConfig::with_max_tool_rounds.

Fields

§max_rounds: usize

Round limit that was hit.

§

StructuredOutput

Structured output could not be validated against the requested type.

Fields

§provider: ProviderKind

Provider that produced the output.

§model: String

Model that produced the output.

§message: String

Why the output was rejected (empty, invalid JSON, schema violation, or deserialization failure).

Implementations§

Source§

impl Error

Source

pub fn is_retryable(&self) -> bool

Returns true if this error is likely transient and the request can be retried.

Source

pub fn is_auth_error(&self) -> bool

Returns true if this is an authentication error.

Source

pub fn is_rate_limit(&self) -> bool

Returns true if this is a rate limit error.

Source

pub fn unsupported_capability(&self) -> Option<Capability>

The capability an endpoint could not provide, if this is a Error::CapabilityUnsupported.

This is the hook for falling back to a simpler request shape.

§Examples
use rai_sdk::{Capability, Error, ProviderKind};

let error = Error::CapabilityUnsupported {
    provider: ProviderKind::OpenAICompatible,
    capability: Capability::ToolCalling,
    base_url: "http://localhost:11434/v1".to_string(),
    message: "the model does not support tools".to_string(),
};

assert_eq!(error.unsupported_capability(), Some(Capability::ToolCalling));
assert!(!error.is_retryable());
Source

pub fn kind_str(&self) -> &'static str

Short error category string for use as a metrics or logging label.

Source

pub fn provider(&self) -> Option<ProviderKind>

Get the provider associated with this error, if any.

Trait Implementations§

Source§

impl Debug for Error

Source§

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

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

impl Display for Error

Source§

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

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

impl Error for Error

Source§

fn source(&self) -> Option<&(dyn Error + 'static)>

Returns the lower-level source of this error, if any. Read more
1.0.0 · Source§

fn description(&self) -> &str

👎Deprecated since 1.42.0:

use the Display impl or to_string()

1.0.0 · Source§

fn cause(&self) -> Option<&dyn Error>

👎Deprecated since 1.33.0:

replaced by Error::source, which can support downcasting

Source§

fn provide<'a>(&'a self, request: &mut Request<'a>)

🔬This is a nightly-only experimental API. (error_generic_member_access)
Provides type-based access to context intended for error reports. Read more
Source§

impl From<&Error> for WireError

Source§

fn from(error: &Error) -> Self

Converts to this type from the input type.
Source§

impl From<Error> for Error

Source§

fn from(source: Error) -> Self

Converts to this type from the input type.
Source§

impl From<Error> for Error

Source§

fn from(source: Error) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

§

impl !RefUnwindSafe for Error

§

impl !UnwindSafe for Error

§

impl Freeze for Error

§

impl Send for Error

§

impl Sync for Error

§

impl Unpin for Error

§

impl UnsafeUnpin for Error

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> 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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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