stream-rs
Overview
stream-rs is a high-performance Rust toolkit for parsing and accumulating LLM token streams. It was born out of a need for a pure, no_std compatible parsing core that doesn't force a specific HTTP client on the user. The library implements a robust state-machine parser for Server-Sent Events (SSE) and includes specialized delta accumulators for OpenAI, Anthropic, and Gemini providers. It is designed to be the 'Parsing Engine' for the next generation of Rust-based AI clients like the included xai-grok package.
Architecture & Design
State-machine based parser that operates directly on byte-buffers. The workspace is split into a no_std core (stream-rs) and a batteries-included async client (xai-grok) using reqwest and tokio.
Technical Capabilities
- 01
Zero-Dependency Core: The base parser uses only the Rust core/alloc libraries for maximum portability.
- 02
Chunk-Boundary Invariance: Hardened via cargo-fuzz to ensure correct parsing even when tokens are split across TCP packets.
- 03
no_std Support: Can be embedded in resource-constrained environments or alternative runtimes.
- 04
xAI Grok Integration: Includes a full async client implementation for xAI's real-time streaming APIs.
- 05
Unified Event Model: Normalises diverse provider deltas (text, tool-calls, finish-reasons) into a single type-safe stream.