use stream_rs::TruncatedJson;
#[derive(Debug, thiserror::Error)]
#[non_exhaustive]
pub enum Error {
#[error("HTTP transport error: {0}")]
Transport(#[from] reqwest::Error),
#[error("xAI API returned status {status}: {body}")]
Api {
status: u16,
body: String,
},
#[error("failed to decode JSON: {0}")]
Decode(#[from] serde_json::Error),
#[error("stream truncated: {0}")]
Truncated(#[from] TruncatedJson),
#[error("missing xAI API key (set XAI_API_KEY or pass it to the builder)")]
MissingApiKey,
}
pub type Result<T> = core::result::Result<T, Error>;