Siumai — Unified LLM Interface for Rust
Siumai (烧卖) is a type-safe Rust library that provides a single, consistent API over multiple LLM providers. It focuses on clear abstractions, predictable behavior, and practical extensibility.
This README keeps things straightforward: what you can do, how to customize, and short examples.
What It Provides
- Unified clients for multiple providers (OpenAI, Anthropic, Google Gemini, Ollama, Groq, xAI, and OpenAI‑compatible vendors)
- Capability traits for chat, streaming, tools, vision, audio, files, embeddings, and rerank
- Streaming with start/delta/usage/end events and cancellation
- Tool calling and a lightweight orchestrator for multi‑step workflows
- Structured outputs (JSON/schema) with repair and validation helpers
- HTTP interceptors, middleware, and a simple retry facade
- Optional extras for telemetry, OpenTelemetry, schema validation, and server adapters
Install
[]
= "0.11.0-beta.1"
= { = "1", = ["rt-multi-thread", "macros"] }
Feature flags (enable only what you need):
# One provider
= { = "0.11.0-beta.1", = ["openai"] }
# Multiple providers
= { = "0.11.0-beta.1", = ["openai", "anthropic", "google"] }
# All (default)
= { = "0.11.0-beta.1", = ["all-providers"] }
Optional package for advanced utilities:
[]
= "0.11.0-beta.1"
= { = "0.11.0-beta.1", = ["schema", "telemetry", "opentelemetry", "server", "mcp"] }
Usage
Registry (recommended)
Use the registry to resolve models via provider:model and get a handle with a uniform API.
use *;
async
Supported examples of provider:model:
openai:gpt-4o,openai:gpt-4o-minianthropic:claude-3-5-sonnet-20240620gemini:gemini-2.0-flash-expgroq:llama-3.1-70b-versatilexai:grok-betaollama:llama3.2
OpenAI‑compatible vendors follow the same pattern (API keys read as {PROVIDER_ID}_API_KEY when possible). See docs for details.
Builder (unified or provider‑specific)
Provider‑specific client:
use *;
async
Unified interface (portable across providers):
use *;
async
OpenAI‑compatible (custom base URL):
use *;
async
Streaming
use StreamExt;
use *;
async
Structured output
Provider‑agnostic high‑level helper for generating typed JSON:
use Deserialize;
use *;
async
Recommended: ChatRequestBuilder + ProviderOptions (example: OpenAI Responses API):
use *;
use json;
let schema = json!;
let req = new
.message
.openai_options
.build;
let resp = client.chat_request.await?;
Retries
use *;
use ;
let text = client
.ask_with_retry
.await?;
Customization
- HTTP client and headers
- Middleware chain (defaults, clamping, reasoning extraction)
- HTTP interceptors (request/response hooks, SSE observation)
- Retry options and backoff
HTTP configuration example:
use *;
let http = builder.build?;
let client = new
.with_http_client
.with_user_agent
.with_header
.openai
.model
.build
.await?;
Registry with custom middleware and interceptors:
use *;
use chain_default_and_clamp;
use LoggingInterceptor;
use ;
use HashMap;
use Arc;
let reg = create_provider_registry;
Extras (siumai-extras)
- Telemetry subscribers and helpers
- OpenTelemetry middleware (W3C Trace Context)
- JSON schema validation
- Server adapters (Axum SSE)
- MCP utilities
See the siumai-extras crate for details and examples.
Examples
Examples are under siumai/examples/:
- 01-quickstart — basic chat, streaming, provider switching
- 02-core-api — chat, streaming, tools, multimodal
- 03-advanced-features — middleware, retry, orchestrator, error types
- 04-provider-specific — provider‑unique capabilities
- 05-integrations — registry, MCP, telemetry
- 06-applications — chatbot, code assistant, API server
Typical commands:
Status and notes
- OpenAI Responses API web_search is not implemented yet and returns
UnsupportedOperation. - Several modules were reorganized in 0.11: HTTP helpers live under
execution::http::*, Vertex helpers underauth::vertex. See CHANGELOG for migration notes.
API keys and environment variables:
- OpenAI:
.api_key(..)orOPENAI_API_KEY - Anthropic:
.api_key(..)orANTHROPIC_API_KEY - Groq:
.api_key(..)orGROQ_API_KEY - Gemini:
.api_key(..)orGEMINI_API_KEY - xAI:
.api_key(..)orXAI_API_KEY - Ollama: no API key
- OpenAI‑compatible via Registry: reads
{PROVIDER_ID}_API_KEY(e.g.,DEEPSEEK_API_KEY) - OpenAI‑compatible via Builder:
.api_key(..)or{PROVIDER_ID}_API_KEY
Acknowledgements
This project draws inspiration from:
- Vercel AI SDK (adapter patterns)
- Cherry Studio (transformer design)
Changelog and license
See CHANGELOG.md for detailed changes and migration tips.
Licensed under either of:
- Apache License, Version 2.0, or
- MIT license
at your option.