llm-connector
Next-generation Rust library for LLM protocol abstraction with native multi-modal support.
Supports 12+ providers: OpenAI, Anthropic, Google, Aliyun, Zhipu, Ollama, Tencent, Volcengine, DeepSeek, Moonshot, Xiaomi, and more.
Key Features
- 12+ Provider Support - OpenAI, Anthropic, Google, Aliyun, Zhipu, Ollama, Tencent, Volcengine, DeepSeek, Moonshot, Xiaomi
- Unified Output Format - All providers return the same
StreamingResponsetype - Multi-modal Support - Text + images in a single message (details)
- Function Calling - OpenAI-compatible tools with streaming (details)
- Reasoning Models - Universal support for reasoning models (details)
- Real-time Streaming - Universal streaming with format abstraction (details)
- Extreme Performance - 7,000x+ faster client creation (7ยตs vs 53ms)
- Type-Safe - Full Rust type safety with Result-based error handling
Installation
MSRV: Rust 1.85+ (Rust 2024 edition)
[]
= "0.6.1"
= { = "1", = ["full"] }
# Streaming is included by default since v0.6.0
# To disable default features:
# llm-connector = { version = "0.6.1", default-features = false, features = ["reqwest"] }
Quick Start
use ;
async
Supported Providers
| Provider | Quick Start | Features |
|---|---|---|
| OpenAI | LlmClient::openai("sk-...") |
Chat, Streaming, Tools, Multi-modal |
| Anthropic | LlmClient::anthropic("sk-ant-...") |
Chat, Streaming, Multi-modal |
| Google Gemini | LlmClient::google("key") |
Chat, Streaming |
| Aliyun | LlmClient::aliyun("sk-...") |
Chat, Streaming, Qwen models |
| Zhipu | LlmClient::zhipu("key") |
Chat, Streaming, Tools, Multi-modal, GLM models |
| Tencent | LlmClient::tencent("id", "key") |
Chat, Streaming, Hunyuan |
| Volcengine | LlmClient::volcengine("key") |
Chat, Streaming, Reasoning |
| DeepSeek | LlmClient::deepseek("sk-...") |
Chat, Streaming, Reasoning (R1) |
| Moonshot | LlmClient::moonshot("sk-...") |
Chat, Streaming |
| Xiaomi MiMo | LlmClient::xiaomi("sk-...") |
Chat, Streaming |
| Ollama | LlmClient::ollama() |
Chat, Streaming, Local models |
๐ Detailed documentation: docs/PROVIDERS.md
Builder Pattern
use LlmClient;
// Simple
let client = builder
.deepseek
.build?;
// With custom configuration
let client = builder
.openai
.base_url
.timeout
.proxy
.build?;
// Ollama (no API key needed)
let client = builder
.ollama
.base_url
.build?;
Streaming
use ;
use StreamExt;
let client = openai?;
let request = ChatRequest ;
let mut stream = client.chat_stream.await?;
while let Some = stream.next.await
All providers return the same StreamingResponse type. ๐ Streaming Guide
Function Calling / Tools
use ;
let tools = vec!;
let request = new
.add_message
.with_tools
.with_tool_choice;
let response = client.chat.await?;
// Convenience methods for tool call handling
if response.is_tool_call
๐ Detailed documentation: docs/TOOLS.md
Multi-modal Content
use ;
let request = ChatRequest ;
๐ Detailed documentation: docs/MULTIMODAL.md
Reasoning Models
Universal support for reasoning models (DeepSeek R1, OpenAI o1, Volcengine Doubao-Seed-Code, etc.):
let request = ChatRequest ;
let response = client.chat.await?;
if let Some = response.reasoning_content
println!;
๐ Detailed documentation: docs/REASONING_MODELS_SUPPORT.md
Structured Output
use ;
// JSON mode
let request = new
.add_message
.with_response_format;
// JSON Schema mode (Structured Outputs)
let request = new
.add_message
.with_response_format;
Error Handling
use LlmConnectorError;
match client.chat.await
Model Discovery
let client = openai?;
let models = client.models.await?;
println!;
Examples
# Basic examples
# Advanced examples
See examples/ directory for all available examples.
Documentation
| Document | Description |
|---|---|
| PROVIDERS.md | Detailed provider configuration |
| STREAMING.md | Streaming guide |
| TOOLS.md | Function calling / tools |
| MULTIMODAL.md | Multi-modal content |
| REASONING_MODELS_SUPPORT.md | Reasoning models |
| ARCHITECTURE.md | Technical architecture |
| CHANGELOG.md | Version history |
Contributing
Contributions welcome! See docs/CONTRIBUTING.md for guidelines.
License
MIT