Universal LLM API client for Swift. Access 143 LLM providers through a single Swift Concurrency-native interface (async/await, AsyncSequence streaming) with Codable request/response types.
## 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/model` convention 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.
- **SwiftPM package** — Swift Concurrency API with Codable request/response types.
## Installation
### Package Installation
The Swift binding ships as a pre-built artifact bundle. No Rust toolchain required.
Each release at attaches:
- `LiterLlm-rs.artifactbundle.zip` — the prebuilt artifact bundle
- `LiterLlm-rs.artifactbundle.zip.checksum` — the SwiftPM checksum
- `Package.swift` — `Package.swift` with version + checksum already substituted
**Recommended** — add a `.binaryTarget` to your own `Package.swift`, copying the URL and checksum from the release notes:
```swift
.binaryTarget(
name: "LiterLlm",
url: "https://github.com/xberg-io/liter-llm/releases/download/v1.9.2/LiterLlm-rs.artifactbundle.zip",
checksum: ""
)
```
**Alternative** — download the release-attached `Package.swift` and copy it into your project root.
> The repository's checked-in `Package.swift` on `main` uses placeholder values and is not usable as-is. The `.package(url: ..., from: ...)` SwiftPM pattern is **not supported** because release tags carry the placeholder file; pull the release-attached `Package.swift` or use `.binaryTarget` directly.
### System Requirements
- **Swift 6.0+** with SwiftPM
- Pre-built artifact bundle for macOS (arm64, x86_64), iOS, iOS Simulator
- API keys via environment variables (e.g. `OPENAI_API_KEY`, `ANTHROPIC_API_KEY`)
## Quick Start
### Basic Chat
Send a message to any provider using the `provider/model` prefix:
```swift
import Foundation
import LiterLlm
let client = try await LiterLlm.createClient(apiKey: ProcessInfo.processInfo.environment["OPENAI_API_KEY"] ?? "")
let request = ChatCompletionRequest(
model: "openai/gpt-4o",
messages: [.user(.init(content: .of("Hello!")))],
temperature: nil, topP: nil, maxTokens: nil, toolChoice: nil, tools: nil, responseFormat: nil
)
let response = try await client.chat(request)
print(response.choices[0].message.content ?? "")
```
### Common Use Cases
### Next Steps
- **[Provider Registry](https://github.com/xberg-io/liter-llm/blob/main/schemas/providers.json)** - Full list of supported providers
- **[GitHub Repository](https://github.com/xberg-io/liter-llm)** - 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` |
**[Complete Provider List](https://github.com/xberg-io/liter-llm/blob/main/schemas/providers.json)**
### Key Capabilities
- **Provider Routing** -- Single client for 143 LLM providers via `provider/model` prefix
- **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_models` interface
- **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](https://opentelemetry.io/docs/specs/semconv/gen-ai/) 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:
```text
openai/gpt-4o
anthropic/claude-3-5-sonnet-20241022
groq/llama-3.1-70b-versatile
mistral/mistral-large-latest
```
See the [provider registry](https://github.com/xberg-io/liter-llm/blob/main/schemas/providers.json) for the full list.
## Proxy, MCP Server & Plugin
Run the OpenAI-compatible proxy or the MCP server
Beyond the SDK, the `liter-llm` CLI ships an OpenAI-compatible proxy and a Model Context Protocol (MCP) server:
```bash
brew install xberg-io/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/xberg-io/liter-llm
```
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.
## Documentation
- **[Documentation](https://docs.liter-llm.xberg.io)** -- Full docs and API reference
- **[GitHub Repository](https://github.com/xberg-io/liter-llm)** -- Source, issues, and discussions
- **[Provider Registry](https://github.com/xberg-io/liter-llm/blob/main/schemas/providers.json)** -- 143 supported providers
## Part of Xberg.io
- [Xberg](https://github.com/xberg-io/xberg) — document intelligence: text, tables, metadata from 91+ formats with optional OCR.
- [Xberg Enterprise](https://github.com/xberg-io/xberg-enterprise) — managed extraction API with SDKs, dashboards, and observability.
- [crawlberg](https://github.com/xberg-io/crawlberg) — web crawling and scraping with HTML→Markdown and headless-Chrome fallback.
- [html-to-markdown](https://github.com/xberg-io/html-to-markdown) — fast, lossless HTML→Markdown engine.
- [liter-llm](https://github.com/xberg-io/liter-llm) — universal LLM API client with native bindings for 14 languages and 143 providers.
- [tree-sitter-language-pack](https://github.com/xberg-io/tree-sitter-language-pack) — tree-sitter grammars and code-intelligence primitives.
- [alef](https://github.com/xberg-io/alef) — the polyglot binding generator that produces every per-language binding across the 5 polyglot repos.
- [Discord](https://discord.gg/xt9WY3GnKR) — community, roadmap, announcements.
## Contributing
Contributions are welcome! See [CONTRIBUTING.md](https://github.com/xberg-io/liter-llm/blob/main/CONTRIBUTING.md) for guidelines.
Join our [Discord community](https://discord.gg/xt9WY3GnKR) for questions and discussion.
## License
MIT -- see [LICENSE](https://github.com/xberg-io/liter-llm/blob/main/LICENSE) for details.