ai_sdk_openai/error.rs
1use thiserror::Error;
2
3/// Errors that can occur when using the OpenAI provider.
4#[derive(Error, Debug)]
5pub enum OpenAIError {
6 /// API error from OpenAI service.
7 #[error("API error: {message}")]
8 ApiError {
9 /// Error message from the API.
10 message: String,
11 /// HTTP status code if available.
12 status_code: Option<u16>,
13 },
14
15 /// Authentication failed with the provided API key.
16 #[error("Authentication failed")]
17 AuthenticationError,
18
19 /// Rate limit exceeded for the API.
20 #[error("Rate limit exceeded")]
21 RateLimitError {
22 /// Number of seconds to wait before retrying.
23 retry_after: Option<u64>,
24 },
25
26 /// Network error occurred during request.
27 #[error("Network error: {0}")]
28 NetworkError(#[from] reqwest::Error),
29
30 /// JSON serialization/deserialization error.
31 #[error("Serialization error: {0}")]
32 SerializationError(#[from] serde_json::Error),
33
34 /// Invalid response received from the API.
35 #[error("Invalid response")]
36 InvalidResponse,
37}