Build LLM clients with ease
chat-rs is a unified, type-safe Rust framework for Large Language Models. One API across every major provider, with streaming, tools, and automatic retries.
main.rs
use chat_rs::{ChatBuilder, openrouter::OpenRouterBuilder, parts, types::messages};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
let client = OpenRouterBuilder::new()
.with_model("anthropic/claude-sonnet-4")
.build();
let mut chat = ChatBuilder::new().with_model(client).build();
let mut msgs = messages::from_user(parts!["Say hello in one sentence."]);
let res = chat.complete(&mut msgs).await?.expect_complete();
println!("{:#?}", res.content);
Ok(())
}One API, many providers
Swap between OpenAI, Claude, Gemini, OpenRouter, DeepSeek, Ollama and more without touching your call sites.
Type-state builders
Required configuration is enforced at compile time — misuse is a type error, not a runtime panic.
Streaming first
Token-by-token output over SSE (and WebSocket where supported) behind a single StreamEvent enum.
Tools & human-in-the-loop
Native tool calling with pause/resume flows for approvals and side-effecting actions.
Pluggable transport
Bring your own HTTP/WS transport, or use the built-in reqwest and tungstenite implementations.
Composable wires
Shared Chat Completions and Responses API wire crates — new OpenAI-compatible providers are thin wrappers.