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