@xberg-io/liter-llm 0.0.1 → 1.9.0-rc.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,7 @@
1
+ Copyright 2026 Kreuzberg, Inc.
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,327 @@
1
- # @xberg-io/liter-llm
1
+ <p align="center">
2
+ <picture>
3
+ <source media="(prefers-color-scheme: dark)" srcset="https://cdn.jsdelivr.net/gh/xberg-io/assets@v1/banner/readme-banner-dark.svg">
4
+ <img alt="Xberg" width="420" src="https://cdn.jsdelivr.net/gh/xberg-io/assets@v1/banner/readme-banner-light.svg">
5
+ </picture>
6
+ </p>
2
7
 
3
- Placeholder release. See https://github.com/xberg-io/liter-llm
8
+ # TypeScript (Node.js)
9
+
10
+ <div align="center" style="display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin: 20px 0">
11
+ <!-- Built with -->
12
+ <a href="https://github.com/xberg-io/alef">
13
+ <img src="https://img.shields.io/badge/Bindings-alef%20%D7%90-007ec6" alt="Bindings" />
14
+ </a>
15
+ <!-- Language Bindings -->
16
+ <a href="https://crates.io/crates/liter-llm">
17
+ <img src="https://img.shields.io/crates/v/liter-llm?label=Rust&color=007ec6" alt="Rust" />
18
+ </a>
19
+ <a href="https://pypi.org/project/liter-llm/">
20
+ <img src="https://img.shields.io/pypi/v/liter-llm?label=Python&color=007ec6" alt="Python" />
21
+ </a>
22
+ <a href="https://www.npmjs.com/package/@xberg-io/liter-llm">
23
+ <img src="https://img.shields.io/npm/v/@xberg-io/liter-llm?label=Node.js&color=007ec6" alt="Node.js" />
24
+ </a>
25
+ <a href="https://www.npmjs.com/package/@xberg-io/liter-llm-wasm">
26
+ <img src="https://img.shields.io/npm/v/@xberg-io/liter-llm-wasm?label=WASM&color=007ec6" alt="WASM" />
27
+ </a>
28
+ <a href="https://central.sonatype.com/artifact/io.xberg.literllm/liter-llm">
29
+ <img src="https://img.shields.io/maven-central/v/io.xberg.literllm/liter-llm?label=Java&color=007ec6" alt="Java" />
30
+ </a>
31
+ <a href="https://github.com/xberg-io/liter-llm/tree/main/packages/go">
32
+ <img src="https://img.shields.io/github/v/tag/xberg-io/liter-llm?label=Go&color=007ec6" alt="Go" />
33
+ </a>
34
+ <a href="https://www.nuget.org/packages/LiterLlm">
35
+ <img src="https://img.shields.io/nuget/v/LiterLlm?label=C%23&color=007ec6" alt="C#" />
36
+ </a>
37
+ <a href="https://packagist.org/packages/xberg-io/liter-llm">
38
+ <img src="https://img.shields.io/packagist/v/xberg-io/liter-llm?label=PHP&color=007ec6" alt="PHP" />
39
+ </a>
40
+ <a href="https://rubygems.org/gems/liter_llm">
41
+ <img src="https://img.shields.io/gem/v/liter_llm?label=Ruby&color=007ec6" alt="Ruby" />
42
+ </a>
43
+ <a href="https://hex.pm/packages/liter_llm">
44
+ <img src="https://img.shields.io/hexpm/v/liter_llm?label=Elixir&color=007ec6" alt="Elixir" />
45
+ </a>
46
+ <a href="https://github.com/xberg-io/liter-llm/pkgs/container/liter-llm">
47
+ <img src="https://img.shields.io/badge/Docker-007ec6?logo=docker&logoColor=white" alt="Docker" />
48
+ </a>
49
+ <a href="https://github.com/xberg-io/homebrew-tap/blob/main/Formula/liter-llm.rb">
50
+ <img src="https://img.shields.io/badge/Homebrew-007ec6?logo=homebrew&logoColor=white" alt="Homebrew" />
51
+ </a>
52
+ <a href="https://github.com/xberg-io/liter-llm/tree/main/crates/liter-llm-ffi">
53
+ <img src="https://img.shields.io/badge/C-FFI-007ec6" alt="C FFI" />
54
+ </a>
55
+
56
+ <!-- Project Info -->
57
+ <a href="https://github.com/xberg-io/liter-llm/blob/main/LICENSE">
58
+ <img src="https://img.shields.io/badge/License-MIT-007ec6" alt="License" />
59
+ </a>
60
+ <a href="https://docs.liter-llm.xberg.io">
61
+ <img src="https://img.shields.io/badge/Docs-liter--llm-007ec6" alt="Docs" />
62
+ </a>
63
+ </div>
64
+ <div align="center" style="margin: 24px 0 0">
65
+ <a href="https://xberg.io">
66
+ <img
67
+ alt="xberg.io"
68
+ src="https://github.com/user-attachments/assets/1b6c6ad7-3b6d-4171-b1c9-f2026cc9deb8"
69
+ />
70
+ </a>
71
+ </div>
72
+ <div align="center" style="display: flex; flex-wrap: wrap; gap: 12px; justify-content: center; margin: 28px 0 24px">
73
+ <a href="https://discord.gg/xt9WY3GnKR">
74
+ <img
75
+ height="22"
76
+ src="https://img.shields.io/badge/Discord-Chat-007ec6?logo=discord&logoColor=white"
77
+ alt="Join Discord"
78
+ />
79
+ </a>
80
+ </div>
81
+
82
+ Universal LLM API client for TypeScript and Node.js. Access 143 LLM providers through a single interface with native NAPI-RS bindings, async/await, streaming, tool calling, and full TypeScript type definitions.
83
+
84
+ ## What This Package Provides
85
+
86
+ - **One provider surface** — chat, streaming, embeddings, images, audio, search, OCR, tools, and structured output across the provider registry.
87
+ - **Provider/model routing** — call models with the `provider/model` convention and keep provider-specific request code out of application paths.
88
+ - **Production controls** — retries, fallback, rate limits, cache layers, budgets, health checks, OpenTelemetry spans, and redacted secrets.
89
+ - **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.
90
+ - **Node-first TypeScript API** — NAPI-RS package with typed requests/responses and async iterables for streaming.
91
+
92
+ ## Installation
93
+
94
+ ### Package Installation
95
+
96
+ Install via one of the supported package managers:
97
+
98
+ **npm:**
99
+
100
+ ```bash
101
+ npm install @xberg-io/liter-llm
102
+ ```
103
+
104
+ **pnpm:**
105
+
106
+ ```bash
107
+ pnpm add @xberg-io/liter-llm
108
+ ```
109
+
110
+ **yarn:**
111
+
112
+ ```bash
113
+ yarn add @xberg-io/liter-llm
114
+ ```
115
+
116
+ ### System Requirements
117
+
118
+ - **Node.js 22+** required (NAPI-RS native bindings)
119
+ - API keys via environment variables (e.g. `OPENAI_API_KEY`, `ANTHROPIC_API_KEY`)
120
+
121
+ ### Platform Support
122
+
123
+ Pre-built binaries available for:
124
+
125
+ - macOS (arm64, x64)
126
+ - Linux (x64)
127
+ - Windows (x64)
128
+
129
+ ## Quick Start
130
+
131
+ ### Basic Chat
132
+
133
+ Send a message to any provider using the `provider/model` prefix:
134
+
135
+ ```typescript
136
+ import { createClient } from "@xberg-io/liter-llm";
137
+
138
+ const client = createClient(process.env.OPENAI_API_KEY!);
139
+ const response = await client.chat({
140
+ model: "openai/gpt-4o",
141
+ messages: [{ role: "user", content: "Hello!" }],
142
+ });
143
+ console.log(response.choices[0].message.content);
144
+ ```
145
+
146
+ ### Common Use Cases
147
+
148
+ #### Streaming Responses
149
+
150
+ Stream tokens in real time:
151
+
152
+ ```typescript
153
+ import { createClient } from "@xberg-io/liter-llm";
154
+
155
+ const client = createClient(process.env.OPENAI_API_KEY!);
156
+ const chunks = await client.chatStream({
157
+ model: "openai/gpt-4o",
158
+ messages: [{ role: "user", content: "Tell me a story" }],
159
+ });
160
+
161
+ for await (const chunk of chunks) {
162
+ process.stdout.write(chunk.choices?.[0]?.delta?.content ?? "");
163
+ }
164
+ console.log();
165
+ ```
166
+
167
+ #### Tool Calling
168
+
169
+ Define and invoke tools:
170
+
171
+ ```typescript
172
+ import { createClient, ToolType } from "@xberg-io/liter-llm";
173
+
174
+ const client = createClient(process.env.OPENAI_API_KEY!);
175
+
176
+ const response = await client.chat({
177
+ model: "openai/gpt-4o",
178
+ messages: [{ role: "user", content: "What is the weather in Berlin?" }],
179
+ tools: [
180
+ {
181
+ toolType: ToolType.Function,
182
+ function: {
183
+ name: "get_weather",
184
+ description: "Get the current weather for a location",
185
+ parameters: {
186
+ type: "object",
187
+ properties: { location: { type: "string" } },
188
+ required: ["location"],
189
+ },
190
+ },
191
+ },
192
+ ],
193
+ });
194
+
195
+ for (const call of response.choices[0]?.message?.toolCalls ?? []) {
196
+ console.log(`Tool: ${call.function.name}, Args: ${call.function.arguments}`);
197
+ }
198
+ ```
199
+
200
+ ### Next Steps
201
+
202
+ - **[Provider Registry](https://github.com/xberg-io/liter-llm/blob/main/schemas/providers.json)** - Full list of supported providers
203
+ - **[GitHub Repository](https://github.com/xberg-io/liter-llm)** - Source, issues, and discussions
204
+
205
+ ## NAPI-RS Implementation Details
206
+
207
+ ### Native Performance
208
+
209
+ This binding uses NAPI-RS to provide native Node.js bindings with:
210
+
211
+ - **Zero-copy data transfer** between JavaScript and Rust layers
212
+ - **Async by default** — all LLM calls return Promises backed by Tokio
213
+ - **Binary-compatible** pre-built native modules across platforms
214
+ - **TypeScript definitions** generated automatically from Rust types
215
+
216
+ ### Threading Model
217
+
218
+ - LLM calls are non-blocking — Tokio async runtime handles concurrency
219
+ - Streaming responses use Node.js async iterators backed by Tokio streams
220
+ - CPU-bound work runs in `spawn_blocking` to avoid blocking the event loop
221
+
222
+ ### Memory Management
223
+
224
+ - API keys are wrapped in `secrecy::SecretString` and never logged
225
+ - Streaming buffers are released as soon as each chunk is consumed
226
+ - Provider registry is compiled into the binary — no runtime disk access
227
+
228
+ ## Features
229
+
230
+ ### Supported Providers (143)
231
+
232
+ Route to any provider using the `provider/model` prefix convention:
233
+
234
+ | Provider | Example Model |
235
+ | ------------------ | ------------------------------------------------------------- |
236
+ | **OpenAI** | `openai/gpt-4o`, `openai/gpt-4o-mini` |
237
+ | **Anthropic** | `anthropic/claude-3-5-sonnet-20241022` |
238
+ | **Groq** | `groq/llama-3.1-70b-versatile` |
239
+ | **Mistral** | `mistral/mistral-large-latest` |
240
+ | **Cohere** | `cohere/command-r-plus` |
241
+ | **Together AI** | `together/meta-llama/Meta-Llama-3.1-70B-Instruct-Turbo` |
242
+ | **Fireworks** | `fireworks/accounts/fireworks/models/llama-v3p1-70b-instruct` |
243
+ | **Google Vertex** | `vertexai/gemini-1.5-pro` |
244
+ | **Amazon Bedrock** | `bedrock/anthropic.claude-3-5-sonnet-20241022-v2:0` |
245
+
246
+ **[Complete Provider List](https://github.com/xberg-io/liter-llm/blob/main/schemas/providers.json)**
247
+
248
+ ### Key Capabilities
249
+
250
+ - **Provider Routing** -- Single client for 143 LLM providers via `provider/model` prefix
251
+ - **Local LLMs** — Connect to locally-hosted models via Ollama, LM Studio, vLLM, llama.cpp, and other local inference servers
252
+ - **Unified API** -- Consistent `chat`, `chat_stream`, `embeddings`, `list_models` interface
253
+ - **Streaming** -- Real-time token streaming via `chat_stream`
254
+ - **Tool Calling** -- Function calling and tool use across all supporting providers
255
+ - **Type Safe** -- Schema-driven types compiled from JSON schemas
256
+ - **Secure** -- API keys never logged or serialized, managed via environment variables
257
+ - **Observability** -- Built-in [OpenTelemetry](https://opentelemetry.io/docs/specs/semconv/gen-ai/) with GenAI semantic conventions
258
+ - **Error Handling** -- Structured errors with provider context and retry hints
259
+
260
+ ### Performance
261
+
262
+ Built on a compiled Rust core for speed and safety:
263
+
264
+ - **Provider resolution** at client construction -- zero per-request overhead
265
+ - **Configurable timeouts** and connection pooling
266
+ - **Zero-copy streaming** with SSE and AWS EventStream support
267
+ - **API keys** wrapped in secure memory, zeroed on drop
268
+
269
+ ## Provider Routing
270
+
271
+ Route to 143 providers using the `provider/model` prefix convention:
272
+
273
+ ```text
274
+ openai/gpt-4o
275
+ anthropic/claude-3-5-sonnet-20241022
276
+ groq/llama-3.1-70b-versatile
277
+ mistral/mistral-large-latest
278
+ ```
279
+
280
+ See the [provider registry](https://github.com/xberg-io/liter-llm/blob/main/schemas/providers.json) for the full list.
281
+
282
+ ## Proxy, MCP Server & Plugin
283
+
284
+ <details>
285
+ <summary><strong>Run the OpenAI-compatible proxy or the MCP server</strong></summary>
286
+
287
+ Beyond the SDK, the `liter-llm` CLI ships an OpenAI-compatible proxy and a Model Context Protocol (MCP) server:
288
+
289
+ ```bash
290
+ brew install xberg-io/tap/liter-llm # or: cargo install liter-llm-cli
291
+ liter-llm api --config liter-llm-proxy.toml # OpenAI-compatible proxy
292
+ liter-llm mcp --transport stdio # MCP tool server
293
+
294
+ # or run the proxy without installing:
295
+ docker run -p 4000:4000 -e LITER_LLM_MASTER_KEY=sk-your-key ghcr.io/xberg-io/liter-llm
296
+ ```
297
+
298
+ To use the MCP server inside a coding agent, install the **liter-llm plugin** from the [`xberg-io/plugins`](https://github.com/xberg-io/plugins) marketplace — it auto-registers the server. See the [MCP server](https://docs.liter-llm.xberg.io/server/mcp-server/) and [proxy server](https://docs.liter-llm.xberg.io/server/proxy-server/) guides for configuration, CLI usage, and agent integration.
299
+
300
+ </details>
301
+
302
+ ## Documentation
303
+
304
+ - **[Documentation](https://docs.liter-llm.xberg.io)** -- Full docs and API reference
305
+ - **[GitHub Repository](https://github.com/xberg-io/liter-llm)** -- Source, issues, and discussions
306
+ - **[Provider Registry](https://github.com/xberg-io/liter-llm/blob/main/schemas/providers.json)** -- 143 supported providers
307
+
308
+ ## Part of Xberg.io
309
+
310
+ - [Xberg](https://github.com/xberg-io/xberg) — document intelligence: text, tables, metadata from 91+ formats with optional OCR.
311
+ - [Xberg Enterprise](https://github.com/xberg-io/xberg-enterprise) — managed extraction API with SDKs, dashboards, and observability.
312
+ - [crawlberg](https://github.com/xberg-io/crawlberg) — web crawling and scraping with HTML→Markdown and headless-Chrome fallback.
313
+ - [html-to-markdown](https://github.com/xberg-io/html-to-markdown) — fast, lossless HTML→Markdown engine.
314
+ - [liter-llm](https://github.com/xberg-io/liter-llm) — universal LLM API client with native bindings for 14 languages and 143 providers.
315
+ - [tree-sitter-language-pack](https://github.com/xberg-io/tree-sitter-language-pack) — tree-sitter grammars and code-intelligence primitives.
316
+ - [alef](https://github.com/xberg-io/alef) — the polyglot binding generator that produces every per-language binding across the 5 polyglot repos.
317
+ - [Discord](https://discord.gg/xt9WY3GnKR) — community, roadmap, announcements.
318
+
319
+ ## Contributing
320
+
321
+ Contributions are welcome! See [CONTRIBUTING.md](https://github.com/xberg-io/liter-llm/blob/main/CONTRIBUTING.md) for guidelines.
322
+
323
+ Join our [Discord community](https://discord.gg/xt9WY3GnKR) for questions and discussion.
324
+
325
+ ## License
326
+
327
+ MIT -- see [LICENSE](https://github.com/xberg-io/liter-llm/blob/main/LICENSE) for details.