@kreuzberg/liter-llm-wasm
v1.8.2
Published
Universal LLM API client with Rust-powered polyglot bindings.
Maintainers
Readme
WebAssembly
<!-- Project Info -->
<a href="https://github.com/kreuzberg-dev/liter-llm/blob/main/LICENSE">
<img src="https://img.shields.io/badge/License-MIT-007ec6" alt="License" />
</a>
<a href="https://docs.liter-llm.kreuzberg.dev">
<img src="https://img.shields.io/badge/Docs-liter--llm-007ec6" alt="Docs" />
</a>Universal LLM API client for browsers and WebAssembly runtimes. Access 143 LLM providers with portable deployment across browsers, Deno, and Cloudflare Workers.
What This Package Provides
- One provider surface — chat, streaming, embeddings, images, audio, search, OCR, tools, and structured output across the provider registry.
- Provider/model routing — call models with the
provider/modelconvention and keep provider-specific request code out of application paths. - Production controls — retries, fallback, rate limits, cache layers, budgets, health checks, OpenTelemetry spans, and redacted secrets.
- Same core as every binding — Rust, Python, Node.js, Go, Java, PHP, Ruby, .NET, Elixir, WASM, Kotlin Android, Swift, Dart, Zig, and C FFI use the same Rust implementation.
- WASM package — browser and edge-compatible client for provider calls from WebAssembly runtimes.
Installation
Package Installation
Install via one of the supported package managers:
npm:
npm install @kreuzberg/liter-llm-wasmpnpm:
pnpm add @kreuzberg/liter-llm-wasmyarn:
yarn add @kreuzberg/liter-llm-wasmSystem Requirements
- Modern browser with WebAssembly support, or Deno 1.0+, or Cloudflare Workers
- API keys via environment variables or runtime configuration
Quick Start
Basic Chat
Send a message to any provider using the provider/model prefix:
import init, { createClient, WasmChatCompletionRequest } from "@kreuzberg/liter-llm-wasm";
await init();
const client = createClient(process.env.OPENAI_API_KEY!);
const request = WasmChatCompletionRequest.default();
request.model = "openai/gpt-4o";
request.messages = [{ role: "user", content: "Hello!" }];
const response = await client.chat(request);
console.log(response.choices[0].message.content);Common Use Cases
Streaming Responses
Stream tokens in real time:
import init, { createClient, WasmChatCompletionRequest } from "@kreuzberg/liter-llm-wasm";
await init();
const client = createClient(process.env.OPENAI_API_KEY!);
const request = WasmChatCompletionRequest.default();
request.model = "openai/gpt-4o";
request.messages = [{ role: "user", content: "Tell me a story" }];
request.stream = true;
const stream = await client.chatStream(request);
while (true) {
const chunk = await stream.next();
if (chunk === null) {
break;
}
process.stdout.write(chunk.choices?.[0]?.delta?.content ?? "");
}
console.log();Next Steps
- Provider Registry - Full list of supported providers
- GitHub Repository - Source, issues, and discussions
Features
Supported Providers (143)
Route to any provider using the provider/model prefix convention:
| Provider | Example Model |
| ------------------ | ------------------------------------------------------------- |
| OpenAI | openai/gpt-4o, openai/gpt-4o-mini |
| Anthropic | anthropic/claude-3-5-sonnet-20241022 |
| Groq | groq/llama-3.1-70b-versatile |
| Mistral | mistral/mistral-large-latest |
| Cohere | cohere/command-r-plus |
| Together AI | together/meta-llama/Meta-Llama-3.1-70B-Instruct-Turbo |
| Fireworks | fireworks/accounts/fireworks/models/llama-v3p1-70b-instruct |
| Google Vertex | vertexai/gemini-1.5-pro |
| Amazon Bedrock | bedrock/anthropic.claude-3-5-sonnet-20241022-v2:0 |
Key Capabilities
- Provider Routing -- Single client for 143 LLM providers via
provider/modelprefix - Local LLMs — Connect to locally-hosted models via Ollama, LM Studio, vLLM, llama.cpp, and other local inference servers
- Unified API -- Consistent
chat,chat_stream,embeddings,list_modelsinterface - Streaming -- Real-time token streaming via
chat_stream - Tool Calling -- Function calling and tool use across all supporting providers
- Type Safe -- Schema-driven types compiled from JSON schemas
- Secure -- API keys never logged or serialized, managed via environment variables
- Observability -- Built-in OpenTelemetry with GenAI semantic conventions
- Error Handling -- Structured errors with provider context and retry hints
Performance
Built on a compiled Rust core for speed and safety:
- Provider resolution at client construction -- zero per-request overhead
- Configurable timeouts and connection pooling
- Zero-copy streaming with SSE and AWS EventStream support
- API keys wrapped in secure memory, zeroed on drop
Provider Routing
Route to 143 providers using the provider/model prefix convention:
openai/gpt-4o
anthropic/claude-3-5-sonnet-20241022
groq/llama-3.1-70b-versatile
mistral/mistral-large-latestSee the provider registry for the full list.
Proxy, MCP Server & Plugin
Beyond the SDK, the liter-llm CLI ships an OpenAI-compatible proxy and a Model Context Protocol (MCP) server:
brew install kreuzberg-dev/tap/liter-llm # or: cargo install liter-llm-cli
liter-llm api --config liter-llm-proxy.toml # OpenAI-compatible proxy
liter-llm mcp --transport stdio # MCP tool server
# or run the proxy without installing:
docker run -p 4000:4000 -e LITER_LLM_MASTER_KEY=sk-your-key ghcr.io/kreuzberg-dev/liter-llmTo use the MCP server inside a coding agent, install the liter-llm plugin from the kreuzberg-dev/plugins marketplace — it auto-registers the server. See the MCP server and proxy server guides for configuration, CLI usage, and agent integration.
Documentation
- Documentation -- Full docs and API reference
- GitHub Repository -- Source, issues, and discussions
- Provider Registry -- 143 supported providers
Part of Kreuzberg.dev
- Kreuzberg — document intelligence: text, tables, metadata from 91+ formats with optional OCR.
- Kreuzberg Cloud — managed extraction API with SDKs, dashboards, and observability.
- kreuzcrawl — web crawling and scraping with HTML→Markdown and headless-Chrome fallback.
- html-to-markdown — fast, lossless HTML→Markdown engine.
- liter-llm — universal LLM API client with native bindings for 14 languages and 143 providers.
- tree-sitter-language-pack — tree-sitter grammars and code-intelligence primitives.
- alef — the polyglot binding generator that produces every per-language binding across the 5 polyglot repos.
- Discord — community, roadmap, announcements.
Contributing
Contributions are welcome! See CONTRIBUTING.md for guidelines.
Join our Discord community for questions and discussion.
License
MIT -- see LICENSE for details.
