LedgeKitDocs
API referenceSwift SDK
Developer documentation

Client and agents

Configure one client and stable agent identities.

LedgeClient

public init(
    serviceName: String,
    writeKey: String,
    isEnabled: Bool = true,
    localDirectory: URL? = nil,
    onDiagnostic: (@Sendable (LedgeDiagnostic) -> Void)? = nil
) throws

A shared actor with automatic outbox recovery and delivery. The advanced initializer accepts transport: any LedgeTransport in place of writeKey. isEnabled is immutable. A disabled client executes native requests without recording or touching storage. Recovery begins on the first startTrace, recorded model call, or flush.

session(model:tools:instructions:agent:) creates a recorded LedgeSession without suspension. Recording is installed before the native session is created. withTrace scopes completion; startTrace returns a manually owned LedgeTrace. flush() async -> LedgeDeliverySummary attempts delivery and leaves active traces open. See trace lifecycle and delivery.

Pass your app's write key directly. An empty or whitespace-only key throws LedgeConfigurationError.missingAPIKey during client setup.

LedgeAgent

public init(name: String, version: Int) throws

Immutable name and version, with Codable, Equatable, and Sendable conformance. Names require non-whitespace text and at most 256 characters; versions are positive 32-bit integers. Invalid setup throws LedgeConfigurationError.invalidName or .invalidVersion, including when decoding an agent.

LedgeClient.sdkVersion identifies the installed SDK version (1.0.0 for this release).

On this page