API Reference
API Reference for the SmartSpectra SDK.
SmartSpectraSDK
Entry point for the SmartSpectra SDK.
Most apps use the shared instance:
let sdk = SmartSpectraSDK.shared
sdk.config.apiKey = "your-key"
try await sdk.start()Tests and advanced integrations can create an isolated instance via init(config:). The underlying authentication handler and C++ preprocessing runtime are process-global, so only one SDK instance can drive an active measurement at a time.
Initializers
-
public init (config: SmartSpectraConfig)Create an isolated SDK instance backed by the given configuration.
The authentication handler and preprocessing runtime are process-global, so only one instance can drive an active measurement at a time. Use this initializer for tests or advanced integrations where you intentionally need a separate observable state from
shared. Most apps should just useSmartSpectraSDK/shared.
Methods
-
public func start () async throwsBegin processing frames from the device camera.
-
public func stop () async throwsStop processing. Call
start()again to resume. -
@discardableResult public func requestInsight (_ text: String) throws -> Int32Dispatch an on-demand insight request alongside the vitals samples buffered since the last send.
The provided
textis sent as the current turn's prompt; prior calls' text is not retained or re-sent by the SDK. The dispatched request type mirrors the Presage Analytics Gateway contract:combinedwhen vitals samples are buffered at dispatch time,speechwhen only the prompt is present. Vitals snapshots auto-fire approximately every 15 seconds with no prompt and are published throughSmartSpectraSDK/insightalongside on-demand replies; callers route on the delivered Insight'stypefield. -
@_spi(Testing) public func setVideoInput (path: String)Configures a video file as input source instead of the live camera. Supported formats: .mov, .mp4, .qt
-
@_spi(Testing) public func setVideoTimestampInput (path: String)Configures optional timestamp file (one ms value per line) for frame timing.
-
@_spi(Testing) public func setVideoInterframeDelay (milliseconds: Int)Configures optional video-file playback throttling in milliseconds.
-
@_spi(Testing) public func setVideoInputEnabled (_ enabled: Bool)Enables or disables video file input mode. Toggleable at runtime. When enabled, camera input is disabled.
Properties
-
public static let shared = SmartSpectraSDK()The shared SDK instance.
-
public internal(set) var metrics : Metrics?Real-time metrics emitted while processing is active.
-
public internal(set) var imageOutput : UIImage?Live camera preview image.
-
public internal(set) var processingStatus : ProcessingStatus = .idleCurrent processing pipeline status.
-
public internal(set) var error : SmartSpectraError?Latest error from the SDK.
-
public internal(set) var validationStatus : ValidationStatus?Measurement readiness: face position, lighting, etc. Only meaningful while
processingStatusis.running. -
public internal(set) var insight : Insight?Latest insight from the AI insights service.
-
public nonisolated static var version : StringSDK version string.
-
public let config : SmartSpectraConfigConfiguration for this SDK instance.
Mutate properties on this object rather than replacing it.
SmartSpectraConfig
Configuration for SmartSpectraSDK.
Access configuration through SmartSpectraSDK/config rather than constructing one directly:
let sdk = SmartSpectraSDK.shared
sdk.config.apiKey = "your-key"Standalone construction is available for tests and advanced integrations that pass a custom config into SmartSpectraSDK/init(config:).
Initializers
-
public init ()Creates a configuration with default values. Prefer
SmartSpectraSDK/configover constructing a standalone config unless you are driving an isolatedSmartSpectraSDKinstance.
Properties
-
public var cameraPosition : AVCaptureDevice.Position = .frontCamera position used for capture. Defaults to
.front. -
public var logLevel : SmartSpectraLogLevel = .defaultVerbosity of SDK logging — both the SDK's Swift-side logging and the native engine. Takes effect immediately when set (like
imageOutputEnabled). Defaults toSmartSpectraLogLevel/warning(warnings and errors only). -
public var imageOutputEnabled : Bool = trueControls whether the SDK publishes preview frames to
SmartSpectraSDK/imageOutput.When disabled, camera frames are still processed for vitals analysis, but the SDK skips
CVPixelBuffertoUIImageconversion and preview updates. This is useful for custom integrations that do not display a live camera feed.Example:
let sdk = SmartSpectraSDK.shared sdk.config.imageOutputEnabled = false- Note: Changes take effect immediately and do not require restarting processing.
-
public var enableTelemetry : Bool = trueControls whether the SDK reports anonymous, aggregate usage telemetry.
Telemetry is on by default; set this to
falseto opt out. When enabled, the SDK sends a per-session summary. It does not include raw frames, metric values, file paths, user identifiers, or device identifiers. Reporting is best-effort and never blocks or affects a measurement session.Example:
let sdk = SmartSpectraSDK.shared sdk.config.enableTelemetry = false- Note: Read when a measurement session starts.
-
public var apiKey : String?API key from the Presage developer portal. Setting this automatically configures authentication.
-
public var requestedMetrics : [MetricType]?Which metrics to compute during processing.
This property provides granular control over which metric families the SDK requests. Derived feature flags such as cardio and face processing are inferred from the selected metric types.
Duplicate metrics are removed automatically while preserving the original order.
If you do not set this property, the SDK defaults to breathing-only metrics: chest breathing, abdomen breathing, breathing rate, breathing amplitude, apnea, respiratory line length, baseline, and inhale/exhale ratio.
Example:
let sdk = SmartSpectraSDK.shared sdk.config.requestedMetrics = [ .breathingRate, .pulseRate, .faceLandmarks ]Example using the predefined bundles:
config.requestedMetrics = SmartSpectraConfig.breathingMetrics + SmartSpectraConfig.cardioMetrics -
public nonisolated static let breathingMetrics : [MetricType]Breathing metric bundle. Equivalent to leaving
SmartSpectraConfig/requestedMetricsunset. -
public nonisolated static let cardioMetrics : [MetricType]Cardio metric bundle (pulse rate, arterial pressure trace, HRV). Combine with
breathingMetricsfor the typical "vitals" bundle. -
public nonisolated static let faceMetrics : [MetricType]Face metric bundle (landmarks, blinking, talking, expressions).
-
public nonisolated static let edaMetrics : [MetricType]Electrodermal activity (EDA) trace metric bundle.
ProcessingStatus
Indicates the current state of the preprocessing pipeline.
case idlecase startingcase runningcase stoppingcase error
ValidationStatus
Measurement readiness: a stable code plus a human-readable hint. Orthogonal to ProcessingStatus (engine lifecycle).
Properties
-
public let code : ValidationCodeThe stable, machine-readable readiness code.
-
public let hint : StringA human-readable hint describing what needs to change for a valid measurement.
ValidationCode
Measurement-readiness codes.
case ok = 0case noFaceFound = 1case multipleFacesFound = 2case faceNotCentered = 3case faceSizeOutOfRange = 4case tooDark = 5case tooBright = 6case chestNotVisible = 7case cameraTuning = 10case frameRateTooLow = 11case excessiveMotion = 12case faceTooClose = 13case faceTooFar = 14case faceTooHigh = 15case faceTooLow = 16case faceNotForward = 17
SmartSpectraError
A typed error from the SmartSpectra SDK.
Thrown by SmartSpectraSDK/start() and SmartSpectraSDK/stop(), and published on SmartSpectraSDK/error for async pipeline failures.
Properties
-
public let code : CodeThe error category.
-
public let message : StringA human-readable description of what went wrong.
-
public let retryable : BoolWhether the operation that produced this error can be retried.
-
public var errorDescription : String?A human-readable description of the error; returns
message.
SmartSpectraError.Code
SDK error codes. No .ok case — in Swift, success means no error thrown.
Raw values are stable across SDK versions and match the C++/Android wire values.
case invalidState = 1case authenticationFailed = 2case configurationFailed = 3case creditExhausted = 4case networkError = 5case serverError = 6case inputUnavailable = 7case processingFailed = 8case frameConversionFailed = 9case nonMonotonicTimestamp = 10case timestampGap = 11
SmartSpectraLogLevel
Verbosity of SDK logging, set via SmartSpectraConfig/logLevel.
Levels are cumulative: a level shows its own messages plus everything more severe. The setting covers both the SDK's Swift-side logging and the native engine. debug cannot restore debug-only statements that were compiled out of the release engine binary.
Raw values are stable across SDK versions and match the C++/Android wire values.
case debug = 0case info = 1case warning = 2case error = 3case none = 4