xai-grok 0.1.0

High-level async client for the xAI Grok API (chat, streaming, tool calling, vision, structured outputs), built on the stream-rs streaming toolkit.
Documentation
//! Error types for the Grok client.

use stream_rs::TruncatedJson;

/// Errors that can occur while talking to the xAI Grok API.
#[derive(Debug, thiserror::Error)]
#[non_exhaustive]
pub enum Error {
    /// The transport (reqwest) failed: DNS, TLS, connect, or read error.
    #[error("HTTP transport error: {0}")]
    Transport(#[from] reqwest::Error),

    /// The API returned a non-2xx status. Carries the status and response body.
    #[error("xAI API returned status {status}: {body}")]
    Api {
        /// The HTTP status code.
        status: u16,
        /// The raw response body (often a JSON error object).
        body: String,
    },

    /// A response (or streamed chunk) could not be deserialized.
    #[error("failed to decode JSON: {0}")]
    Decode(#[from] serde_json::Error),

    /// The stream ended in the middle of a JSON value or SSE event.
    #[error("stream truncated: {0}")]
    Truncated(#[from] TruncatedJson),

    /// The API key was missing or empty.
    #[error("missing xAI API key (set XAI_API_KEY or pass it to the builder)")]
    MissingApiKey,
}

/// Convenient result alias.
pub type Result<T> = core::result::Result<T, Error>;