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: ProviderKindProvider that rejected the credentials.
Request
The API request failed.
Used for provider errors that do not map to a more specific variant, including malformed provider responses.
Fields
provider: ProviderKindProvider that produced the failure.
RateLimit
Rate limit exceeded.
Retryable: see Error::is_retryable.
Fields
provider: ProviderKindProvider that throttled the request.
InvalidRequest(String)
Invalid request (bad parameters, etc.)
ModelNotAvailable
The requested model is not available or not supported.
Fields
provider: ProviderKindProvider the model was requested from.
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: ProviderKindProvider that could not serve the request.
capability: CapabilityCapability the request needed.
ContentFiltered
Content was filtered/blocked by the provider.
Fields
provider: ProviderKindProvider that filtered the content.
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: ProviderKindProvider whose request timed out.
ToolProviderUnsupported
Tool calling is not supported for the selected provider.
Fields
provider: ProviderKindProvider 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
issues: Vec<ToolArgumentIssue>Per-violation diagnostics, sorted and deduplicated.
ToolNotFound
A requested tool is not registered.
ToolLoopLimitExceeded
Tool execution exceeded the configured loop limit.
The limit comes from
GenerationConfig::with_max_tool_rounds.
StructuredOutput
Structured output could not be validated against the requested type.
Implementations§
Source§impl Error
impl Error
Sourcepub fn is_retryable(&self) -> bool
pub fn is_retryable(&self) -> bool
Returns true if this error is likely transient and the request can be retried.
Sourcepub fn is_auth_error(&self) -> bool
pub fn is_auth_error(&self) -> bool
Returns true if this is an authentication error.
Sourcepub fn is_rate_limit(&self) -> bool
pub fn is_rate_limit(&self) -> bool
Returns true if this is a rate limit error.
Sourcepub fn unsupported_capability(&self) -> Option<Capability>
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());Sourcepub fn kind_str(&self) -> &'static str
pub fn kind_str(&self) -> &'static str
Short error category string for use as a metrics or logging label.
Sourcepub fn provider(&self) -> Option<ProviderKind>
pub fn provider(&self) -> Option<ProviderKind>
Get the provider associated with this error, if any.
Trait Implementations§
Source§impl Error for Error
impl Error for Error
Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
use the Display impl or to_string()