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
| Parameter | Type | Required | Description |
|---|
apiKey | String? | Production | API key for authentication |
baseURL | String? | Production | Backend API base URL |
environment | SDKEnvironment | No | Environment mode (default: .development) |
SDKEnvironment
public enum SDKEnvironment: String, Sendable {
case development
case staging
case production
}
| Environment | Log Level | Authentication | Analytics | Description |
|---|
.development | Debug | Optional | Local | Verbose logging, mock services |
.staging | Info | Required | Yes | Testing with real services |
.production | Warning | 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
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 |
|---|
maxTokens | 100 | 1-4096+ | Max tokens to generate |
temperature | 0.8 | 0.0-2.0 | Lower = deterministic |
topP | 1.0 | 0.0-1.0 | Nucleus sampling threshold |
stopSequences | [] | [String] | Stop on these strings |
streamingEnabled | false | Bool | Enable token streaming |
systemPrompt | nil | 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) |
sampleRate | 16000 | Audio sample rate in Hz |
enableWordTimestamps | false | Include word timing info |
enableVAD | true | Filter 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 |
|---|
rate | 1.0 | 0.5-2.0 | Playback speed |
pitch | 1.0 | 0.5-2.0 | Voice pitch |
volume | 1.0 | 0.0-1.0 | Audio volume |
sampleRate | 22050 | Hz | Output sample rate |
audioFormat | .wav | Enum | 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 |
|---|
sampleRate | 16000 | Audio sample rate |
frameLength | 0.032 | Frame length (32ms) |
energyThreshold | 0.5 | Sensitivity (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 |
|---|
.debug | Detailed information for debugging |
.info | General operational information |
.warning | Potential issues that don’t prevent operation |
.error | Errors that affect specific operations |
.fault | Critical 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.