Skip to main content

Initialization

One call sets everything up. Platform adapters, native load, authentication, device registration, and catalog sync all happen inside it. The network parts run in the background and retry, so the call returns as soon as local inference is usable.
initialize is synchronous and throws. There is no second phase to await.

SDKEnvironment

There is no staging case. Point baseUrl at a staging deployment and keep environment: .production.

Module registration

Register backends before initialize(). The C++ plugin registry resolves an engine on the first model load, and with nothing registered that load fails.
All three are @MainActor and idempotent. MLX.register() returns Bool and reports false in the Simulator, where the MLX runtime is unavailable. The other two return Void and log rather than throw.

Engine priority

register(priority:) accepts a priority argument for source compatibility but ignores it. Selection happens in the C++ registry using each plugin’s base priority, per primitive: To pin an engine for one model, pass LoadOptions(framework:) to models.load.

The models namespace

Generation verbs auto-load, so load is for callers who want to choose when the cost is paid.

Registering models

ModelRegistration is one builder with three factories.
id is optional on .url and .archive, where commons derives one from the URL. .multiFile requires it. ArchiveType: .zip, .tarGz, .tarBz2, .tarXz. ArchiveStructure: .singleFileNested, .directoryBased, .nestedDirectory, .unknown.

InferenceFramework

InferenceFramework is a typealias for RAInferenceFramework, and ModelCategory for RAModelCategory.

Downloading

One verb reports progress and completion on the same stream. percent runs 0 to 100.
The factory throws when the id is unknown. Transfer failures throw into the loop.

Loading and unloading

Both throw on failure. Neither returns a result to inspect.
LoadOptions carries placement knobs:
Only framework reaches commons today. The other three are logged and dropped because the native load ABI does not carry them.

Querying the registry

ModelFilter takes category, framework, downloadedOnly, and search. get returns nil for an unknown id rather than throwing.

What is loaded

ModelsState.loaded is keyed by ModelCategory, so one read tells you the whole picture. models.refresh() rescans the managed model directories and reconciles downloaded state, which is worth calling once at launch.

Options types

Every options struct has a memberwise initializer and per-field defaults read from the IDL, so the values match every other SDK.

LlmOptions

See generate() for the full list, including reasoning and structuredOutput.

SttOptions

The language is a BCP-47 string, not an enum. See STT Options.

TtsOptions

VadOptions

Others

ImageOptions, EmbedOptions, DiarizationOptions, SegmentationOptions, RagConfig, TurnHandlingOptions, and LoadOptions follow the same pattern. Each is documented on the page for its namespace.

LoRA adapters

Adapters register through the model registry, then apply to whatever base model is loaded.
apply throws when the adapter is unknown, has no local file, or is incompatible with the loaded base model. scale of nil uses the catalog default.

Storage

For a quick read on space without the request struct, models.state() reports storageUsedBytes and storageFreeBytes.

Logging

RALoggingConfiguration.defaults() sets enableLocalLogging = true and leaves the rest at their zero values, which makes minLogLevel default to .trace. RALogLevel, lowest to highest: .trace, .debug, .info, .warning, .error, .fatal. There is no .fault case.

SDK state

isReady means local inference is usable. The older isInitialized, isActive, and areServicesReady are deprecated: network readiness is an SDK-internal concern now, and calls wait for it themselves.

Events

RunAnywhere.events is an AsyncStream<SdkEvent> of lifecycle breadcrumbs.
When you need a field SdkEvent folds away, such as download byte counts or per-component progress, RunAnywhere.eventBus exposes the raw proto envelopes through Combine.
EventBus also exposes llmEvents, sttEvents, ttsEvents, modelEvents, ragEvents, sdkEvents, and events(for:).

Environment-specific setup

Reset

reset() unloads models, closes sessions, and clears state including authentication. It is async and does not throw.
Use reset() in development and tests only.

Error Handling

Handle SDK errors

Best Practices

Performance patterns