This guide covers all configuration options for the RunAnywhere Swift SDK.
SDK Initialization
For development (no API key needed):
try RunAnywhere. initialize ( environment : . development )
For production:
try RunAnywhere. initialize (
apiKey : "<YOUR_API_KEY>" ,
baseURL : "https://api.runanywhere.ai" ,
environment : . production
)
Parameters
Parameter Type Required Description apiKeyString?Production API key for authentication baseURLString?Production Backend API base URL environmentSDKEnvironmentNo Environment mode (default: .development)
SDKEnvironment
public enum SDKEnvironment : String , Sendable {
case development
case staging
case production
}
Environment Log Level Authentication Analytics Description .developmentDebug Optional Local Verbose logging, mock services .stagingInfo Required Yes Testing with real services .productionWarning Required Yes Minimal logging, full auth
Module Registration
Register modules at app startup to enable capabilities:
import RunAnywhere
import LlamaCPPRuntime
import ONNXRuntime
@MainActor
func configureSDK () {
// Register LlamaCPP for LLM capability
LlamaCPP. register ( priority : 100 )
// Register ONNX for STT/TTS/VAD
ONNX. register ( priority : 100 )
}
Priority
Higher priority modules are preferred when multiple can handle a request:
// Custom module with higher priority
MyCustomLLM. register ( priority : 200 ) // Used first
LlamaCPP. register ( priority : 100 ) // Fallback
Model Registration
Register models before downloading or loading. Models require an ID, name, download URL, inference framework, and memory requirement.
Single-File Model
RunAnywhere. registerModel (
id : String ,
name : String ,
url : URL,
framework : . llamaCpp | . onnx | . coreml ,
modality : . speechRecognition | . speechSynthesis | . imageGeneration , // optional
artifactType : . archive (. tarGz | . zip , structure : . nestedDirectory ), // optional, for archives
memoryRequirement : Int // bytes
)
Multi-File Model
For models with multiple files (e.g., VLM with a vision projector):
RunAnywhere. registerMultiFileModel (
id : String ,
name : String ,
files : [ ModelFileDescriptor ( url : URL, filename : String )],
framework : . llamaCpp ,
modality : . multimodal ,
memoryRequirement : Int
)
InferenceFramework
Value Description .llamaCppLLM/VLM via llama.cpp (GGUF) .onnxSTT/TTS/VAD via Sherpa-ONNX .coremlApple CoreML (e.g., Diffusion)
Model Download and Loading
Download with Progress
let progressStream = try await RunAnywhere. downloadModel ( modelId : String )
for await progress in progressStream {
progress. overallProgress // Double (0.0-1.0)
progress. stage // includes .completed
}
Load Models by Modality
try await RunAnywhere. loadModel ( modelId : String ) // LLM
try await RunAnywhere. loadSTTModel ( modelId : String ) // STT
try await RunAnywhere. loadTTSVoice ( modelId : String ) // TTS
try await RunAnywhere. loadVLMModel ( model : ModelDescriptor) // VLM (requires descriptor)
VLM model loading requires a ModelDescriptor object, not just a model ID. Fetch it via
RunAnywhere.availableModels() and find the matching model.
Query Available Models
let models = try await RunAnywhere. availableModels ()
// Returns [ModelDescriptor] — each has .id, .name, .isDownloaded, .localPath
Model State Checks
await RunAnywhere. isModelLoaded // Bool — LLM loaded?
await RunAnywhere. isSTTModelLoaded // Bool — STT loaded?
await RunAnywhere. isTTSVoiceLoaded // Bool — TTS loaded?
await RunAnywhere. isVLMModelLoaded // Bool — VLM loaded?
await RunAnywhere. isDiffusionModelLoaded // Bool — Diffusion loaded?
LLM Generation Options
public struct LLMGenerationOptions : Sendable {
public let maxTokens: Int // Maximum tokens to generate
public let temperature: Float // Randomness (0.0-2.0)
public let topP: Float // Nucleus sampling (0.0-1.0)
public let stopSequences: [ String ] // Stop generation strings
public let streamingEnabled: Bool // Token streaming
public let preferredFramework: InferenceFramework ?
public let structuredOutput: StructuredOutputConfig ?
public let systemPrompt: String ? // System prompt
}
Default Values
Option Default Range/Type Description maxTokens100 1-4096+ Max tokens to generate temperature0.8 0.0-2.0 Lower = deterministic topP1.0 0.0-1.0 Nucleus sampling threshold stopSequences[][String]Stop on these strings streamingEnabledfalse BoolEnable token streaming systemPromptnil String?System instruction
Example Configurations
// Deterministic, factual responses
let factual = LLMGenerationOptions (
maxTokens : 200 ,
temperature : 0.1 ,
topP : 0.9
)
// Creative writing
let creative = LLMGenerationOptions (
maxTokens : 500 ,
temperature : 1.2 ,
topP : 0.95
)
// JSON output
let json = LLMGenerationOptions (
maxTokens : 300 ,
temperature : 0.2 ,
stopSequences : [ "}" ],
systemPrompt : "Respond only with valid JSON."
)
STT Options
public struct STTOptions : Sendable {
public let language: String // ISO 639-1 code
public let sampleRate: Int // Audio sample rate
public let enableWordTimestamps: Bool // Per-word timing
public let enableVAD: Bool // Voice activity detection
}
Option Default Description language"en"Language code (or empty for auto) sampleRate16000Audio sample rate in Hz enableWordTimestampsfalseInclude word timing info enableVADtrueFilter silent segments
TTS Options
public struct TTSOptions : Sendable {
public let rate: Float // Speed (0.5-2.0)
public let pitch: Float // Pitch (0.5-2.0)
public let volume: Float // Volume (0.0-1.0)
public let language: String // Language code
public let sampleRate: Int // Output sample rate
public let audioFormat: AudioFormat
}
Option Default Range Description rate1.00.5-2.0 Playback speed pitch1.00.5-2.0 Voice pitch volume1.00.0-1.0 Audio volume sampleRate22050Hz Output sample rate audioFormat.wavEnum Output format
VAD Configuration
public struct VADConfiguration : Sendable {
public let sampleRate: Int // Audio sample rate
public let frameLength: Double // Frame duration (seconds)
public let energyThreshold: Double // Detection sensitivity
}
Option Default Description sampleRate16000Audio sample rate frameLength0.032Frame length (32ms) energyThreshold0.5Sensitivity (0=sensitive, 1=strict)
Memory Considerations
Model Memory Usage
Model Type Typical Memory Notes LLM Q4 (1B params) 1-2 GB Suitable for all devices LLM Q4 (3B params) 3-4 GB iPhone Pro / iPad LLM Q4 (7B params) 6-8 GB M1+ Macs only STT (Whisper Base) ~150 MB Universal TTS (Piper) 50-100 MB Universal
Memory Management
// Unload models when not needed
try await RunAnywhere. unloadModel ()
try await RunAnywhere. unloadSTTModel ()
try await RunAnywhere. unloadTTSVoice ()
// Check storage
let storage = await RunAnywhere. getStorageInfo ()
print ( "Available: \( storage. availableBytes / 1_000_000_000 ) GB" )
// Clean temporary files
try await RunAnywhere. cleanTempFiles ()
Logging Configuration
// Set log level
RunAnywhere. setLogLevel (. debug ) // .debug | .info | .warning | .error | .fault
// Enable local logging (Pulse integration)
RunAnywhere. configureLocalLogging ( enabled : true )
// Enable verbose debug mode
RunAnywhere. setDebugMode ( true )
// Flush logs
await RunAnywhere. flushAll ()
Log Levels
Level Description .debugDetailed information for debugging .infoGeneral operational information .warningPotential issues that don’t prevent operation .errorErrors that affect specific operations .faultCritical errors indicating serious problems
SDK State
// Check initialization
let isInitialized = RunAnywhere. isSDKInitialized
let servicesReady = RunAnywhere. areServicesReady
let isActive = RunAnywhere. isActive
// Version info
let version = RunAnywhere. version
// Authentication
let isAuthenticated = RunAnywhere. isAuthenticated
let userId = RunAnywhere. getUserId ()
let orgId = RunAnywhere. getOrganizationId ()
// Device
let deviceId = RunAnywhere. deviceId
let isRegistered = RunAnywhere. isDeviceRegistered ()
Environment-Specific Settings
func configureForEnvironment () {
# if DEBUG
try ? RunAnywhere. initialize (
environment : . development
)
RunAnywhere. setLogLevel (. debug )
RunAnywhere. setDebugMode ( true )
# else
try ? RunAnywhere. initialize (
apiKey : ProcessInfo. processInfo . environment [ "RUNANYWHERE_API_KEY" ],
baseURL : "https://api.runanywhere.ai" ,
environment : . production
)
RunAnywhere. setLogLevel (. warning )
# endif
}
Reset (Testing)
// Reset SDK state for testing
RunAnywhere. reset ()
Only use reset() in development/testing. It clears all SDK state including authentication.
Error Handling Handle SDK errors →
Best Practices Performance tips →