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:
| Type | Wire message |
|---|---|
ReadyEvent | ready |
TranscriptDeltaEvent | transcript |
ModelTextEvent | model-text |
TurnCompleteEvent | turn-complete |
ToolCallEvent | tool-call |
ToolDispatchStartedEvent | tool-dispatch-started |
ToolResultEvent | tool-result |
ToolInvocationEvent | tool-invocation |
ReconnectingEvent | reconnecting |
SessionEndingSoonEvent | session-ending-soon |
UserSpeechTimeoutEvent | user-speech-timeout |
UsageEvent | cosmo.usage |
ErrorEvent | error |
ErrorCode | the code enum on error |
RejectedTool | entries of ready.rejected_tools |
ResolvedAgent | the 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
| Type | Purpose |
|---|---|
SilenceTimeout, Say, EndCall | Server-hook wire config, wrapped as Hook.server(_:) entries in the agent's hooks. |
InterruptionSensitivity | How 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. |
TurnDetectionMode | Which detector ends the user's turn — serverVad, semanticVad, cosmoVad. |
EndOfSpeechSensitivity | How readily serverVad decides the turn ended — low, high. |
SemanticEagerness | How eagerly OpenAI's semanticVad closes the turn — low, medium, high, auto. |
ThinkingLevel | Gemini reasoning depth — minimal, low, medium, high. |
GrokReasoningEffort | Whether Grok Voice reasons before speaking — high, none (spelled .disabled in optional position). |
CredentialInfo | What RealtimeClient.verify() resolves — credential kind, workspace, scopes, canStartSessions, realtimeVoiceAvailable, externalUserId. |
WorkspaceInfo | The workspace a credential is bound to (name, slug). |
CredentialKind | Which credential the server saw — api_key or user_token. |
SessionUsage | What session.usage() resolves — status, usageStatus, durationSeconds, talk time, provider/model, tokens. |
SessionTokenUsage | Token counts by direction and modality on SessionUsage.tokens. |
SessionStatus | Lifecycle state of a voice session — active, completed, or error. |
UsageStatus | Whether 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.