lmkit
One config. Every major AI provider.
δΈζ | English
A unified Rust client for OpenAI, Anthropic, Google Gemini, Aliyun, Ollama, and Zhipu β built around a single trait and factory pattern. Switch providers by changing one config. Your business logic stays untouched.
Why use lmkit
- π Unified interface β
ChatProvider,EmbedProviderand friends abstract away provider differences; your code never talks to raw HTTP - π One-line switching β swap
ProviderConfigto move from OpenAI to Aliyun or a local Ollama, zero other changes - π¦ Compile only what you need β providers and modalities are Cargo features; unused ones add zero dependencies
- π Streaming + tool calls β native SSE streaming;
ChatChunkcarries both textdeltaandtool_call_deltasin one unified type - π Precise errors β
ProviderDisabled/Unsupported/Apitell you exactly what went wrong and where
Quick Start
Add the dependency
[]
= { = "0.1", = ["openai", "chat", "embed"] }
= { = "1", = ["rt-multi-thread", "macros"] }
The defaults already include openai + chat + embed. Mix and match features as needed:
# Aliyun + multi-turn chat + embeddings + reranking
= { = "0.1", = ["aliyun", "chat", "embed", "rerank"] }
Send a message
use ;
async
Stream the response
use StreamExt;
use ;
async
Switch providers
Change Provider::OpenAI to your target, update base_url and the API key β everything else stays the same:
// Aliyun Qwen
let cfg = new;
// Local Ollama (no key required)
let cfg = new;
Provider & Capability Matrix
| Provider | Chat | Embed | Rerank | Image |
|---|---|---|---|---|
| OpenAI | β | β | β | β |
| Anthropic | β | β | β | β |
| Google Gemini | β | β | β | β |
| Aliyun DashScope | β | β | β | β |
| Ollama | β | β | β | β |
| Zhipu | β | β | β | β |
Chat primary API: complete (blocking) and complete_stream (SSE). chat / chat_stream are single-turn convenience wrappers.
Documentation
- π Usage Guide β getting started, features, provider config, error handling
- π§ API Reference β Rust traits, factory functions, type definitions
- π HTTP Endpoints β per-provider request / response shapes
- ποΈ Design Guidelines β architecture and extension principles
- π€ Contributing β how to add providers or modalities