Back to Runanywhere Sdks

RunAnywhere Swift SDK

sdk/runanywhere-swift/README.md

0.20.126.2 KB
Original Source

RunAnywhere Swift SDK

Run large language models, speech recognition, text-to-speech, and voice agents directly on iPhone, iPad, and Mac — with low latency and on-device privacy. The Swift SDK provides a unified API over pluggable backends (llama.cpp, ONNX, Apple MLX) so you can ship AI features without sending user data to the cloud for inference.


Requirements

RequirementMinimum
iOS17.5+
macOS14.5+
Swift6.2
Xcode26+

Installation

Swift Package Manager

In Xcode: File → Add Package Dependencies… and enter:

https://github.com/RunanywhereAI/runanywhere-sdks

Select version 0.20.11 (or from: "0.20.11"), then add the products you need. Resolve against the newest tag on the Releases page if 0.20.11 binary assets are not published yet.

ProductRequiredCapabilities
RunAnywhereYesCore SDK, model lifecycle, events
RunAnywhereLlamaCPPFor LLM/VLMGGUF models via llama.cpp + Metal
RunAnywhereONNXFor STT/TTS/VADWhisper, Piper, Sherpa-ONNX
RunAnywhereMLXFor MLX modelsApple MLX LLM, VLM, STT, TTS

Package.swift

swift
dependencies: [
    .package(url: "https://github.com/RunanywhereAI/runanywhere-sdks", from: "0.20.11")
],
targets: [
    .target(
        name: "YourApp",
        dependencies: [
            .product(name: "RunAnywhere", package: "runanywhere-sdks"),
            .product(name: "RunAnywhereLlamaCPP", package: "runanywhere-sdks"),
            .product(name: "RunAnywhereONNX", package: "runanywhere-sdks"),
        ]
    )
]

Quick Start

swift
import RunAnywhere
import LlamaCPPRuntime

@main
struct MyApp: App {
    init() {
        Task { @MainActor in
            // 1. Register the LLM backend
            LlamaCPP.register()

            // 2. Initialize the SDK
            try RunAnywhere.initialize(
                apiKey: "<YOUR_API_KEY>",
                baseURL: "https://api.runanywhere.ai",
                environment: .production
            )

            // 3. Load a model
            var loadRequest = RAModelLoadRequest()
            loadRequest.modelID = "llama-3.2-1b-instruct-q4"
            loadRequest.category = .language
            let loadResult = await RunAnywhere.loadModel(loadRequest)
            guard loadResult.success else { return }

            // 4. Generate text
            var request = RALLMGenerateRequest()
            request.prompt = "What is the capital of France?"
            var options = RALLMGenerationOptions.defaults()
            options.maxTokens = 128
            request.options = options

            let result = try await RunAnywhere.generate(request)
            print(result.text)
        }
    }

    var body: some Scene {
        WindowGroup { ContentView() }
    }
}

For development without an API key, call try RunAnywhere.initialize() with the default .development environment.


Capabilities

CapabilityBackendsModel formatsNotes
LLMRunAnywhereLlamaCPP, RunAnywhereMLXGGUF (.gguf)Streaming, structured output, tool calling
STTRunAnywhereONNX, RunAnywhereMLXONNX (.onnx, .ort)Whisper, Sherpa streaming
TTSRunAnywhereONNX, RunAnywhereMLXONNX, Piper voicesSystem TTS also available
VLMRunAnywhereLlamaCPP, RunAnywhereMLXGGUF multimodalImage + text inference
VoiceCore + STT + LLM + TTS backendsVAD → STT → LLM → TTS pipeline
NPUNot available on Apple platforms via this SDK

Register each backend module before using its capabilities:

swift
LlamaCPP.register()  // LLM + VLM
ONNX.register()      // STT + TTS + VAD (requires RunAnywhereONNX)
MLX.register()       // MLX modalities (requires RunAnywhereMLX)

Supported model formats

FormatExtensionBackendUse case
GGUF.ggufllama.cppLLM, VLM text generation
ONNX.onnxONNX RuntimeSTT, TTS, VAD
ORT.ortONNX RuntimeOptimized STT/TTS

Models are discovered through the RunAnywhere catalog, downloaded on-device, and managed via RunAnywhere.loadModel(_:), RunAnywhere.downloadModel(_:onProgress:), and related lifecycle APIs.


Documentation and Examples

ResourceLink
Docsdocs.runanywhere.ai/swift/introduction
Example appexamples/ios/RunAnywhereAI/
Contributing / local builddocs/DEVELOPMENT.md

Privacy

Inference runs on-device after models are downloaded. Network access is used for SDK authentication, model downloads, and optional analytics — prompts, responses, and audio are not sent to the cloud for inference by default.

Compliance with regulations such as HIPAA or GDPR depends on your deployment, data handling practices, and backend configuration. Review your architecture and consult legal counsel for regulated use cases.


Support


License

Copyright © 2026 RunAnywhere AI. All rights reserved.

This SDK is distributed under the RunAnywhere License. For commercial licensing inquiries, contact [email protected].