#[non_exhaustive]pub enum ClientError {
Show 19 variants
NetworkError(Error),
MiddlewareError(Error),
SerializationError(Error),
AuthenticationError(String),
EventSourceError(Error),
RateLimitError {
retry_after: Option<Duration>,
},
ModelError(String),
ConfigurationError(String),
TimeoutError,
InvalidRequest(String),
InvalidResponse(String),
ToolsNotSupported,
StreamingNotSupported,
ContextLengthExceeded {
current_tokens: usize,
max_tokens: usize,
},
ContentFiltered {
reason: String,
},
ServiceUnavailable(String),
InvalidTemperature,
InvalidTopP,
InvalidFrequencyPenalty,
}Expand description
Errors that can occur when interacting with LLM APIs.
This enum covers all error conditions from network failures to API-specific errors like rate limiting and content filtering.
Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
NetworkError(Error)
Network or HTTP request failure.
Indicates issues like DNS resolution, connection failures, or socket errors. These errors are typically retryable.
MiddlewareError(Error)
Middleware layer error.
Errors from request/response middleware such as retry logic or logging.
SerializationError(Error)
JSON serialization or deserialization error.
Occurs when request/response JSON cannot be properly encoded or decoded.
AuthenticationError(String)
API authentication failure (HTTP 401).
The API key is missing, invalid, or revoked. Check your credentials.
EventSourceError(Error)
use reqwest_eventsource::{Error as EventSourceError};
RateLimitError
Rate limit exceeded (HTTP 429).
Too many requests sent in a given time period. Wait and retry.
ModelError(String)
Model-specific error from the API.
The model encountered an error during generation.
ConfigurationError(String)
Client configuration issue.
Invalid base URL, missing required fields, or incompatible settings.
TimeoutError
Request timeout.
The request took longer than the configured timeout. Consider increasing the timeout or reducing request complexity.
InvalidRequest(String)
Malformed request.
The request structure is invalid or missing required parameters.
InvalidResponse(String)
Unexpected or malformed API response.
The API returned data that doesn’t match the expected format.
ToolsNotSupported
Tools requested but not supported by this model.
The model or provider doesn’t support function calling.
StreamingNotSupported
Streaming requested but not supported.
The model or provider doesn’t support streaming responses.
ContextLengthExceeded
Token limit exceeded for this model.
The input plus requested output exceeds the model’s context window.
Fields
ContentFiltered
Content blocked by safety filter.
The content violates the provider’s usage policies.
API service unavailable (5xx errors).
The provider’s servers are experiencing issues. Retry with backoff.
InvalidTemperature
Temperature parameter out of valid range.
Temperature must be between 0.0 and 2.0.
InvalidTopP
top_p parameter out of valid range.
top_p must be between 0.0 and 1.0.
InvalidFrequencyPenalty
frequency_penalty parameter out of valid range.
frequency_penalty must be between -2.0 and 2.0.
Implementations§
Source§impl ClientError
impl ClientError
Sourcepub fn is_retryable(&self) -> bool
pub fn is_retryable(&self) -> bool
Check if this error is potentially retryable.
Returns true for network errors, timeouts, rate limits, and service unavailable errors.
Sourcepub fn is_authentication_error(&self) -> bool
pub fn is_authentication_error(&self) -> bool
Check if this is an authentication error.
Sourcepub fn is_rate_limit_error(&self) -> bool
pub fn is_rate_limit_error(&self) -> bool
Check if this is a rate limit error.
Sourcepub fn retry_after(&self) -> Option<Duration>
pub fn retry_after(&self) -> Option<Duration>
Get the retry-after duration if this is a rate limit error.
Returns the suggested wait time before retrying the request.
Trait Implementations§
Source§impl Debug for ClientError
impl Debug for ClientError
Source§impl Display for ClientError
impl Display for ClientError
Source§impl Error for ClientError
impl Error for ClientError
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
Source§impl From<Error> for ClientError
impl From<Error> for ClientError
Source§fn from(source: Error) -> ClientError
fn from(source: Error) -> ClientError
Source§impl From<Error> for ClientError
impl From<Error> for ClientError
Source§fn from(source: Error) -> ClientError
fn from(source: Error) -> ClientError
Source§impl From<Error> for ClientError
impl From<Error> for ClientError
Source§fn from(source: Error) -> ClientError
fn from(source: Error) -> ClientError
Source§impl From<Error> for ClientError
impl From<Error> for ClientError
Source§fn from(source: Error) -> ClientError
fn from(source: Error) -> ClientError
Auto Trait Implementations§
impl !Freeze for ClientError
impl !RefUnwindSafe for ClientError
impl Send for ClientError
impl Sync for ClientError
impl Unpin for ClientError
impl !UnwindSafe for ClientError
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> 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> 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.