- Swift
- Kotlin
- React Native
- Flutter
- Web
- Electron
1. Install
Add the package in Xcode via File → Add Package Dependencies… with the URLhttps://github.com/RunanywhereAI/runanywhere-swift, or declare it:Package.swift
dependencies: [
.package(url: "https://github.com/RunanywhereAI/runanywhere-swift", from: "0.20.24")
],
targets: [
.target(
name: "YourApp",
dependencies: [
.product(name: "RunAnywhere", package: "runanywhere-swift"),
.product(name: "RunAnywhereLlamaCPP", package: "runanywhere-swift"),
]
)
]
2. Register a backend, then initialize
Register backends beforeinitialize(). Do it after and the first model load fails
with “No provider could handle the request”.import RunAnywhere
import RunAnywhereLlamaCPP
LlamaCPP.register()
try RunAnywhere.initialize(apiKey: "", baseUrl: "", environment: .development)
3. Generate
let result = try await RunAnywhere.llm.generate(
prompt: "Explain on-device AI in one sentence",
options: LlmOptions(model: "qwen3-0.6b", maxOutputTokens: 100)
)
print(result.text)
4. Stream
for try await event in try await RunAnywhere.llm.generateStream(prompt: "Write a haiku") {
if case .token(let token) = event { print(token.text, terminator: "") }
}
1. Install
build.gradle.kts (Module: app)
dependencies {
implementation("io.github.sanchitmonga22:runanywhere-sdk:0.20.27")
implementation("io.github.sanchitmonga22:runanywhere-llamacpp:0.20.27")
implementation("io.github.sanchitmonga22:runanywhere-onnx:0.20.27")
// QHexRT stops at 0.20.19; it is not published past that
implementation("io.github.sanchitmonga22:runanywhere-qhexrt-android:0.20.19")
}
2. Import both packages
import com.runanywhere.sdk.public.RunAnywhere
import com.runanywhere.sdk.public.api.*
RunAnywhere.llm does
not resolve.3. Initialize
class App : Application() {
override fun onCreate() {
super.onCreate()
RunAnywhere.initialize(apiKey = "", baseUrl = "")
}
}
4. Generate
val result = RunAnywhere.llm.generate(
"Explain on-device AI in one sentence",
LlmOptions(model = "qwen3-0.6b", maxOutputTokens = 100)
)
println(result.text)
RunAnywhere.llm.generateStream("Write a haiku").collect { event ->
if (event is GenerationEvent.Token) print(event.text)
}
1. Install
npm install @runanywhere/core @runanywhere/llamacpp @runanywhere/onnx
cd ios && pod install
2. Register a backend, then initialize
import { RunAnywhere } from '@runanywhere/core';
import { LlamaCPP } from '@runanywhere/llamacpp';
await LlamaCPP.register();
await RunAnywhere.initialize({});
3. Generate
const result = await RunAnywhere.llm.generate('Explain on-device AI in one sentence', {
model: 'qwen3-0.6b',
maxOutputTokens: 100,
});
console.log(result.text);
4. Stream
for await (const event of RunAnywhere.llm.generateStream('Write a haiku')) {
if (event.type === 'textDelta') setText((t) => t + event.text);
}
AudioInputs, ImageInputs.Full React Native guide →1. Install
pubspec.yaml
dependencies:
runanywhere: ^0.20.27
runanywhere_llamacpp: ^0.20.27
runanywhere_onnx: ^0.20.27
# QHexRT publishes at 0.20.19
runanywhere_qhexrt: ^0.20.19
>=3.12.0, iOS 17.5, Android API 24.2. Register a backend, then initialize
import 'package:runanywhere/runanywhere.dart';
import 'package:runanywhere_llamacpp/runanywhere_llamacpp.dart';
await LlamaCpp.register();
await RunAnywhere.initialize(apiKey: '', baseUrl: '');
3. Generate
final result = await RunAnywhere.llm.generate(
'Explain on-device AI in one sentence',
options: LlmOptions(model: 'qwen3-0.6b', maxOutputTokens: 100),
);
print(result.text);
4. Stream
await for (final event in RunAnywhere.llm.generateStream('Write a haiku')) {
if (event is GenerationEventToken) setState(() => _text += event.text);
}
generateChat, not generate. Dart has no overloading.Full Flutter guide →1. Install
npm install @runanywhere/web @runanywhere/web-llamacpp @runanywhere/web-onnx @runanywhere/proto-ts
2. Serve the isolation headers
Cross-Origin-Opener-Policy: same-origin
Cross-Origin-Embedder-Policy: require-corp
SharedArrayBuffer and nothing loads.3. Register a backend, then initialize
import { RunAnywhere } from '@runanywhere/web';
import { LlamaCPP } from '@runanywhere/web-llamacpp';
await LlamaCPP.autoRegister();
await RunAnywhere.initialize({ environment: 'development' });
4. Generate
const result = await RunAnywhere.llm.generate('Explain on-device AI in one sentence', {
model: 'qwen3-0.6b',
maxOutputTokens: 100,
});
console.log(result.text);
for await (const event of RunAnywhere.llm.generateStream('Write a haiku')) {
if (event.type === 'textDelta') output.textContent += event.text;
}
1. Install
npm install @runanywhere/electron @runanywhere/electron-llamacpp @runanywhere/electron-onnx
2. Construct the facade and initialize
main.ts
import { createRunAnywhere, NativeBackend } from '@runanywhere/electron'
const RunAnywhere = createRunAnywhere(new NativeBackend())
await RunAnywhere.initialize()
initialize() is single-phase here: one call, no second services phase to await.3. Generate
const result = await RunAnywhere.llm.generate('Explain on-device AI in one sentence', {
model: 'qwen3-0.6b',
maxOutputTokens: 100,
})
console.log(result.text, result.tokensPerSecond)
for await (const event of RunAnywhere.llm.generateStream('Write a haiku')) {
if (event.type === 'textDelta') process.stdout.write(event.text)
}
4. Reach it from the renderer
The preload exposes the same facade aswindow.runanywhere, so page code calls the
identical methods without importing a native addon.renderer.ts
const result = await window.runanywhere.llm.generate('Hello')
output.textContent = result.text
What happens on the first call
Generation auto-loads whatever it needs. Whenoptions.model names a model that is not on
disk, the SDK downloads it first, so the first call is slow and later calls are not. To control
when that cost is paid, download and load explicitly:
for try await event in try await RunAnywhere.models.download(id: "qwen3-0.6b") {
if case .progress(let p) = event { progress = p.fraction ?? 0 }
}
Next
SDK overview
What differs between platforms
Tool calling
Let the model call your functions