ollama-client-rs
Rust client library for the Ollama API.
Features
- Async-first with optional blocking API (
blocking feature, enabled by default)
- All 14 Ollama API endpoints: chat, generate, embeddings, model management, blobs, version
- Streaming support via NDJSON for chat, generate, pull, push, create
Quick start
use ollama_client::blocking::BlockingClient;
use ollama_client::types::Message;
fn main() -> ollama_client::Result<()> {
let client = BlockingClient::new();
let response = client.chat()
.model("gemma4")
.messages(vec![Message::user("Hello!")])
.send()?;
println!("{}", response.message.content);
let stream = client.chat()
.model("gemma4")
.messages(vec![Message::user("Hello!")])
.send_stream()?;
for chunk in stream {
print!("{}", chunk?.message.content);
}
Ok(())
}
Async
use ollama_client::{OllamaClient, types::Message};
use tokio_stream::StreamExt;
#[tokio::main]
async fn main() -> ollama_client::Result<()> {
let client = OllamaClient::new();
let mut stream = client.chat()
.model("gemma4")
.messages(vec![Message::user("Hello!")])
.send_stream()
.await?;
while let Some(chunk) = stream.next().await {
print!("{}", chunk?.message.content);
}
Ok(())
}
ollama-chat
The workspace includes a CLI chat REPL:
cargo run -p ollama-client-rs
Requires Ollama running on localhost:11434.
License
MIT