RealtimeSessionCreateResponse.fromJson constructor

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

Creates a RealtimeSessionCreateResponse from JSON.

Throws FormatException when any spec-required field (id, object, type) is missing. model and expires_at are optional per the spec — transcription session responses don't carry a top-level model, and partial frames may omit expires_at.

Implementation

factory RealtimeSessionCreateResponse.fromJson(Map<String, dynamic> json) {
  if (json['id'] == null || json['object'] == null || json['type'] == null) {
    throw const FormatException(
      'RealtimeSessionCreateResponse.fromJson missing one or more required '
      'fields (id, object, type)',
    );
  }
  return RealtimeSessionCreateResponse(
    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>(),
  );
}