Skip to main content

gproxy_protocol/wire/openai/realtime/
session.rs

1//! Native Realtime wire DTOs. Source definitions are cited on each object.
2//! Verified with Realtime.md and openai-python snapshot
3//! e12b81d3bbf644ec7045e152d69bc4b68d69cd48 (2026-09-13).
4//! https://github.com/openai/openai-python/tree/e12b81d3bbf644ec7045e152d69bc4b68d69cd48/src/openai/types/realtime
5use super::wire::present_nullable;
6use super::{
7    RealtimeAudioConfig, RealtimeReasoning, RealtimeToolChoiceConfig, RealtimeToolsConfig,
8    RealtimeTracingConfig, RealtimeTranscriptionSessionCreateRequest, RealtimeTruncation,
9    ResponsePrompt,
10};
11use crate::Rest;
12use serde::{Deserialize, Serialize};
13
14/// Source: `openai/types/realtime/realtime_session_create_request.py`, `RealtimeSessionCreateRequest`.
15#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, gproxy_protocol_macros::WireBuilder)]
16#[cfg_attr(not(feature = "exhaustive"), non_exhaustive)]
17#[derive(gproxy_protocol_macros::DeclaredFields)]
18pub struct RealtimeSessionCreateRequest {
19    #[serde(rename = "type")]
20    pub type_: RealtimeSessionCreateRequestType,
21    #[serde(
22        default,
23        deserialize_with = "present_nullable",
24        skip_serializing_if = "Option::is_none"
25    )]
26    pub audio: Option<Option<RealtimeAudioConfig>>,
27    #[serde(
28        default,
29        deserialize_with = "present_nullable",
30        skip_serializing_if = "Option::is_none"
31    )]
32    pub include: Option<Option<Vec<RealtimeSessionCreateRequestIncludeItem>>>,
33    #[serde(
34        default,
35        deserialize_with = "present_nullable",
36        skip_serializing_if = "Option::is_none"
37    )]
38    pub instructions: Option<Option<String>>,
39    #[serde(
40        default,
41        deserialize_with = "present_nullable",
42        skip_serializing_if = "Option::is_none"
43    )]
44    pub max_output_tokens: Option<Option<RealtimeSessionCreateRequestMaxOutputTokens>>,
45    #[serde(
46        default,
47        deserialize_with = "present_nullable",
48        skip_serializing_if = "Option::is_none"
49    )]
50    pub model: Option<Option<String>>,
51    #[serde(
52        default,
53        deserialize_with = "present_nullable",
54        skip_serializing_if = "Option::is_none"
55    )]
56    pub output_modalities: Option<Option<Vec<RealtimeSessionCreateRequestOutputModalitiesItem>>>,
57    #[serde(
58        default,
59        deserialize_with = "present_nullable",
60        skip_serializing_if = "Option::is_none"
61    )]
62    pub parallel_tool_calls: Option<Option<bool>>,
63    #[serde(
64        default,
65        deserialize_with = "present_nullable",
66        skip_serializing_if = "Option::is_none"
67    )]
68    pub prompt: Option<Option<ResponsePrompt>>,
69    #[serde(
70        default,
71        deserialize_with = "present_nullable",
72        skip_serializing_if = "Option::is_none"
73    )]
74    pub reasoning: Option<Option<RealtimeReasoning>>,
75    #[serde(
76        default,
77        deserialize_with = "present_nullable",
78        skip_serializing_if = "Option::is_none"
79    )]
80    pub tool_choice: Option<Option<RealtimeToolChoiceConfig>>,
81    #[serde(
82        default,
83        deserialize_with = "present_nullable",
84        skip_serializing_if = "Option::is_none"
85    )]
86    pub tools: Option<Option<RealtimeToolsConfig>>,
87    #[serde(
88        default,
89        deserialize_with = "present_nullable",
90        skip_serializing_if = "Option::is_none"
91    )]
92    pub tracing: Option<Option<RealtimeTracingConfig>>,
93    #[serde(
94        default,
95        deserialize_with = "present_nullable",
96        skip_serializing_if = "Option::is_none"
97    )]
98    pub truncation: Option<Option<RealtimeTruncation>>,
99    #[serde(default, flatten, skip_serializing_if = "serde_json::Map::is_empty")]
100    pub rest: Rest,
101}
102
103/// Source: `openai/types/realtime/session_created_event.py`, `SessionCreatedEvent`.
104#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, gproxy_protocol_macros::WireBuilder)]
105#[cfg_attr(not(feature = "exhaustive"), non_exhaustive)]
106#[derive(gproxy_protocol_macros::DeclaredFields)]
107pub struct SessionCreatedEvent {
108    pub event_id: String,
109    pub session: SessionCreatedEventSession,
110    #[serde(rename = "type")]
111    pub type_: SessionCreatedEventType,
112    #[serde(default, flatten, skip_serializing_if = "serde_json::Map::is_empty")]
113    pub rest: Rest,
114}
115
116/// Source: `openai/types/realtime/session_updated_event.py`, `SessionUpdatedEvent`.
117#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, gproxy_protocol_macros::WireBuilder)]
118#[cfg_attr(not(feature = "exhaustive"), non_exhaustive)]
119#[derive(gproxy_protocol_macros::DeclaredFields)]
120pub struct SessionUpdatedEvent {
121    pub event_id: String,
122    pub session: SessionUpdatedEventSession,
123    #[serde(rename = "type")]
124    pub type_: SessionUpdatedEventType,
125    #[serde(default, flatten, skip_serializing_if = "serde_json::Map::is_empty")]
126    pub rest: Rest,
127}
128
129/// Source: `openai/types/realtime/session_created_event.py`, `Session`.
130#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
131#[cfg_attr(not(feature = "exhaustive"), non_exhaustive)]
132#[serde(untagged)]
133#[allow(clippy::large_enum_variant)]
134#[derive(gproxy_protocol_macros::DeclaredFields)]
135pub enum SessionCreatedEventSession {
136    RealtimeSessionCreateRequest(RealtimeSessionCreateRequest),
137    RealtimeTranscriptionSessionCreateRequest(RealtimeTranscriptionSessionCreateRequest),
138}
139
140/// Source: `openai/types/realtime/session_updated_event.py`, `Session`.
141#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
142#[cfg_attr(not(feature = "exhaustive"), non_exhaustive)]
143#[serde(untagged)]
144#[allow(clippy::large_enum_variant)]
145#[derive(gproxy_protocol_macros::DeclaredFields)]
146pub enum SessionUpdatedEventSession {
147    RealtimeSessionCreateRequest(RealtimeSessionCreateRequest),
148    RealtimeTranscriptionSessionCreateRequest(RealtimeTranscriptionSessionCreateRequest),
149}
150
151#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
152#[cfg_attr(not(feature = "exhaustive"), non_exhaustive)]
153#[derive(gproxy_protocol_macros::DeclaredFields)]
154pub enum RealtimeSessionCreateRequestType {
155    #[serde(rename = "realtime")]
156    Realtime,
157}
158
159#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
160#[cfg_attr(not(feature = "exhaustive"), non_exhaustive)]
161#[derive(gproxy_protocol_macros::DeclaredFields)]
162pub enum RealtimeSessionCreateRequestIncludeItem {
163    #[serde(rename = "item.input_audio_transcription.logprobs")]
164    ItemInputAudioTranscriptionLogprobs,
165}
166
167#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
168#[cfg_attr(not(feature = "exhaustive"), non_exhaustive)]
169#[derive(gproxy_protocol_macros::DeclaredFields)]
170pub enum RealtimeSessionCreateRequestMaxOutputTokensVariant2 {
171    #[serde(rename = "inf")]
172    Inf,
173}
174
175#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
176#[cfg_attr(not(feature = "exhaustive"), non_exhaustive)]
177#[serde(untagged)]
178#[derive(gproxy_protocol_macros::DeclaredFields)]
179pub enum RealtimeSessionCreateRequestMaxOutputTokens {
180    Number(i64),
181    Literal(RealtimeSessionCreateRequestMaxOutputTokensVariant2),
182}
183
184#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
185#[cfg_attr(not(feature = "exhaustive"), non_exhaustive)]
186#[derive(gproxy_protocol_macros::DeclaredFields)]
187pub enum RealtimeSessionCreateRequestOutputModalitiesItem {
188    #[serde(rename = "text")]
189    Text,
190    #[serde(rename = "audio")]
191    Audio,
192}
193
194#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
195#[cfg_attr(not(feature = "exhaustive"), non_exhaustive)]
196#[derive(gproxy_protocol_macros::DeclaredFields)]
197pub enum SessionCreatedEventType {
198    #[serde(rename = "session.created")]
199    SessionCreated,
200}
201
202#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
203#[cfg_attr(not(feature = "exhaustive"), non_exhaustive)]
204#[derive(gproxy_protocol_macros::DeclaredFields)]
205pub enum SessionUpdatedEventType {
206    #[serde(rename = "session.updated")]
207    SessionUpdated,
208}