On-device LLM inference for Swift — optimized for Apple silicon.
Rust SDK · Flutter SDK · Website
In Xcode: File → Add Package Dependencies and enter:
https://github.com/ondeinference/onde-swift
Or add it to your Package.swift:
dependencies: [
.package(url: "https://github.com/ondeinference/onde-swift", from: "0.1.0")
],
targets: [
.target(name: "MyApp", dependencies: [
.product(name: "Onde", package: "onde-swift")
])
]| Platform | Minimum | GPU Backend |
|---|---|---|
| iOS | 15.0 | Metal |
| macOS | 11.0 | Metal |
| tvOS | 15.0 | Metal |
import Onde
let engine = OndeChatEngine()
// Load the platform-appropriate default model:
// iOS / tvOS → Qwen 2.5 1.5B (~941 MB)
// macOS → Qwen 2.5 3B (~1.93 GB)
let elapsed = try await engine.loadDefaultModel(
systemPrompt: "You are a helpful assistant.",
sampling: nil
)
let result = try await engine.sendMessage(message: "Hello!")
print(result.text)import Onde
class StreamHandler: StreamChunkListener {
func onChunk(chunk: StreamChunk) -> Bool {
print(chunk.delta, terminator: "")
return !chunk.done
}
}
try await streamChatMessage(
engine: engine,
message: "Tell me a story.",
listener: StreamHandler()
)Run inference without modifying conversation history:
let result = try await engine.generate(
messages: [userMessage(content: "Expand: a cat in space")],
sampling: deterministicSamplingConfig()
)On iOS and App Store macOS, the default ~/.cache/huggingface is outside the app sandbox. This helper seeds HF_HOME inside the App Group shared container (group.com.ondeinference.apps) so all Onde-powered apps share downloaded models. Call once at app launch before creating an OndeChatEngine.
import Foundation
func setupInferenceEnvironment() {
guard let container = FileManager.default.containerURL(
forSecurityApplicationGroupIdentifier: "group.com.ondeinference.apps"
) else {
// Fall back to app-private Application Support if App Group is unavailable.
let appSupport = FileManager.default
.urls(for: .applicationSupportDirectory, in: .userDomainMask)[0]
setupHfCache(at: appSupport)
return
}
setupHfCache(at: container)
}
private func setupHfCache(at base: URL) {
let hfHome = base.appendingPathComponent("models")
let hfHub = hfHome.appendingPathComponent("hub")
try? FileManager.default.createDirectory(at: hfHub, withIntermediateDirectories: true)
setenv("HF_HOME", hfHome.path, 1)
setenv("HF_HUB_CACHE", hfHub.path, 1)
let tmp = base.appendingPathComponent("tmp")
try? FileManager.default.createDirectory(at: tmp, withIntermediateDirectories: true)
setenv("TMPDIR", tmp.path, 1)
}Onde is dual-licensed under MIT and Apache 2.0. You may use it under either license at your option.
© 2026 Splitfire AB
© 2026 Onde Inference