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):
| Typealias | Wire message |
|---|---|
RealtimeSession.Ready | ready |
RealtimeSession.TranscriptDelta | transcript |
RealtimeSession.ModelText | model-text |
RealtimeSession.TurnComplete | turn-complete |
RealtimeSession.ToolCall | tool-call |
RealtimeSession.ToolDispatchStarted | tool-dispatch-started |
RealtimeSession.ToolResult | tool-result |
RealtimeSession.ToolInvocation | tool-invocation |
RealtimeSession.Reconnecting | reconnecting |
RealtimeSession.UserSpeechTimeout | user-speech-timeout |
RealtimeSession.CosmoUsage | cosmo.usage |
RealtimeSession.ErrorEvent | error |
RealtimeSession.ErrorCode | the code enum on error |
RealtimeSession.RejectedTool | entries of ready.rejected_tools |
RealtimeSession.ResolvedAgent | the 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
| Typealias | Purpose |
|---|---|
SilenceTimeout, Say, EndCall | Server-hook wire config for SessionConfig.serverHooks. |
SessionConfig.InterruptionSensitivity | Barge-in sensitivity enum. |
SessionConfig.ThinkingLevel | Gemini reasoning-depth enum. |
VoiceSessionSummary | One recorded session from the voice-sessions REST list (renamed from the spec's VoiceSession to avoid colliding with the VoiceSession actor). |
VoiceSessionTranscriptTurn | One transcript turn from the session-transcript endpoint. |
RealtimeProviderCapabilities | Per-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.