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: "") }}
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")}
The namespaces are extension properties. Without the second import, 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)
Streaming:
RunAnywhere.llm.generateStream("Write a haiku").collect { event -> if (event is GenerationEvent.Token) print(event.text)}
npm install @runanywhere/core @runanywhere/llamacpp @runanywhere/onnxcd ios && pod install
Requires React Native 0.83.1, iOS 17.5, Android API 24.
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);}
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);}
For a conversation, call generateChat, not generate. Dart has no overloading.Full Flutter guide →
Without these there is no 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);
Streaming:
for await (const event of RunAnywhere.llm.generateStream('Write a haiku')) { if (event.type === 'textDelta') output.textContent += event.text;}
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)
Streaming:
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 as window.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
Generation auto-loads whatever it needs. When options.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 }}