Cosmo Realtime SDK
ReferenceSwift

Generated types (Swift)

How the OpenAPI-generated wire types surface as RealtimeSession.* typealiases.

Generated types

The Swift package generates its wire types from sdks/cosmo-realtime/external-openapi.json with the Swift OpenAPI Generator plugin at build time. The generated code lives in an internal module (CosmoRealtimeAPI) — its Components.Schemas namespace and generated Client are implementation details. Consumers import CosmoRealtime only; the public spellings are typealiases.

import CosmoRealtime

for try await event in session.events {
    if case .transcript(let delta) = event {
        // delta is RealtimeSession.TranscriptDelta — a generated struct,
        // reached without spelling the generated namespace.
        print(delta.text, delta.isFinal)
    }
}

The generated structs are the source of truth for field shapes — they regenerate from external-openapi.json on every build. Never depend on the CosmoRealtimeAPI module name or its Components.Schemas paths.


Event payload typealiases (RealtimeSession.*)

Payloads carried by RealtimeSession.Event cases (see RealtimeSession):

TypealiasWire message
RealtimeSession.Readyready
RealtimeSession.TranscriptDeltatranscript
RealtimeSession.ModelTextmodel-text
RealtimeSession.TurnCompleteturn-complete
RealtimeSession.ToolCalltool-call
RealtimeSession.ToolDispatchStartedtool-dispatch-started
RealtimeSession.ToolResulttool-result
RealtimeSession.ToolInvocationtool-invocation
RealtimeSession.Reconnectingreconnecting
RealtimeSession.UserSpeechTimeoutuser-speech-timeout
RealtimeSession.CosmoUsagecosmo.usage
RealtimeSession.ErrorEventerror
RealtimeSession.ErrorCodethe code enum on error
RealtimeSession.RejectedToolentries of ready.rejected_tools
RealtimeSession.ResolvedAgentthe agent summary on ready

RealtimeSession.SessionEnded (the terminal stream element) is a hand-written local sentinel, not a generated type — the server's best-effort session-ended frame only supplies its reason.

Field shapes for all of these are in the wire protocol reference.

Config and REST typealiases

TypealiasPurpose
SilenceTimeout, Say, EndCallServer-hook wire config for SessionConfig.serverHooks.
SessionConfig.InterruptionSensitivityBarge-in sensitivity enum.
SessionConfig.ThinkingLevelGemini reasoning-depth enum.
VoiceSessionSummaryOne recorded session from the voice-sessions REST list (renamed from the spec's VoiceSession to avoid colliding with the VoiceSession actor).
VoiceSessionTranscriptTurnOne transcript turn from the session-transcript endpoint.
RealtimeProviderCapabilitiesPer-provider model capabilities from the capabilities endpoint.

Forward compatibility

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


Regenerating

external-openapi.json is exported from the backend by backend/scripts/export_realtime_openapi.py; the Swift target reads it via the symlink at Sources/CosmoRealtimeAPI/openapi.json and regenerates on build. Do not hand-edit either file.

On this page