RealtimeSession.fromJson constructor

RealtimeSession.fromJson(
  1. Map<String, dynamic> json
)

Creates a RealtimeSession from JSON.

All fields are optional per the spec — server payloads include the relevant subset for the session shape (realtime vs. transcription) and partial frames omit metadata that hasn't been resolved yet.

Implementation

factory RealtimeSession.fromJson(Map<String, dynamic> json) {
  return RealtimeSession(
    id: json['id'] as String?,
    object: json['object'] as String?,
    type: json['type'] as String?,
    model: json['model'] as String?,
    expiresAt: json['expires_at'] as int?,
    audio: json['audio'] != null
        ? RealtimeAudioConfig.fromJson(json['audio'] as Map<String, dynamic>)
        : null,
    outputModalities: (json['output_modalities'] as List<dynamic>?)
        ?.cast<String>(),
    instructions: json['instructions'] as String?,
    tools: (json['tools'] as List<dynamic>?)
        ?.map((e) => RealtimeTool.fromJson(e as Map<String, dynamic>))
        .toList(),
    toolChoice: json['tool_choice'] != null
        ? RealtimeToolChoice.fromJson(json['tool_choice'] as Object)
        : null,
    maxOutputTokens: json['max_output_tokens'] != null
        ? InfOrInt.fromJson(json['max_output_tokens'] as Object)
        : null,
    parallelToolCalls: json['parallel_tool_calls'] as bool?,
    reasoning: json['reasoning'] != null
        ? RealtimeReasoning.fromJson(
            json['reasoning'] as Map<String, dynamic>,
          )
        : null,
    tracing: json['tracing'] != null
        ? RealtimeTracingConfig.fromJson(json['tracing'] as Object)
        : null,
    truncation: json['truncation'] != null
        ? RealtimeTruncation.fromJson(json['truncation'] as Object)
        : null,
    include: (json['include'] as List<dynamic>?)?.cast<String>(),
  );
}