The xAI Rust SDK is a gRPC client that lets you talk to xAI's API in Rust. It currently exposes an asynchronous client built on tonic.
- Early preview focused on chat completions (
GetCompletion), streaming chunks (GetCompletionChunk), and agentic server-side tool calling - Only asynchronous usage is supported today
- Async
AsyncClientthat authenticates with the xAI API - Unary (
get_completion) and server‑streaming (get_completion_chunk) helpers - Generated protobuf types from xAI's published
.protofiles - Helper builders to construct chat messages (
ChatMessage), requests (build_request), and tool definitions for server-side agentic flows
cargo add xai-rsAlternatively, add this to your Cargo.toml:
[dependencies]
xai-rs = "0.0.8"- Simple chat completion example in the
examples/dir examples/chat_unary.rs– single response viaGetCompletionexamples/chat_server_streaming.rs– server-streaming chunks viaGetCompletionChunkexamples/agentic_tool_calling.rs– enables server-side web/X/code tools and streams tool-call telemetry- Run them with
cargo run --example <example_name>after settingXAI_API_KEY(and optionallyXAI_MODEL)
Contributions are welcome! Please open issues or submit pull requests on the GitHub repository.
Open gaps include, additional RPCs (images, models, telemetry, etc.), a sync client, retries, and richer error types.
This project is licensed under the MIT License. See the LICENSE file for details.