Skip to main content
This guide covers all configuration options for the RunAnywhere Swift SDK.

SDK Initialization

try RunAnywhere.initialize(
    apiKey: "<YOUR_API_KEY>",
    baseURL: "https://api.runanywhere.ai",
    environment: .production
)

Parameters

ParameterTypeRequiredDescription
apiKeyString?ProductionAPI key for authentication
baseURLString?ProductionBackend API base URL
environmentSDKEnvironmentNoEnvironment mode (default: .development)

SDKEnvironment

public enum SDKEnvironment: String, Sendable {
    case development
    case staging
    case production
}
EnvironmentLog LevelAuthenticationAnalyticsDescription
.developmentDebugOptionalLocalVerbose logging, mock services
.stagingInfoRequiredYesTesting with real services
.productionWarningRequiredYesMinimal 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

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

OptionDefaultRange/TypeDescription
maxTokens1001-4096+Max tokens to generate
temperature0.80.0-2.0Lower = deterministic
topP1.00.0-1.0Nucleus sampling threshold
stopSequences[][String]Stop on these strings
streamingEnabledfalseBoolEnable token streaming
systemPromptnilString?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
}
OptionDefaultDescription
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
}
OptionDefaultRangeDescription
rate1.00.5-2.0Playback speed
pitch1.00.5-2.0Voice pitch
volume1.00.0-1.0Audio volume
sampleRate22050HzOutput sample rate
audioFormat.wavEnumOutput 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
}
OptionDefaultDescription
sampleRate16000Audio sample rate
frameLength0.032Frame length (32ms)
energyThreshold0.5Sensitivity (0=sensitive, 1=strict)

Memory Considerations

Model Memory Usage

Model TypeTypical MemoryNotes
LLM Q4 (1B params)1-2 GBSuitable for all devices
LLM Q4 (3B params)3-4 GBiPhone Pro / iPad
LLM Q4 (7B params)6-8 GBM1+ Macs only
STT (Whisper Base)~150 MBUniversal
TTS (Piper)50-100 MBUniversal

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

LevelDescription
.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.