1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
//! Server event structures for Realtime API communication.
//!
//! This module contains all server-to-client event types emitted during
//! a Realtime API WebSocket session.
/// Define a private namespace for server event items.
mod private
{
use crate::components::common::{ Error, LogProbProperties };
use crate::components::realtime_shared::session::RealtimeSession;
use crate::components::realtime_shared::transcription::RealtimeTranscriptionSessionCreateResponse;
use crate::components::realtime_shared::conversation::
{
RealtimeConversationItem,
RealtimeConversationInfo,
};
use crate::components::realtime_shared::response::RealtimeResponse;
use serde::{ Serialize, Deserialize };
use serde_json::Value;
/// Server event indicating a conversation was created.
///
/// # Used By
/// - `RealtimeServerEvent`
#[ derive( Debug, Deserialize, Clone, PartialEq ) ]
pub struct RealtimeServerEventConversationCreated
{
/// The unique ID of the server event.
pub event_id : String,
/// The conversation resource info.
pub conversation : RealtimeConversationInfo,
}
/// Server event indicating a conversation item was created.
///
/// # Used By
/// - `RealtimeServerEvent`
#[ derive( Debug, Deserialize, Clone, PartialEq ) ]
pub struct RealtimeServerEventConversationItemCreated
{
/// The unique ID of the server event.
pub event_id : String,
/// The ID of the preceding item in the Conversation context.
pub previous_item_id : Option< String >,
/// The created conversation item.
pub item : RealtimeConversationItem,
}
/// Server event indicating a conversation item was deleted.
///
/// # Used By
/// - `RealtimeServerEvent`
#[ derive( Debug, Deserialize, Clone, PartialEq ) ]
pub struct RealtimeServerEventConversationItemDeleted
{
/// The unique ID of the server event.
pub event_id : String,
/// The ID of the item that was deleted.
pub item_id : String,
}
/// Server event indicating input audio transcription completed successfully.
///
/// # Used By
/// - `RealtimeServerEvent`
#[ derive( Debug, Deserialize, Clone, PartialEq ) ]
pub struct RealtimeServerEventConversationItemInputAudioTranscriptionCompleted
{
/// The unique ID of the server event.
pub event_id : String,
/// The ID of the user message item containing the audio.
pub item_id : String,
/// The index of the content part containing the audio.
pub content_index : i32,
/// The transcribed text.
pub transcript : String,
/// The log probabilities of the transcription, if requested.
pub logprobs : Option< Vec< LogProbProperties > >,
}
/// Server event indicating a delta in the input audio transcription.
///
/// # Used By
/// - `RealtimeServerEvent`
#[ derive( Debug, Deserialize, Clone, PartialEq ) ]
pub struct RealtimeServerEventConversationItemInputAudioTranscriptionDelta
{
/// The unique ID of the server event.
pub event_id : String,
/// The ID of the item being transcribed.
pub item_id : String,
/// The index of the content part being transcribed.
pub content_index : Option< i32 >, // Made optional as per example
/// The text delta.
pub delta : String,
/// The log probabilities of the transcription delta, if requested.
pub logprobs : Option< Vec< LogProbProperties > >,
}
/// Server event indicating input audio transcription failed.
///
/// # Used By
/// - `RealtimeServerEvent`
#[ derive( Debug, Deserialize, Clone, PartialEq ) ]
pub struct RealtimeServerEventConversationItemInputAudioTranscriptionFailed
{
/// The unique ID of the server event.
pub event_id : String,
/// The ID of the user message item.
pub item_id : String,
/// The index of the content part containing the audio.
pub content_index : i32,
/// Details of the transcription error.
pub error : Error,
}
/// Server event containing the retrieved conversation item.
///
/// # Used By
/// - `RealtimeServerEvent`
#[ derive( Debug, Deserialize, Clone, PartialEq ) ]
pub struct RealtimeServerEventConversationItemRetrieved
{
/// The unique ID of the server event.
pub event_id : String,
/// The retrieved conversation item.
pub item : RealtimeConversationItem,
}
/// Server event confirming an assistant audio message was truncated.
///
/// # Used By
/// - `RealtimeServerEvent`
#[ derive( Debug, Deserialize, Clone, PartialEq ) ]
pub struct RealtimeServerEventConversationItemTruncated
{
/// The unique ID of the server event.
pub event_id : String,
/// The ID of the assistant message item that was truncated.
pub item_id : String,
/// The index of the content part that was truncated.
pub content_index : i32,
/// The duration up to which the audio was truncated (ms).
pub audio_end_ms : i32,
}
/// Server event indicating an error occurred.
///
/// # Used By
/// - `RealtimeServerEvent`
#[ derive( Debug, Deserialize, Clone, PartialEq ) ]
pub struct RealtimeServerEventError
{
/// The unique ID of the server event.
pub event_id : String,
/// Details of the error.
pub error : RealtimeErrorDetails,
}
/// Details of an error reported by the Realtime server.
///
/// # Used By
/// - `RealtimeServerEventError`
#[ derive( Debug, Deserialize, Clone, PartialEq ) ]
pub struct RealtimeErrorDetails
{
/// The type of error (e.g., "`invalid_request_error`").
pub r#type : String,
/// Error code, if any.
pub code : Option< String >,
/// A human-readable error message.
pub message : String,
/// Parameter related to the error, if any.
pub param : Option< String >,
/// The `event_id` of the client event that caused the error, if applicable.
pub event_id : Option< String >,
}
/// Server event confirming the input audio buffer was cleared.
///
/// # Used By
/// - `RealtimeServerEvent`
#[ derive( Debug, Deserialize, Clone, PartialEq ) ]
pub struct RealtimeServerEventInputAudioBufferCleared
{
/// The unique ID of the server event.
pub event_id : String,
}
/// Server event confirming the input audio buffer was committed.
///
/// # Used By
/// - `RealtimeServerEvent`
#[ derive( Debug, Deserialize, Clone, PartialEq ) ]
pub struct RealtimeServerEventInputAudioBufferCommitted
{
/// The unique ID of the server event.
pub event_id : String,
/// The ID of the preceding item after which the new item will be inserted.
pub previous_item_id : Option< String >,
/// The ID of the user message item that will be created.
pub item_id : String,
}
/// Server event indicating speech start detected by VAD.
///
/// # Used By
/// - `RealtimeServerEvent`
#[ derive( Debug, Deserialize, Clone, PartialEq ) ]
pub struct RealtimeServerEventInputAudioBufferSpeechStarted
{
/// The unique ID of the server event.
pub event_id : String,
/// Milliseconds from session start when speech was first detected.
pub audio_start_ms : i32,
/// The ID of the user message item that will be created when speech stops.
pub item_id : String,
}
/// Server event indicating speech stop detected by VAD.
///
/// # Used By
/// - `RealtimeServerEvent`
#[ derive( Debug, Deserialize, Clone, PartialEq ) ]
pub struct RealtimeServerEventInputAudioBufferSpeechStopped
{
/// The unique ID of the server event.
pub event_id : String,
/// Milliseconds since session start when speech stopped.
pub audio_end_ms : i32,
/// The ID of the user message item that will be created.
pub item_id : String,
}
/// Server event providing updated rate limit information.
///
/// # Used By
/// - `RealtimeServerEvent`
#[ derive( Debug, Deserialize, Clone, PartialEq ) ]
pub struct RealtimeServerEventRateLimitsUpdated
{
/// The unique ID of the server event.
pub event_id : String,
/// List of rate limit information.
pub rate_limits : Vec< RateLimitInfo >,
}
/// Contains information about a specific rate limit.
///
/// # Used By
/// - `RealtimeServerEventRateLimitsUpdated`
#[ derive( Debug, Deserialize, Clone, PartialEq ) ]
pub struct RateLimitInfo
{
/// The name of the rate limit (`requests` or `tokens`).
pub name : String,
/// The maximum allowed value for the rate limit.
pub limit : i32,
/// The remaining value before the limit is reached.
pub remaining : i32,
/// Seconds until the rate limit resets.
pub reset_seconds : f64,
}
/// Server event containing a delta of model-generated audio.
///
/// # Used By
/// - `RealtimeServerEvent`
#[ derive( Debug, Deserialize, Clone, PartialEq ) ]
pub struct RealtimeServerEventResponseAudioDelta
{
/// The unique ID of the server event.
pub event_id : String,
/// The ID of the response.
pub response_id : String,
/// The ID of the item containing the audio.
pub item_id : String,
/// The index of the output item in the response.
pub output_index : i32,
/// The index of the content part in the item's content array.
pub content_index : i32,
/// Base64-encoded audio data delta.
pub delta : String,
}
/// Server event indicating the model-generated audio stream is done.
///
/// # Used By
/// - `RealtimeServerEvent`
#[ derive( Debug, Deserialize, Clone, PartialEq ) ]
pub struct RealtimeServerEventResponseAudioDone
{
/// The unique ID of the server event.
pub event_id : String,
/// The ID of the response.
pub response_id : String,
/// The ID of the item containing the audio.
pub item_id : String,
/// The index of the output item in the response.
pub output_index : i32,
/// The index of the content part in the item's content array.
pub content_index : i32,
}
/// Server event containing a delta of the model-generated audio transcript.
///
/// # Used By
/// - `RealtimeServerEvent`
#[ derive( Debug, Deserialize, Clone, PartialEq ) ]
pub struct RealtimeServerEventResponseAudioTranscriptDelta
{
/// The unique ID of the server event.
pub event_id : String,
/// The ID of the response.
pub response_id : String,
/// The ID of the item containing the audio.
pub item_id : String,
/// The index of the output item in the response.
pub output_index : i32,
/// The index of the content part in the item's content array.
pub content_index : i32,
/// The transcript delta.
pub delta : String,
}
/// Server event indicating the model-generated audio transcript is done.
///
/// # Used By
/// - `RealtimeServerEvent`
#[ derive( Debug, Deserialize, Clone, PartialEq ) ]
pub struct RealtimeServerEventResponseAudioTranscriptDone
{
/// The unique ID of the server event.
pub event_id : String,
/// The ID of the response.
pub response_id : String,
/// The ID of the item containing the audio.
pub item_id : String,
/// The index of the output item in the response.
pub output_index : i32,
/// The index of the content part in the item's content array.
pub content_index : i32,
/// The final transcript of the audio.
pub transcript : String,
}
/// Server event indicating a new content part was added to an output item.
///
/// # Used By
/// - `RealtimeServerEvent`
#[ derive( Debug, Deserialize, Clone, PartialEq ) ]
pub struct RealtimeServerEventResponseContentPartAdded
{
/// The unique ID of the server event.
pub event_id : String,
/// The ID of the response.
pub response_id : String,
/// The ID of the item to which the content part was added.
pub item_id : String,
/// The index of the output item in the response.
pub output_index : i32,
/// The index of the content part in the item's content array.
pub content_index : i32,
/// The content part that was added (structure depends on content type).
pub part : Value,
}
/// Server event indicating a content part is done streaming.
///
/// # Used By
/// - `RealtimeServerEvent`
#[ derive( Debug, Deserialize, Clone, PartialEq ) ]
pub struct RealtimeServerEventResponseContentPartDone
{
/// The unique ID of the server event.
pub event_id : String,
/// The ID of the response.
pub response_id : String,
/// The ID of the item.
pub item_id : String,
/// The index of the output item in the response.
pub output_index : i32,
/// The index of the content part in the item's content array.
pub content_index : i32,
/// The content part that is done (structure depends on content type).
pub part : Value,
}
/// Server event indicating a new response was created.
///
/// # Used By
/// - `RealtimeServerEvent`
#[ derive( Debug, Deserialize, Clone, PartialEq ) ]
pub struct RealtimeServerEventResponseCreated
{
/// The unique ID of the server event.
pub event_id : String,
/// The created response object (initial state).
pub response : RealtimeResponse,
}
/// Server event indicating a response is done streaming (completed, failed, etc.).
///
/// # Used By
/// - `RealtimeServerEvent`
#[ derive( Debug, Deserialize, Clone, PartialEq ) ]
pub struct RealtimeServerEventResponseDone
{
/// The unique ID of the server event.
pub event_id : String,
/// The final response object (omits raw audio data).
pub response : RealtimeResponse,
}
/// Server event containing a delta for function call arguments.
///
/// # Used By
/// - `RealtimeServerEvent`
#[ derive( Debug, Deserialize, Clone, PartialEq ) ]
pub struct RealtimeServerEventResponseFunctionCallArgumentsDelta
{
/// The unique ID of the server event.
pub event_id : String,
/// The ID of the response.
pub response_id : String,
/// The ID of the function call item.
pub item_id : String,
/// The index of the output item in the response.
pub output_index : i32,
/// The ID of the function call.
pub call_id : String,
/// The arguments delta as a JSON string.
pub delta : String,
}
/// Server event indicating function call arguments are finalized.
///
/// # Used By
/// - `RealtimeServerEvent`
#[ derive( Debug, Deserialize, Clone, PartialEq ) ]
pub struct RealtimeServerEventResponseFunctionCallArgumentsDone
{
/// The unique ID of the server event.
pub event_id : String,
/// The ID of the response.
pub response_id : String,
/// The ID of the function call item.
pub item_id : String,
/// The index of the output item in the response.
pub output_index : i32,
/// The ID of the function call.
pub call_id : String,
/// The final arguments as a JSON string.
pub arguments : String,
}
/// Server event indicating a new output item was added to the response.
///
/// # Used By
/// - `RealtimeServerEvent`
#[ derive( Debug, Deserialize, Clone, PartialEq ) ]
pub struct RealtimeServerEventResponseOutputItemAdded
{
/// The unique ID of the server event.
pub event_id : String,
/// The ID of the Response to which the item belongs.
pub response_id : String,
/// The index of the output item in the Response.
pub output_index : i32,
/// The output item that was added.
pub item : RealtimeConversationItem,
}
/// Server event indicating an output item is done streaming.
///
/// # Used By
/// - `RealtimeServerEvent`
#[ derive( Debug, Deserialize, Clone, PartialEq ) ]
pub struct RealtimeServerEventResponseOutputItemDone
{
/// The unique ID of the server event.
pub event_id : String,
/// The ID of the Response to which the item belongs.
pub response_id : String,
/// The index of the output item in the Response.
pub output_index : i32,
/// The output item that was marked done.
pub item : RealtimeConversationItem,
}
/// Server event containing a delta for text content.
///
/// # Used By
/// - `RealtimeServerEvent`
#[ derive( Debug, Deserialize, Clone, PartialEq ) ]
pub struct RealtimeServerEventResponseTextDelta
{
/// The unique ID of the server event.
pub event_id : String,
/// The ID of the response.
pub response_id : String,
/// The ID of the item containing the text.
pub item_id : String,
/// The index of the output item in the response.
pub output_index : i32,
/// The index of the content part in the item's content array.
pub content_index : i32,
/// The text delta.
pub delta : String,
}
/// Server event indicating text content is finalized.
///
/// # Used By
/// - `RealtimeServerEvent`
#[ derive( Debug, Deserialize, Clone, PartialEq ) ]
pub struct RealtimeServerEventResponseTextDone
{
/// The unique ID of the server event.
pub event_id : String,
/// The ID of the response.
pub response_id : String,
/// The ID of the item containing the text.
pub item_id : String,
/// The index of the output item in the response.
pub output_index : i32,
/// The index of the content part in the item's content array.
pub content_index : i32,
/// The final text content.
pub text : String,
}
/// Server event indicating the session was created (initial event).
///
/// # Used By
/// - `RealtimeServerEvent`
#[ derive( Debug, Deserialize, Clone, PartialEq ) ]
pub struct RealtimeServerEventSessionCreated
{
/// The unique ID of the server event.
pub event_id : String,
/// The initial session configuration.
pub session : RealtimeSession,
}
/// Server event confirming a session update.
///
/// # Used By
/// - `RealtimeServerEvent`
#[ derive( Debug, Deserialize, Clone, PartialEq ) ]
pub struct RealtimeServerEventSessionUpdated
{
/// The unique ID of the server event.
pub event_id : String,
/// The updated session configuration.
pub session : RealtimeSession,
}
/// Response object returned when creating a Realtime transcription session via REST API.
///
/// # Used By
/// - `/realtime/transcription_sessions` (POST)
/// - `RealtimeServerEventTranscriptionSessionUpdated`
#[ derive( Debug, Serialize, Deserialize, Clone, PartialEq ) ]
pub struct RealtimeServerEventTranscriptionSessionCreated
{
/// Unique identifier for the session.
#[ serde( skip_serializing_if = "Option::is_none" ) ]
pub id : Option< String >,
/// The object type, always "`realtime.transcription_session`".
#[ serde( skip_serializing_if = "Option::is_none" ) ]
pub object : Option< String >,
/// The set of modalities supported (always [`"audio"`, `"text"`] for transcription).
#[ serde( skip_serializing_if = "Option::is_none" ) ]
pub modalities : Option< Vec< String > >,
/// The format of input audio.
#[ serde( skip_serializing_if = "Option::is_none" ) ]
pub input_audio_format : Option< String >,
/// Configuration for input audio transcription.
#[ serde( skip_serializing_if = "Option::is_none" ) ]
pub input_audio_transcription : Option< crate::components::realtime_shared::session::RealtimeSessionInputAudioTranscription >,
/// Configuration for turn detection.
#[ serde( skip_serializing_if = "Option::is_none" ) ]
pub turn_detection : Option< crate::components::realtime_shared::session::RealtimeSessionTurnDetection >,
/// Configuration for input audio noise reduction.
#[ serde( skip_serializing_if = "Option::is_none" ) ]
pub input_audio_noise_reduction : Option< crate::components::realtime_shared::session::RealtimeSessionInputAudioNoiseReduction >,
/// Items to include in the transcription response (e.g., logprobs).
#[ serde( skip_serializing_if = "Option::is_none" ) ]
pub include : Option< Vec< String > >,
}
/// Server event confirming a transcription session update.
///
/// # Used By
/// - `RealtimeServerEvent`
#[ derive( Debug, Deserialize, Clone, PartialEq ) ]
pub struct RealtimeServerEventTranscriptionSessionUpdated
{
/// The unique ID of the server event.
pub event_id : String,
/// The updated transcription session configuration.
pub session : RealtimeTranscriptionSessionCreateResponse,
}
} // end mod private
crate ::mod_interface!
{
exposed use
{
RealtimeServerEventConversationCreated,
RealtimeServerEventConversationItemCreated,
RealtimeServerEventConversationItemDeleted,
RealtimeServerEventConversationItemInputAudioTranscriptionCompleted,
RealtimeServerEventConversationItemInputAudioTranscriptionDelta,
RealtimeServerEventConversationItemInputAudioTranscriptionFailed,
RealtimeServerEventConversationItemRetrieved,
RealtimeServerEventConversationItemTruncated,
RealtimeServerEventError,
RealtimeErrorDetails,
RealtimeServerEventInputAudioBufferCleared,
RealtimeServerEventInputAudioBufferCommitted,
RealtimeServerEventInputAudioBufferSpeechStarted,
RealtimeServerEventInputAudioBufferSpeechStopped,
RealtimeServerEventRateLimitsUpdated,
RateLimitInfo,
RealtimeServerEventResponseAudioDelta,
RealtimeServerEventResponseAudioDone,
RealtimeServerEventResponseAudioTranscriptDelta,
RealtimeServerEventResponseAudioTranscriptDone,
RealtimeServerEventResponseContentPartAdded,
RealtimeServerEventResponseContentPartDone,
RealtimeServerEventResponseCreated,
RealtimeServerEventResponseDone,
RealtimeServerEventResponseFunctionCallArgumentsDelta,
RealtimeServerEventResponseFunctionCallArgumentsDone,
RealtimeServerEventResponseOutputItemAdded,
RealtimeServerEventResponseOutputItemDone,
RealtimeServerEventResponseTextDelta,
RealtimeServerEventResponseTextDone,
RealtimeServerEventSessionCreated,
RealtimeServerEventSessionUpdated,
RealtimeServerEventTranscriptionSessionCreated,
RealtimeServerEventTranscriptionSessionUpdated,
};
}