Back to Runanywhere Sdks

RunAnywhere Kotlin SDK

sdk/runanywhere-kotlin/README.md

0.20.125.5 KB
Original Source

RunAnywhere Kotlin SDK

Privacy-first, on-device AI for Android. Run large language models, speech-to-text, text-to-speech, and voice agents locally with a single Kotlin API — optional cloud fallback, OTA model updates, and built-in observability.


Requirements

RequirementMinimum
AndroidAPI 24+ (Android 7.0+)
Kotlin2.0+
JVMJava 17+

Installation

Add dependencies to your app module's build.gradle.kts:

kotlin
dependencies {
    // Core SDK (required)
    implementation("io.github.sanchitmonga22:runanywhere-sdk:0.20.12")

    // LLM support via llama.cpp (~34 MB)
    implementation("io.github.sanchitmonga22:runanywhere-llamacpp:0.20.12")

    // Optional: STT, TTS, VAD via ONNX/Sherpa (~25 MB)
    implementation("io.github.sanchitmonga22:runanywhere-onnx:0.20.12")
}

Ensure INTERNET permission is declared for model downloads and SDK authentication:

xml
<uses-permission android:name="android.permission.INTERNET" />

Quick Start

kotlin
import ai.runanywhere.proto.v1.ModelCategory
import ai.runanywhere.proto.v1.SDKEnvironment
import com.runanywhere.sdk.llm.llamacpp.LlamaCPP
import com.runanywhere.sdk.public.RunAnywhere
import com.runanywhere.sdk.public.extensions.downloadModelStream
import com.runanywhere.sdk.public.extensions.generate
import com.runanywhere.sdk.public.extensions.loadModel
import com.runanywhere.sdk.public.types.RAModelInfo
import com.runanywhere.sdk.public.types.RAModelLoadRequest
import kotlinx.coroutines.launch

class MyApplication : Application() {
    override fun onCreate() {
        super.onCreate()

        LlamaCPP.register()

        RunAnywhere.initialize(
            context = this,
            environment = SDKEnvironment.SDK_ENVIRONMENT_DEVELOPMENT,
        )
    }
}

// In a coroutine scope (e.g. lifecycleScope):
suspend fun runInference() {
    val modelId = "smollm2-360m-instruct-q8_0"

    RunAnywhere.downloadModelStream(RAModelInfo(id = modelId)).collect { progress ->
        // Update UI with progress.overall_progress
    }

    RunAnywhere.loadModel(
        RAModelLoadRequest(
            model_id = modelId,
            category = ModelCategory.MODEL_CATEGORY_LANGUAGE,
        ),
    )

    val result = RunAnywhere.generate("What is the capital of France?")
    println(result.text)
}

Register optional backends before initialization when needed:

kotlin
import com.runanywhere.sdk.core.onnx.ONNX

ONNX.register()  // STT, TTS, VAD (requires runanywhere-onnx artifact)

Capabilities

CapabilityArtifactModel formatsNotes
LLMrunanywhere-llamacppGGUF (.gguf)Streaming, structured output, tool calling
STTrunanywhere-onnxONNX (.onnx, .ort)Whisper, Sherpa streaming
TTSrunanywhere-onnxONNX, Piper voicesSystem TTS via Android TextToSpeech
VLMrunanywhere-llamacppGGUF multimodalImage + text inference
VoiceCore + backendsVAD → STT → LLM → TTS pipeline
NPUrunanywhere-qhexrt-android (optional)QNN / HexagonQualcomm devices only

Supported model formats

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

Models are managed through the SDK catalog and lifecycle APIs: RunAnywhere.downloadModelStream(), RunAnywhere.loadModel(), and RunAnywhere.listModels().


Documentation and Examples

ResourceLink
Docsdocs.runanywhere.ai/kotlin/introduction
API referencedocs/Documentation.md
Example appexamples/android/RunAnywhereAI/
Contributing / local builddocs/DEVELOPMENT.md
Architecturedocs/ARCHITECTURE.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].