sdk/runanywhere-flutter/docs/Documentation.md
Updated: 2026-05-13. This API reference is being kept aligned with the current Flutter implementation plan while code is in progress. It should not be read as a final validation report until Flutter Android and iOS E2E pass.
Public API documentation for the RunAnywhere Flutter SDK.
All entry points hang off the RunAnywhere static namespace. Each capability
is a static property on that namespace, so usage looks like
RunAnywhere.<capability>.<method>(...).
import 'package:runanywhere/runanywhere.dart';
RunAnywherellm — Language Modelstt — Speech-to-Texttts — Text-to-Speechvad — Voice Activity Detectionvlm — Vision Language Modelvoice — Voice Agentmodels — Model Registrydownloads — Downloads + Storagetools — Tool Callingrag — Retrieval-Augmented Generationsolutions — Solution YAML Runnerhardware — Hardware InfoRunAnywhereabstract final class RunAnywhere {
// Lifecycle
static bool get isInitialized;
static bool get isActive;
static bool get areServicesReady;
static String get version;
static SDKEnvironment? get environment;
// Identity (set after authentication)
static String get deviceId;
static String? get userId;
static String? get organizationId;
static bool get isAuthenticated;
// Capability accessors
static RunAnywhereLLM get llm;
static RunAnywhereSTT get stt;
static RunAnywhereTTS get tts;
static RunAnywhereVAD get vad;
static RunAnywhereVLM get vlm;
static RunAnywhereVLM get visionLanguage;
static RunAnywhereVoice get voice;
static RunAnywhereModels get models;
static RunAnywhereModelLifecycle get modelLifecycle;
static RunAnywhereDownloads get downloads;
static RunAnywhereTools get tools;
static RunAnywhereRAG get rag;
static RunAnywhereSolutions get solutions;
static RunAnywhereEmbeddings get embeddings;
static RunAnywhereLoRACapability get lora;
static RunAnywhereHardware get hardware;
static RunAnywherePluginLoader get pluginLoader;
// Convenience model-state accessors
static bool get isLLMModelLoaded;
static bool get isSTTModelLoaded;
static bool get isTTSVoiceLoaded;
static bool get isVADModelLoaded;
static Future<ModelInfo?> get currentLLMModel;
// SDK event stream (proto-typed)
static EventBus get events;
}
initializeTwo-phase init: Phase 1 (sync — load lib, register adapter, configure logging,
rac_sdk_init_phase1_proto) runs immediately; Phase 2 (rac_sdk_init_phase2_proto,
device registration + auth) runs in the background.
Future<void> initialize({
String? apiKey,
String? baseURL,
SDKEnvironment environment = SDKEnvironment.SDK_ENVIRONMENT_DEVELOPMENT,
});
Offline inference works without Phase 2 completing. Call completeServicesInitialization()
to wait for Phase 2 if you need authentication or device registration to be done.
await RunAnywhere.initialize(); // development mode
await RunAnywhere.initialize(
apiKey: '<YOUR_API_KEY>',
baseURL: 'https://api.runanywhere.ai',
environment: SDKEnvironment.SDK_ENVIRONMENT_PRODUCTION,
);
llm — Language Modelclass RunAnywhereLLM {
bool get isLoaded;
String? get currentModelId;
Future<void> load(String modelId);
Future<void> unload();
Future<LLMGenerationResult> generate(String prompt, LLMGenerationOptions options);
Stream<LLMStreamEvent> generateStream(String prompt, LLMGenerationOptions options);
Future<void> cancel();
}
await RunAnywhere.llm.load('smollm2-360m-q8_0');
// Non-streaming
final result = await RunAnywhere.llm.generate(
'Explain quantum computing.',
LLMGenerationOptions(maxTokens: 200, temperature: 0.7),
);
// Streaming
final stream = RunAnywhere.llm.generateStream(
'Tell me a story.',
LLMGenerationOptions(maxTokens: 150),
);
await for (final event in stream) {
if (event.isFinal) break;
if (event.token.isNotEmpty) stdout.write(event.token);
}
stt — Speech-to-Textclass RunAnywhereSTT {
bool get isLoaded;
Future<void> load(String modelId);
Future<void> unload();
Future<STTOutput> transcribe(Uint8List audio, [STTOptions? options]);
Stream<STTPartialResult> transcribeStream(Uint8List audio, [STTOptions? options]);
}
Audio: PCM16, 16 kHz mono. STTOutput is proto-typed (text, confidence, segments,
detectedLanguage).
await RunAnywhere.stt.load('sherpa-onnx-whisper-tiny.en');
final result = await RunAnywhere.stt.transcribe(audioBytes);
print(result.text);
tts — Text-to-Speechclass RunAnywhereTTS {
bool get isLoaded;
Future<void> loadVoice(String voiceId);
Future<void> unloadVoice();
Future<TTSOutput> synthesize(String text, [TTSOptions? options]);
Future<TTSSpeakResult> speak(String text, [TTSOptions? options]);
Future<void> stopSynthesis();
}
await RunAnywhere.tts.loadVoice('vits-piper-en_US-lessac-medium');
final result = await RunAnywhere.tts.synthesize(
'Hello world.',
TTSOptions(rate: 1.0, pitch: 1.0),
);
// result.audio = PCM16 Uint8List; result.sampleRate = 22050 typically
vad — Voice Activity Detectionclass RunAnywhereVAD {
bool get isModelLoaded;
Future<void> loadModel(String modelId);
Future<void> unloadModel();
Future<VADResult> process(Uint8List audioChunk, [VADOptions? options]);
}
vlm — Vision Language Modelclass RunAnywhereVLM {
bool get isLoaded;
Future<void> load(String modelId);
Future<void> unload();
Stream<VLMStreamEvent> processImageStream(VLMImage image, String prompt, [VLMOptions? options]);
}
Multimodal models (e.g. SmolVLM, Qwen2-VL) accept an image + text prompt and stream tokenized responses.
voice — Voice AgentEnd-to-end voice pipeline: VAD → STT → LLM → TTS.
class RunAnywhereVoice {
Future<void> initializeWithLoadedModels();
Stream<VoiceEvent> eventStream(); // proto-typed events
Future<void> start();
Future<void> stop();
}
VoiceEvent has oneof payload: state, vad, userSaid, assistantToken, audio, error.
await RunAnywhere.stt.load('sherpa-onnx-whisper-tiny.en');
await RunAnywhere.llm.load('smollm2-360m-q8_0');
await RunAnywhere.tts.loadVoice('vits-piper-en_US-lessac-medium');
await RunAnywhere.voice.initializeWithLoadedModels();
final sub = RunAnywhere.voice.eventStream().listen((e) {
if (e.hasUserSaid()) print('User: ${e.userSaid.text}');
if (e.hasAssistantToken()) stdout.write(e.assistantToken.text);
});
await RunAnywhere.voice.start();
// ... later
await RunAnywhere.voice.stop();
await sub.cancel();
models — Model Registryclass RunAnywhereModels {
ModelInfo register({
required String id,
required String name,
required Uri url,
required InferenceFramework framework,
ModelCategory modality = ModelCategory.MODEL_CATEGORY_LANGUAGE,
ArchiveArtifact? artifactType,
int? memoryRequirement,
bool supportsThinking = false,
});
ModelInfo registerMultiFile({
required String id,
required String name,
required List<ModelFileDescriptor> files,
required InferenceFramework framework,
ModelCategory modality = ModelCategory.MODEL_CATEGORY_LANGUAGE,
int? memoryRequirement,
});
Future<List<ModelInfo>> available();
}
Single-file:
RunAnywhere.models.register(
id: 'smollm2-360m-q8_0',
name: 'SmolLM2 360M Q8_0',
url: Uri.parse('https://huggingface.co/.../SmolLM2-360M.Q8_0.gguf'),
framework: InferenceFramework.INFERENCE_FRAMEWORK_LLAMA_CPP,
memoryRequirement: 500000000,
);
Multi-file (VLM with mmproj companion, RAG embeddings with vocab.txt, etc.):
RunAnywhere.models.registerMultiFile(
id: 'qwen2-vl-2b-instruct-q4_k_m',
name: 'Qwen2-VL 2B Instruct',
files: [
ModelFileDescriptor(filename: 'Qwen2-VL-2B-Instruct-Q4_K_M.gguf', url: '...', isRequired: true),
ModelFileDescriptor(filename: 'mmproj-Qwen2-VL-2B-Instruct-Q8_0.gguf', url: '...', isRequired: true),
],
framework: InferenceFramework.INFERENCE_FRAMEWORK_LLAMA_CPP,
modality: ModelCategory.MODEL_CATEGORY_MULTIMODAL,
memoryRequirement: 1800000000,
);
downloads — Downloads + Storageclass RunAnywhereDownloads {
Stream<DownloadProgress> start(String modelId);
Future<void> cancel(String modelId);
Future<void> delete(String modelId);
Future<List<ModelStorageMetrics>> list();
Future<StorageInfo> getStorageInfo();
}
final stream = RunAnywhere.downloads.start('smollm2-360m-q8_0');
await for (final p in stream) {
final pct = (p.stageProgress * 100).clamp(0.0, 100.0);
print('${p.stage}: ${pct.toStringAsFixed(1)}%');
if (p.stage == DownloadStage.DOWNLOAD_STAGE_COMPLETED) break;
}
tools — Tool Callingclass RunAnywhereTools {
void register({required String name, required String description, required Map<String, Object?> parametersSchema, required Future<Object?> Function(Map<String, Object?>) handler});
Future<ToolCallResult> generateWithTools(String prompt, {ToolCallFormatNames? format});
}
rag — Retrieval-Augmented Generationclass RunAnywhereRAG {
Future<String> createPipeline({required String embeddingModelId, RAGConfiguration? configuration});
Future<void> ingest(String pipelineId, List<RAGDocument> documents);
Stream<RAGStreamEvent> query(String pipelineId, String prompt, {int topK = 4});
Future<void> destroyPipeline(String pipelineId);
}
solutions — Solution YAML Runnerclass RunAnywhereSolutions {
Future<SolutionResult> run({required String yaml});
}
hardware — Hardware Infoclass RunAnywhereHardware {
Future<HardwareProfile> getProfile();
Future<ChipEnum> getChipEnum();
}
Backends are separate Flutter packages that register engine vtables with the C++ core. Register them before downloading/loading models.
LlamaCpp — package:runanywhere_llamacpp/runanywhere_llamacpp.dartLLM + VLM via GGUF / llama.cpp.
await LlamaCpp.register(); // registers llamacpp + llamacpp_vlm vtables
MLX — package:runanywhere_mlx/runanywhere_mlx.dartApple MLX LLM, VLM, embeddings, STT, and TTS on physical iOS 17.5 or newer
devices. The arm64 simulator slice supports package, compile, link, and startup
validation only. The Flutter package links the canonical Swift
RunAnywhereMLX runtime; all model and inference APIs continue to flow through
the core SDK.
final registered = await MLX.register();
Onnx — package:runanywhere_onnx/runanywhere_onnx.dartSTT (Whisper / Zipformer / Paraformer), TTS (Piper / VITS), VAD (Silero) via Sherpa-ONNX.
await Onnx.register();
QHexRT — package:runanywhere_qhexrt/runanywhere_qhexrt.dartPrivate Qualcomm Hexagon NPU support is exposed through QHexRT on Android arm64 devices. It registers the native QHexRT backend and lets commons resolve QNN-context bundles through the standard SDK model APIs.
await QHexRT.register();
RAGModuleawait RAGModule.register(); // enables RAG capability
All public API types are protobuf-generated from idl/*.proto. They live under
lib/generated/ and are re-exported through runanywhere_protos.dart.
| Type | Proto enum values |
|---|---|
SDKEnvironment | SDK_ENVIRONMENT_DEVELOPMENT, SDK_ENVIRONMENT_STAGING, SDK_ENVIRONMENT_PRODUCTION |
InferenceFramework | INFERENCE_FRAMEWORK_LLAMA_CPP, INFERENCE_FRAMEWORK_MLX, INFERENCE_FRAMEWORK_SHERPA, INFERENCE_FRAMEWORK_ONNX, INFERENCE_FRAMEWORK_SYSTEM_TTS, ... |
ModelCategory | MODEL_CATEGORY_LANGUAGE, MODEL_CATEGORY_SPEECH_RECOGNITION, MODEL_CATEGORY_SPEECH_SYNTHESIS, MODEL_CATEGORY_MULTIMODAL, MODEL_CATEGORY_EMBEDDING, MODEL_CATEGORY_VOICE_ACTIVITY_DETECTION, ... |
DownloadStage | DOWNLOAD_STAGE_UNSPECIFIED, DOWNLOAD_STAGE_DOWNLOADING, DOWNLOAD_STAGE_EXTRACTING, DOWNLOAD_STAGE_COMPLETED |
ArchiveType | ARCHIVE_TYPE_NONE, ARCHIVE_TYPE_TAR_GZ, ARCHIVE_TYPE_TAR_BZ2, ARCHIVE_TYPE_ZIP |
ArchiveStructure | ARCHIVE_STRUCTURE_DIRECTORY_BASED, ARCHIVE_STRUCTURE_FLAT |
Never hand-edit enum values — modify the .proto and regenerate.
All SDK errors surface as SDKException — a proto-backed unified error type with
40+ factory constructors (e.g., SDKException.notInitialized, SDKException.modelNotFound,
SDKException.componentNotReady, SDKException.downloadFailed, ...).
try {
await RunAnywhere.llm.load('nonexistent');
} on SDKException catch (e) {
print('Error [${e.errorCode}]: ${e.message}');
}
SDKException.errorCode is a proto enum (SDKErrorCode) — branch on it instead
of string-matching messages.
Subscribe to SDK-level lifecycle events:
RunAnywhere.events.allEvents.listen((event) {
// event is proto-typed SDKEvent with oneof payload (init/model/download/...)
print(event);
});
The event stream is a pure dart:async broadcast stream. (rxdart is not a dependency.)
enum SDKEnvironment {
SDK_ENVIRONMENT_DEVELOPMENT, // local-only, verbose logging, no auth
SDK_ENVIRONMENT_STAGING, // real services for testing
SDK_ENVIRONMENT_PRODUCTION, // minimal logging, full auth, telemetry
}
LLMGenerationOptions(
maxTokens: 256,
temperature: 0.7,
topP: 0.95,
stopSequences: ['END'],
systemPrompt: 'You are a helpful assistant.',
jsonSchema: '{...}', // optional, for structured output
);
Each capability has a proto-typed options struct: STTOptions, TTSOptions,
VADOptions, VLMOptions. Fields are documented in the generated .pb.dart files.
A single barrel imports everything:
import 'package:runanywhere/runanywhere.dart';
This re-exports the SDK entry point, all capability classes, proto-generated types, events, and configuration.
Backend modules each export their own register():
import 'package:runanywhere_llamacpp/runanywhere_llamacpp.dart';
import 'package:runanywhere_mlx/runanywhere_mlx.dart';
import 'package:runanywhere_onnx/runanywhere_onnx.dart';
RunAnywhere.version (currently 0.20.11).RACommons build (0.1.6).b7199.1.24.3.All four Flutter packages share the same version, bumped together via the
root scripts/release/sync-versions.sh.