pub enum LlmError {
MissingApiKey(String),
InvalidApiKey(String),
HttpClientCreation(String),
ApiRequest(String),
ApiError(String),
ContextOverflow(ContextOverflowError),
IoError(String),
JsonParsing(String),
ToolParameterParsing {
tool_name: String,
error: String,
},
OAuthError(String),
UnsupportedContent(String),
Other(String),
}Expand description
Errors that can occur when interacting with LLM providers.
§Variants
§Authentication
MissingApiKey– A required environment variable (e.g.ANTHROPIC_API_KEY) is not set.InvalidApiKey– The API key format is invalid or was rejected by the provider.OAuthError– OAuth authentication failed (when theoauthfeature is enabled).
§Request/Response
HttpClientCreation– Failed to create the HTTP client (e.g. TLS configuration error).ApiRequest– The HTTP request to the provider failed (network error, timeout).ApiError– The provider returned an error response (rate limit, server error).ContextOverflow– The prompt exceeded the model’s context window. Contains aContextOverflowErrorwith provider, model, and token details.
§Parsing
JsonParsing– Failed to parse or serialize JSON (response body, tool arguments).ToolParameterParsing– Failed to parse tool parameters for a specific tool.IoError– IO error while reading the response stream.
§Content
UnsupportedContent– The message contained only content types this provider doesn’t support (e.g. sending audio to a text-only model).
§Other
Other– Catch-all for cases that don’t fit the above categories.
§From implementations
LlmError converts automatically from common error types: reqwest::Error, serde_json::Error, std::io::Error, reqwest::header::InvalidHeaderValue, async_openai::error::OpenAIError, and OAuthError (with the oauth feature).
§Type alias
The crate provides type Result<T> = std::result::Result<T, LlmError> for convenience.
Variants§
MissingApiKey(String)
Environment variable not set or invalid
InvalidApiKey(String)
Invalid API key format
HttpClientCreation(String)
HTTP client creation failed
ApiRequest(String)
API request failed
ApiError(String)
API returned an error response
ContextOverflow(ContextOverflowError)
API rejected the request because the prompt exceeded the model’s context window.
IoError(String)
IO error while reading stream
JsonParsing(String)
JSON parsing/serialization error
ToolParameterParsing
Tool parameter parsing error
OAuthError(String)
OAuth authentication error
UnsupportedContent(String)
The message contained only content types this provider doesn’t support
Other(String)
Generic error for other cases
Trait Implementations§
Source§impl Error for LlmError
impl Error for LlmError
1.30.0 · 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()
Source§impl From<InvalidHeaderValue> for LlmError
impl From<InvalidHeaderValue> for LlmError
Source§fn from(error: InvalidHeaderValue) -> Self
fn from(error: InvalidHeaderValue) -> Self
Source§impl From<OAuthError> for LlmError
Available on crate feature oauth only.
impl From<OAuthError> for LlmError
oauth only.Source§fn from(error: OAuthError) -> Self
fn from(error: OAuthError) -> Self
Source§impl From<OpenAIError> for LlmError
impl From<OpenAIError> for LlmError
Source§fn from(error: OpenAIError) -> Self
fn from(error: OpenAIError) -> Self
Auto Trait Implementations§
impl Freeze for LlmError
impl RefUnwindSafe for LlmError
impl Send for LlmError
impl Sync for LlmError
impl Unpin for LlmError
impl UnsafeUnpin for LlmError
impl UnwindSafe for LlmError
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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 moreSource§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<T> ToStringFallible for Twhere
T: Display,
impl<T> ToStringFallible for Twhere
T: Display,
Source§fn try_to_string(&self) -> Result<String, TryReserveError>
fn try_to_string(&self) -> Result<String, TryReserveError>
ToString::to_string, but without panic on OOM.