sdk/runanywhere-commons/docs/md/react-native.md
iOS + Android via NitroModules (JSI). Entry point is the RunAnywhere object. Async calls return Promise; streaming returns AsyncIterable consumed with a manual iterator.next() loop (Hermes does not support for await over Nitro async iterables).
import { RunAnywhere, SDKEnvironment } from '@runanywhere/core';
// Single options-bag initialize (carries RN-only phase-2 knobs too)
await RunAnywhere.initialize({
apiKey: 'ra_...', // optional in development
environment: SDKEnvironment.SDK_ENVIRONMENT_DEVELOPMENT,
});
await RunAnywhere.completeServicesInitialization();
// State (bridge reads are async → Promise)
RunAnywhere.isInitialized;
RunAnywhere.areServicesReady;
RunAnywhere.version;
await RunAnywhere.deviceId; // Promise<string>
await RunAnywhere.isAuthenticated();
const models = await RunAnywhere.listModels();
const downloaded = await RunAnywhere.downloadedModels();
const one = await RunAnywhere.getModel({ modelId: 'qwen2.5-0.5b' });
const info = await RunAnywhere.registerModel({
name: 'Qwen2.5 0.5B',
url: 'https://huggingface.co/.../model.gguf',
framework: InferenceFramework.INFERENCE_FRAMEWORK_LLAMA_CPP,
});
await RunAnywhere.downloadModel(info, (p) => console.log(p.percentage));
await RunAnywhere.loadModel({ modelId: info.id });
const result = await RunAnywhere.generate('Explain vector databases in one line.');
console.log(result.text);
// Streaming — manual iterator loop (Hermes-safe)
const it = RunAnywhere.generateStream('Write a haiku.')[Symbol.asyncIterator]();
for (let r = await it.next(); !r.done; r = await it.next()) {
process.stdout.write(r.value.token ?? '');
}
await RunAnywhere.cancelGeneration();
const structured = await RunAnywhere.generateStructured('Extract', schema);
await RunAnywhere.registerTool(def, async (args) => ({ result: { stringValue: 'ok' } }));
const toolResult = await RunAnywhere.generateWithTools('Weather in Pune?', undefined, {
signal: abortController.signal, // RN uses AbortSignal for cancellation
});
const transcript = await RunAnywhere.transcribe(pcm16);
const audio = await RunAnywhere.synthesize('Hello there');
await RunAnywhere.speak('Spoken aloud');
await RunAnywhere.stopSpeaking();
const vad = await RunAnywhere.detectVoiceActivity(pcm16);
await RunAnywhere.resetVAD();
const out = await RunAnywhere.processImage(image, { prompt: 'Describe this.' });
// prompt overload — applied onto options.prompt
const stream = await RunAnywhere.processImageStream(image, 'What is this?');
const vit = stream[Symbol.asyncIterator]();
for (let r = await vit.next(); !r.done; r = await vit.next()) console.log(r.value);
await RunAnywhere.cancelVLMGeneration();
await RunAnywhere.ragCreatePipeline({ embeddingModel: emb, llmModel: llm });
await RunAnywhere.ragIngest(document);
const answer = await RunAnywhere.ragQuery('What about pricing?');
const rit = RunAnywhere.ragQueryStream('Summarize')[Symbol.asyncIterator]();
for (let r = await rit.next(); !r.done; r = await rit.next()) console.log(r.value);
await RunAnywhere.lora.applyCatalogAdapter(entry, { scale: 1.0 });
await RunAnywhere.lora.apply(entry); // catalog-entry overload
const state = await RunAnywhere.lora.list();
await RunAnywhere.lora.download(entry, (p) => console.log(p));
await RunAnywhere.initializeVoiceAgentWithLoadedModels();
const vit = RunAnywhere.streamVoiceAgent()[Symbol.asyncIterator]();
for (let r = await vit.next(); !r.done; r = await vit.next()) console.log(r.value);
const turn = await RunAnywhere.processVoiceTurn(pcm16);
await RunAnywhere.cleanupVoiceAgent();
RunAnywhere.events.on((event) => console.log(event));
// Imperative SDK events — subscribe returns a numeric id
const id = await RunAnywhere.subscribeSDKEvents((event) => console.log(event));
await RunAnywhere.unsubscribeSDKEvents(id);
AsyncIterable; use manual iterator.next() loops (never for await — Hermes limitation).AbortSignal (passed via the extra bag on generateWithTools, etc.).