Cosmo Realtime SDK
ReferenceSwift

Wire types (Swift)

The types the SDK declares for the realtime wire protocol, and where their field shapes are defined.

CosmoRealtime declares every type on its public surface. The package's other module, CosmoRealtimeAPI, holds code generated from the OpenAPI spec and is an implementation detail of the REST client and the send path — it is not a product, so it cannot be imported, and no public type points into it.

import CosmoRealtime

for try await event in session.events {
    if case .transcript(let delta) = event {
        print(delta.text, delta.isFinal)
    }
}

One import is all a consumer needs, including to read fields off event payloads and to name the config enums.

Never depend on the CosmoRealtimeAPI module name or its Components.Schemas paths. The types below are the supported spellings; they change only when the SDK changes, and a rename is a breaking release.


Event payloads

Payloads carried by RealtimeSessionEvent cases (see RealtimeClient). The names are the cross-SDK ones — the same symbols Python and TypeScript publish:

TypeWire message
ReadyEventready
TranscriptDeltaEventtranscript
ModelTextEventmodel-text
TurnCompleteEventturn-complete
ToolCallEventtool-call
ToolDispatchStartedEventtool-dispatch-started
ToolResultEventtool-result
ToolInvocationEventtool-invocation
ReconnectingEventreconnecting
SessionEndingSoonEventsession-ending-soon
UserSpeechTimeoutEventuser-speech-timeout
UsageEventcosmo.usage
ErrorEventerror
ErrorCodethe code enum on error
RejectedToolentries of ready.rejected_tools
ResolvedAgentthe agent summary on ready

SessionEndedEvent (the terminal stream element) is a local sentinel rather than a wire frame — the server's best-effort session-ended frame only supplies its reason.

Most event payloads are read, not constructed: they reach you by decoding what the server sent, and carry no public initializer, so a test fixture decodes the wire JSON the server would send. SessionEndedEvent and ToolInvocationEvent are constructible.

Field shapes are in the wire protocol reference.

Config and REST types

TypePurpose
SilenceTimeout, Say, EndCallServer-hook wire config, wrapped as Hook.server(_:) entries in the agent's hooks.
InterruptionSensitivityHow readily user speech interrupts the agent — _default, high, low. The wire value is default, which is a Swift keyword, so the case carries a leading underscore.
TurnDetectionModeWhich detector ends the user's turn — serverVad, semanticVad, cosmoVad.
EndOfSpeechSensitivityHow readily serverVad decides the turn ended — low, high.
SemanticEagernessHow eagerly OpenAI's semanticVad closes the turn — low, medium, high, auto.
ThinkingLevelGemini reasoning depth — minimal, low, medium, high.
GrokReasoningEffortWhether Grok Voice reasons before speaking — high, none (spelled .disabled in optional position).
CredentialInfoWhat RealtimeClient.verify() resolves — credential kind, workspace, scopes, canStartSessions, realtimeVoiceAvailable, externalUserId.
WorkspaceInfoThe workspace a credential is bound to (name, slug).
CredentialKindWhich credential the server saw — api_key or user_token.
SessionUsageWhat session.usage() resolves — status, usageStatus, durationSeconds, talk time, provider/model, tokens.
SessionTokenUsageToken counts by direction and modality on SessionUsage.tokens.
SessionStatusLifecycle state of a voice session — active, completed, or error.
UsageStatusWhether a session's usage summary is there — pending, recorded, or unavailable.

Forward compatibility

Decode failure is never terminal: a frame with an unrecognized type — or one whose payload fails to decode — surfaces as RealtimeSessionEvent.unknown(rawType:payload:) and the session keeps running.

On this page