Skip to main content
Follow these best practices to build high-performance, reliable apps with the RunAnywhere SDK.

Initialization

Initialize Early

Initialize the SDK at app launch, not when first needed. The correct order is: initialize → register backends → register models.

Pre-load Models

Load models during onboarding or splash screen:

Memory Management

Unload When Not Needed

Free memory by unloading unused models:

Monitor Memory

Handle Memory Warnings

Model Selection

Choose Appropriate Model Sizes

Device-Specific Loading

Streaming for Responsiveness

Always Stream for Long Outputs

Batch UI Updates

Threading

Use Appropriate Actors

Don’t Block the Main Thread

Error Recovery

Implement Retries

Graceful Fallbacks

Storage

Check Before Downloads

Clean Up Regularly

Event Handling

Subscribe to Events

Testing

Use Development Environment

Mock for Unit Tests

Platform Gotchas

Permissions (Info.plist)

Your app’s Info.plist must include usage descriptions for all hardware your app accesses:

macOS App Sandbox

For macOS targets, disable the App Sandbox to allow model file downloads and storage: Set ENABLE_APP_SANDBOX = NO in your Xcode build settings.

Backend Registration Order

Backends must be registered after RunAnywhere.initialize() and before any model registration or loading:

Sequential Model Downloads

Download models sequentially (not in parallel) to avoid race conditions in the SDK’s download service:

VLM Model Loading

VLM model loading requires a ModelDescriptor object, not just a model ID. Fetch it from availableModels():

Try-Then-Download Pattern

Always attempt loadModel() first (succeeds if the model is already cached), and only download on failure:

Audio Format for STT

STT transcription requires audio recorded as 16kHz, mono, 16-bit linear PCM (WAV). The minimum data threshold is ~1600 bytes (~0.1 seconds at 16kHz).

Platform-Conditional Code (iOS vs macOS)

When building for both iOS and macOS, use conditional compilation for platform-specific APIs:
AVAudioSession is only available on iOS — skip audio session setup on macOS.

Quick Reference

Configuration

SDK configuration →

Error Handling

Handle errors gracefully →