ollama-client 0.1.0

Async and blocking Rust client for the Ollama API
Documentation

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();

    // Non-streaming
    let response = client.chat()
        .model("gemma4")
        .messages(vec![Message::user("Hello!")])
        .send()?;
    println!("{}", response.message.content);

    // Streaming
    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