8 releases

Uses new Rust 2024

0.2.6 Jun 8, 2026
0.2.5 Jun 3, 2026
0.2.3 May 30, 2026
0.1.0 May 14, 2026

#12 in #chat-rs


Used in chat-rs

MIT license

260KB
5.5K SLoC

chat-huggingface

Hugging Face Inference Providers (Router) provider for chat-rs. Thin wrapper over chat-completions targeting https://router.huggingface.co/v1. Routes any HF-hosted model through a single OpenAI-compatible endpoint, with provider selection via the model slug (:fastest, :cheapest, or a specific provider).

Install

[dependencies]
chat-core = "0.4.0"
chat-huggingface = "0.2.4"
tokio = { version = "1", features = ["macros", "rt-multi-thread"] }

Or via the umbrella crate: chat-rs = { version = "0.5.0", features = ["huggingface"] }.

Usage

use chat_huggingface::HuggingFaceBuilder;
use chat_core::{builder::ChatBuilder, types::messages};

let client = HuggingFaceBuilder::new()
    .with_model("openai/gpt-oss-120b:fastest")
    .build();

let mut chat = ChatBuilder::new().with_model(client).build();

let mut msgs = messages::from_user(vec!["Hello!"]);
let response = chat.complete(&mut msgs).await?;

Set HF_TOKEN in your environment or call .with_api_key() on the builder.

Capabilities

  • Completions — text generation with tool calling and structured output
  • Streaming — token-by-token output (requires stream feature)

Custom Endpoint / Transport

Override the base URL with .with_base_url(...) or supply a custom transport with .with_transport(...).

Feature Flags

Streaming is gated on the stream feature:

chat-huggingface = { version = "0.2.3", features = ["stream"] }

Dependencies

~16–25MB
~381K SLoC