anyllm
Provider-agnostic LLM abstractions for Rust.
anyllm is a low-level crate for code that wants one interface for LLM APIs
(both chat and embeddings) while leaving HTTP transport, request translation,
and response parsing to provider implementations.
Use it when you want to:
- write application code against one provider-neutral contract
- implement a provider adapter on top of shared request and response types
- normalize streaming, tool calls, and metadata across providers
- produce embedding vectors from multiple providers with a single trait
anyllm is intentionally not a provider client and not an agent framework.
You May Be Looking For
- API docs: https://docs.rs/anyllm
ChatProvider: https://docs.rs/anyllm/latest/anyllm/trait.ChatProvider.htmlEmbeddingProvider: https://docs.rs/anyllm/latest/anyllm/trait.EmbeddingProvider.html- chat example: https://github.com/sagikazarmark/anyllm/blob/main/crates/anyllm/examples/chat.rs
- embedding example: https://github.com/sagikazarmark/anyllm/blob/main/crates/anyllm/examples/embedding.rs
- streaming example: https://github.com/sagikazarmark/anyllm/blob/main/crates/anyllm/examples/stream.rs
- provider implementation example: https://github.com/sagikazarmark/anyllm/blob/main/crates/anyllm/examples/provider_impl.rs
Example
This example uses the built-in mock provider, so it runs without credentials.
[]
= { = "0.1", = ["mock"] }
= { = "1", = ["macros", "rt-multi-thread"] }
use *;
async
From the workspace root:
Features
Default features are empty.
| Feature | What it enables |
|---|---|
extract |
structured extraction helpers such as ExtractExt, Extractor, and ExtractingProvider |
mock |
deterministic mock providers (MockProvider, MockStreamingProvider, MockEmbeddingProvider) and response builders for tests and examples |
tracing |
tracing-based instrumentation via TracingChatProvider |
Implementing A Provider
If you are writing a provider, implement ProviderIdentity first, then whichever
capability traits apply: ChatProvider, EmbeddingProvider, or both.
Chat providers with native streaming return their own concrete stream type from
chat_stream(). Providers without native streaming can return
SingleResponseStream and still participate in the same streaming contract.
Embedding providers implement a single batch-oriented embed() method.
If you need a working skeleton, start here: