High-performance Rust library for unifying LLM providers behind one type-safe API.
Installation • Usage • Documentation • Contributing • Providers
Philosophy
- One API, many providers.
- Unified response types for chat + streaming.
- Minimal configuration: explicit
base_url,timeout,proxy.
Key Features
- Provider-agnostic client API (
LlmClient) - Universal streaming with a unified
StreamingResponse - Function calling / tools (OpenAI-compatible)
- Multi-modal messages (text + images)
- Reasoning model normalization
- Per-request overrides: API key, base URL, and headers for multi-tenant / gateway use
Installation
MSRV: Rust 1.85+ (Rust 2024 edition)
[]
= "0.6.1"
= { = "1", = ["full"] }
Usage
Chat
use ;
let client = openai?;
let request = ChatRequest ;
let response = client.chat.await?;
println!;
Streaming
use ;
use StreamExt;
let client = openai?;
let request = ChatRequest ;
let mut stream = client.chat_stream.await?;
while let Some = stream.next.await
Per-Request Overrides (Multi-Tenant / Gateway)
Override API key, base URL, or headers per request without creating a new client:
let request = new
.add_message
.with_api_key
.with_base_url
.with_header;
let response = client.chat.await?;
Advanced Features
Reasoning & Thinking
Support for reasoning models like OpenAI o1/o3 and Claude 3.7 Sonnet.
use ReasoningEffort;
let request = new
.add_message
.with_thinking_budget // Enable thinking with 16k token budget
.with_max_tokens; // Ensure max_tokens > thinking_budget
let response = client.chat.await?;
Dynamic Service Resolution
Resolve API keys and endpoints dynamically based on model name.
use ;
let resolver = new
.with_mapping
.with_mapping;
let target = resolver.resolve.await?;
// Use target.api_key and target.endpoint to configure your request
Request Overrides (Gateway Mode)
For gateway scenarios, you can override the API Key and Base URL per request without creating a new client.
let request = new
.with_api_key // Override API Key
.with_base_url; // Override Endpoint
let response = client.chat.await?;
File & Image Upload
Easily upload local files (Images, PDFs) with automatic Base64 encoding and MIME type detection.
use MessageBlock;
let request = new
.add_message
.add_message_block;
let response = client.chat.await?;
Documentation
Contributing
Contributions welcome! See https://llmconn.com/guide/contributing for guidelines.
License
MIT