Skip to main content

openai_types/realtime/
_gen.rs

1// AUTO-GENERATED by py2rust — do not edit.
2// Re-generate: python3 scripts/py2rust.py sync <python_dir> <rust_dir>
3// Domain: realtime
4#![allow(unused_imports)]
5
6use serde::{Deserialize, Serialize};
7use super::*;
8
9#[derive(Debug, Clone, Serialize, Deserialize)]
10#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
11pub struct AudioTranscription {
12    /// The language of the input audio.
13    #[serde(skip_serializing_if = "Option::is_none", default)]
14    pub language: Option<String>,
15    /// The model to use for transcription.
16    #[serde(skip_serializing_if = "Option::is_none", default)]
17    pub model: Option<String>,
18    /// An optional text to guide the model's style or continue a previous audio
19    #[serde(skip_serializing_if = "Option::is_none", default)]
20    pub prompt: Option<String>,
21}
22
23#[derive(Debug, Clone, Serialize, Deserialize)]
24#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
25pub struct CallAcceptParams {
26    /// The type of session to create. Always `realtime` for the Realtime API.
27    #[serde(rename = "type")]
28    pub type_: String,
29    /// Configuration for input and output audio.
30    #[serde(skip_serializing_if = "Option::is_none", default)]
31    pub audio: Option<serde_json::Value>,
32    /// Additional fields to include in server outputs.
33    #[serde(skip_serializing_if = "Option::is_none", default)]
34    pub include: Option<Vec<String>>,
35    /// The default system instructions (i.e.
36    #[serde(skip_serializing_if = "Option::is_none", default)]
37    pub instructions: Option<String>,
38    /// Maximum number of output tokens for a single assistant response, inclusive of
39    #[serde(skip_serializing_if = "Option::is_none", default)]
40    pub max_output_tokens: Option<String>,
41    /// The Realtime model used for this session.
42    #[serde(skip_serializing_if = "Option::is_none", default)]
43    pub model: Option<String>,
44    /// The set of modalities the model can respond with.
45    #[serde(skip_serializing_if = "Option::is_none", default)]
46    pub output_modalities: Option<Vec<serde_json::Value>>,
47    /// Reference to a prompt template and its variables.
48    #[serde(skip_serializing_if = "Option::is_none", default)]
49    pub prompt: Option<serde_json::Value>,
50    /// How the model chooses tools.
51    #[serde(skip_serializing_if = "Option::is_none", default)]
52    pub tool_choice: Option<serde_json::Value>,
53    /// Tools available to the model.
54    #[serde(skip_serializing_if = "Option::is_none", default)]
55    pub tools: Option<serde_json::Value>,
56    /// Realtime API can write session traces to the
57    #[serde(skip_serializing_if = "Option::is_none", default)]
58    pub tracing: Option<serde_json::Value>,
59    /// When the number of tokens in a conversation exceeds the model's input token
60    #[serde(skip_serializing_if = "Option::is_none", default)]
61    pub truncation: Option<serde_json::Value>,
62}
63
64#[derive(Debug, Clone, Serialize, Deserialize)]
65#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
66pub struct CallCreateParams {
67    /// WebRTC Session Description Protocol (SDP) offer generated by the caller.
68    pub sdp: String,
69    /// Realtime session object configuration.
70    #[serde(skip_serializing_if = "Option::is_none", default)]
71    pub session: Option<serde_json::Value>,
72}
73
74#[derive(Debug, Clone, Serialize, Deserialize)]
75#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
76pub struct CallReferParams {
77    /// URI that should appear in the SIP Refer-To header.
78    pub target_uri: String,
79}
80
81#[derive(Debug, Clone, Serialize, Deserialize)]
82#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
83pub struct CallRejectParams {
84    /// SIP response code to send back to the caller.
85    #[serde(skip_serializing_if = "Option::is_none", default)]
86    pub status_code: Option<i64>,
87}
88
89#[derive(Debug, Clone, Serialize, Deserialize)]
90#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
91pub struct ClientSecretCreateParams {
92    /// Configuration for the client secret expiration.
93    #[serde(skip_serializing_if = "Option::is_none", default)]
94    pub expires_after: Option<ExpiresAfter>,
95    /// Session configuration to use for the client secret.
96    #[serde(skip_serializing_if = "Option::is_none", default)]
97    pub session: Option<Session>,
98}
99
100/// Configuration for the client secret expiration.
101#[derive(Debug, Clone, Serialize, Deserialize)]
102#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
103pub struct ExpiresAfter {
104    /// The anchor point for the client secret expiration, meaning that `seconds` will
105    #[serde(skip_serializing_if = "Option::is_none", default)]
106    pub anchor: Option<String>,
107    /// The number of seconds from the anchor point to the expiration.
108    #[serde(skip_serializing_if = "Option::is_none", default)]
109    pub seconds: Option<i64>,
110}
111
112pub type Session = serde_json::Value;
113
114/// Response from creating a session and client secret for the Realtime API.
115#[derive(Debug, Clone, Serialize, Deserialize)]
116#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
117pub struct ClientSecretCreateResponse {
118    /// Expiration timestamp for the client secret, in seconds since epoch.
119    pub expires_at: i64,
120    /// The session configuration for either a realtime or transcription session.
121    pub session: Session,
122    /// The generated client secret value.
123    pub value: String,
124}
125
126/// The conversation resource.
127#[derive(Debug, Clone, Serialize, Deserialize)]
128#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
129pub struct Conversation {
130    /// The unique ID of the conversation.
131    #[serde(skip_serializing_if = "Option::is_none", default)]
132    pub id: Option<String>,
133    /// The object type, must be `realtime.conversation`.
134    #[serde(skip_serializing_if = "Option::is_none", default)]
135    pub object: Option<String>,
136}
137
138/// Returned when a conversation is created. Emitted right after session creation.
139#[derive(Debug, Clone, Serialize, Deserialize)]
140#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
141pub struct ConversationCreatedEvent {
142    /// The conversation resource.
143    pub conversation: Conversation,
144    /// The unique ID of the server event.
145    pub event_id: String,
146    /// The event type, must be `conversation.created`.
147    #[serde(rename = "type")]
148    pub type_: String,
149}
150
151pub type ConversationItem = serde_json::Value;
152
153/// Sent by the server when an Item is added to the default Conversation.
154#[derive(Debug, Clone, Serialize, Deserialize)]
155#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
156pub struct ConversationItemAdded {
157    /// The unique ID of the server event.
158    pub event_id: String,
159    /// A single item within a Realtime conversation.
160    pub item: ConversationItem,
161    /// The event type, must be `conversation.item.added`.
162    #[serde(rename = "type")]
163    pub type_: String,
164    /// The ID of the item that precedes this one, if any.
165    #[serde(skip_serializing_if = "Option::is_none", default)]
166    pub previous_item_id: Option<String>,
167}
168
169/// Add a new Item to the Conversation's context, including messages, function
170#[derive(Debug, Clone, Serialize, Deserialize)]
171#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
172pub struct ConversationItemCreateEvent {
173    /// A single item within a Realtime conversation.
174    pub item: ConversationItem,
175    /// The event type, must be `conversation.item.create`.
176    #[serde(rename = "type")]
177    pub type_: String,
178    /// Optional client-generated ID used to identify this event.
179    #[serde(skip_serializing_if = "Option::is_none", default)]
180    pub event_id: Option<String>,
181    /// The ID of the preceding item after which the new item will be inserted.
182    #[serde(skip_serializing_if = "Option::is_none", default)]
183    pub previous_item_id: Option<String>,
184}
185
186/// Returned when a conversation item is created.
187#[derive(Debug, Clone, Serialize, Deserialize)]
188#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
189pub struct ConversationItemCreatedEvent {
190    /// The unique ID of the server event.
191    pub event_id: String,
192    /// A single item within a Realtime conversation.
193    pub item: ConversationItem,
194    /// The event type, must be `conversation.item.created`.
195    #[serde(rename = "type")]
196    pub type_: String,
197    /// The ID of the preceding item in the Conversation context, allows the client to
198    #[serde(skip_serializing_if = "Option::is_none", default)]
199    pub previous_item_id: Option<String>,
200}
201
202/// Send this event when you want to remove any item from the conversation
203#[derive(Debug, Clone, Serialize, Deserialize)]
204#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
205pub struct ConversationItemDeleteEvent {
206    /// The ID of the item to delete.
207    pub item_id: String,
208    /// The event type, must be `conversation.item.delete`.
209    #[serde(rename = "type")]
210    pub type_: String,
211    /// Optional client-generated ID used to identify this event.
212    #[serde(skip_serializing_if = "Option::is_none", default)]
213    pub event_id: Option<String>,
214}
215
216/// Returned when an item in the conversation is deleted by the client with a
217#[derive(Debug, Clone, Serialize, Deserialize)]
218#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
219pub struct ConversationItemDeletedEvent {
220    /// The unique ID of the server event.
221    pub event_id: String,
222    /// The ID of the item that was deleted.
223    pub item_id: String,
224    /// The event type, must be `conversation.item.deleted`.
225    #[serde(rename = "type")]
226    pub type_: String,
227}
228
229/// Returned when a conversation item is finalized.
230#[derive(Debug, Clone, Serialize, Deserialize)]
231#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
232pub struct ConversationItemDone {
233    /// The unique ID of the server event.
234    pub event_id: String,
235    /// A single item within a Realtime conversation.
236    pub item: ConversationItem,
237    /// The event type, must be `conversation.item.done`.
238    #[serde(rename = "type")]
239    pub type_: String,
240    /// The ID of the item that precedes this one, if any.
241    #[serde(skip_serializing_if = "Option::is_none", default)]
242    pub previous_item_id: Option<String>,
243}
244
245/// Details about the input tokens billed for this request.
246#[derive(Debug, Clone, Serialize, Deserialize)]
247#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
248pub struct UsageTranscriptTextUsageTokensInputTokenDetails {
249    /// Number of audio tokens billed for this request.
250    #[serde(skip_serializing_if = "Option::is_none", default)]
251    pub audio_tokens: Option<i64>,
252    /// Number of text tokens billed for this request.
253    #[serde(skip_serializing_if = "Option::is_none", default)]
254    pub text_tokens: Option<i64>,
255}
256
257/// Usage statistics for models billed by token usage.
258#[derive(Debug, Clone, Serialize, Deserialize)]
259#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
260pub struct UsageTranscriptTextUsageTokens {
261    /// Number of input tokens billed for this request.
262    pub input_tokens: i64,
263    /// Number of output tokens generated.
264    pub output_tokens: i64,
265    /// Total number of tokens used (input + output).
266    pub total_tokens: i64,
267    /// The type of the usage object. Always `tokens` for this variant.
268    #[serde(rename = "type")]
269    pub type_: String,
270    /// Details about the input tokens billed for this request.
271    #[serde(skip_serializing_if = "Option::is_none", default)]
272    pub input_token_details: Option<UsageTranscriptTextUsageTokensInputTokenDetails>,
273}
274
275/// Usage statistics for models billed by audio input duration.
276#[derive(Debug, Clone, Serialize, Deserialize)]
277#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
278pub struct UsageTranscriptTextUsageDuration {
279    /// Duration of the input audio in seconds.
280    pub seconds: f64,
281    /// The type of the usage object. Always `duration` for this variant.
282    #[serde(rename = "type")]
283    pub type_: String,
284}
285
286pub type Usage = serde_json::Value;
287
288/// This event is the output of audio transcription for user audio written to the
289#[derive(Debug, Clone, Serialize, Deserialize)]
290#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
291pub struct ConversationItemInputAudioTranscriptionCompletedEvent {
292    /// The index of the content part containing the audio.
293    pub content_index: i64,
294    /// The unique ID of the server event.
295    pub event_id: String,
296    /// The ID of the item containing the audio that is being transcribed.
297    pub item_id: String,
298    /// The transcribed text.
299    pub transcript: String,
300    /// The event type, must be `conversation.item.input_audio_transcription.completed`.
301    #[serde(rename = "type")]
302    pub type_: String,
303    /// Usage statistics for the transcription, this is billed according to the ASR
304    pub usage: Usage,
305    /// The log probabilities of the transcription.
306    #[serde(skip_serializing_if = "Option::is_none", default)]
307    pub logprobs: Option<Vec<LogProbProperties>>,
308}
309
310/// Returned when the text value of an input audio transcription content part is updated with incremental transcription results.
311#[derive(Debug, Clone, Serialize, Deserialize)]
312#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
313pub struct ConversationItemInputAudioTranscriptionDeltaEvent {
314    /// The unique ID of the server event.
315    pub event_id: String,
316    /// The ID of the item containing the audio that is being transcribed.
317    pub item_id: String,
318    /// The event type, must be `conversation.item.input_audio_transcription.delta`.
319    #[serde(rename = "type")]
320    pub type_: String,
321    /// The index of the content part in the item's content array.
322    #[serde(skip_serializing_if = "Option::is_none", default)]
323    pub content_index: Option<i64>,
324    /// The text delta.
325    #[serde(skip_serializing_if = "Option::is_none", default)]
326    pub delta: Option<String>,
327    /// The log probabilities of the transcription.
328    #[serde(skip_serializing_if = "Option::is_none", default)]
329    pub logprobs: Option<Vec<LogProbProperties>>,
330}
331
332/// Details of the transcription error.
333#[derive(Debug, Clone, Serialize, Deserialize)]
334#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
335pub struct ConversationItemError {
336    /// Error code, if any.
337    #[serde(skip_serializing_if = "Option::is_none", default)]
338    pub code: Option<String>,
339    /// A human-readable error message.
340    #[serde(skip_serializing_if = "Option::is_none", default)]
341    pub message: Option<String>,
342    /// Parameter related to the error, if any.
343    #[serde(skip_serializing_if = "Option::is_none", default)]
344    pub param: Option<String>,
345    /// The type of error.
346    #[serde(rename = "type", skip_serializing_if = "Option::is_none", default)]
347    pub type_: Option<String>,
348}
349
350/// Returned when input audio transcription is configured, and a transcription
351#[derive(Debug, Clone, Serialize, Deserialize)]
352#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
353pub struct ConversationItemInputAudioTranscriptionFailedEvent {
354    /// The index of the content part containing the audio.
355    pub content_index: i64,
356    /// Details of the transcription error.
357    pub error: serde_json::Value,
358    /// The unique ID of the server event.
359    pub event_id: String,
360    /// The ID of the user message item.
361    pub item_id: String,
362    /// The event type, must be `conversation.item.input_audio_transcription.failed`.
363    #[serde(rename = "type")]
364    pub type_: String,
365}
366
367/// Returned when an input audio transcription segment is identified for an item.
368#[derive(Debug, Clone, Serialize, Deserialize)]
369#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
370pub struct ConversationItemInputAudioTranscriptionSegment {
371    /// The segment identifier.
372    pub id: String,
373    /// The index of the input audio content part within the item.
374    pub content_index: i64,
375    /// End time of the segment in seconds.
376    pub end: f64,
377    /// The unique ID of the server event.
378    pub event_id: String,
379    /// The ID of the item containing the input audio content.
380    pub item_id: String,
381    /// The detected speaker label for this segment.
382    pub speaker: String,
383    /// Start time of the segment in seconds.
384    pub start: f64,
385    /// The text for this segment.
386    pub text: String,
387    /// The event type, must be `conversation.item.input_audio_transcription.segment`.
388    #[serde(rename = "type")]
389    pub type_: String,
390}
391
392/// Send this event when you want to retrieve the server's representation of a specific item in the conversation history. This is useful, for example, to inspect user audio after noise cancellation and VAD.
393#[derive(Debug, Clone, Serialize, Deserialize)]
394#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
395pub struct ConversationItemRetrieveEvent {
396    /// The ID of the item to retrieve.
397    pub item_id: String,
398    /// The event type, must be `conversation.item.retrieve`.
399    #[serde(rename = "type")]
400    pub type_: String,
401    /// Optional client-generated ID used to identify this event.
402    #[serde(skip_serializing_if = "Option::is_none", default)]
403    pub event_id: Option<String>,
404}
405
406/// Send this event to truncate a previous assistant message’s audio.
407#[derive(Debug, Clone, Serialize, Deserialize)]
408#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
409pub struct ConversationItemTruncateEvent {
410    /// Inclusive duration up to which audio is truncated, in milliseconds.
411    pub audio_end_ms: i64,
412    /// The index of the content part to truncate. Set this to `0`.
413    pub content_index: i64,
414    /// The ID of the assistant message item to truncate.
415    pub item_id: String,
416    /// The event type, must be `conversation.item.truncate`.
417    #[serde(rename = "type")]
418    pub type_: String,
419    /// Optional client-generated ID used to identify this event.
420    #[serde(skip_serializing_if = "Option::is_none", default)]
421    pub event_id: Option<String>,
422}
423
424/// Returned when an earlier assistant audio message item is truncated by the
425#[derive(Debug, Clone, Serialize, Deserialize)]
426#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
427pub struct ConversationItemTruncatedEvent {
428    /// The duration up to which the audio was truncated, in milliseconds.
429    pub audio_end_ms: i64,
430    /// The index of the content part that was truncated.
431    pub content_index: i64,
432    /// The unique ID of the server event.
433    pub event_id: String,
434    /// The ID of the assistant message item that was truncated.
435    pub item_id: String,
436    /// The event type, must be `conversation.item.truncated`.
437    #[serde(rename = "type")]
438    pub type_: String,
439}
440
441/// Send this event to append audio bytes to the input audio buffer.
442#[derive(Debug, Clone, Serialize, Deserialize)]
443#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
444pub struct InputAudioBufferAppendEvent {
445    /// Base64-encoded audio bytes.
446    pub audio: String,
447    /// The event type, must be `input_audio_buffer.append`.
448    #[serde(rename = "type")]
449    pub type_: String,
450    /// Optional client-generated ID used to identify this event.
451    #[serde(skip_serializing_if = "Option::is_none", default)]
452    pub event_id: Option<String>,
453}
454
455/// Send this event to clear the audio bytes in the buffer.
456#[derive(Debug, Clone, Serialize, Deserialize)]
457#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
458pub struct InputAudioBufferClearEvent {
459    /// The event type, must be `input_audio_buffer.clear`.
460    #[serde(rename = "type")]
461    pub type_: String,
462    /// Optional client-generated ID used to identify this event.
463    #[serde(skip_serializing_if = "Option::is_none", default)]
464    pub event_id: Option<String>,
465}
466
467/// Returned when the input audio buffer is cleared by the client with a
468#[derive(Debug, Clone, Serialize, Deserialize)]
469#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
470pub struct InputAudioBufferClearedEvent {
471    /// The unique ID of the server event.
472    pub event_id: String,
473    /// The event type, must be `input_audio_buffer.cleared`.
474    #[serde(rename = "type")]
475    pub type_: String,
476}
477
478/// Send this event to commit the user input audio buffer, which will create a  new user message item in the conversation. This event will produce an error  if the input audio buffer is empty. When in Server VAD mode, the client does  not need to send this event, the server will commit the audio buffer  automatically.
479#[derive(Debug, Clone, Serialize, Deserialize)]
480#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
481pub struct InputAudioBufferCommitEvent {
482    /// The event type, must be `input_audio_buffer.commit`.
483    #[serde(rename = "type")]
484    pub type_: String,
485    /// Optional client-generated ID used to identify this event.
486    #[serde(skip_serializing_if = "Option::is_none", default)]
487    pub event_id: Option<String>,
488}
489
490/// Returned when an input audio buffer is committed, either by the client or
491#[derive(Debug, Clone, Serialize, Deserialize)]
492#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
493pub struct InputAudioBufferCommittedEvent {
494    /// The unique ID of the server event.
495    pub event_id: String,
496    /// The ID of the user message item that will be created.
497    pub item_id: String,
498    /// The event type, must be `input_audio_buffer.committed`.
499    #[serde(rename = "type")]
500    pub type_: String,
501    /// The ID of the preceding item after which the new item will be inserted. Can be
502    #[serde(skip_serializing_if = "Option::is_none", default)]
503    pub previous_item_id: Option<String>,
504}
505
506/// **SIP Only:** Returned when an DTMF event is received.
507#[derive(Debug, Clone, Serialize, Deserialize)]
508#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
509pub struct InputAudioBufferDtmfEventReceivedEvent {
510    /// The telephone keypad that was pressed by the user.
511    pub event: String,
512    /// UTC Unix Timestamp when DTMF Event was received by server.
513    pub received_at: i64,
514    /// The event type, must be `input_audio_buffer.dtmf_event_received`.
515    #[serde(rename = "type")]
516    pub type_: String,
517}
518
519/// Sent by the server when in `server_vad` mode to indicate that speech has been
520#[derive(Debug, Clone, Serialize, Deserialize)]
521#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
522pub struct InputAudioBufferSpeechStartedEvent {
523    /// Milliseconds from the start of all audio written to the buffer during the
524    pub audio_start_ms: i64,
525    /// The unique ID of the server event.
526    pub event_id: String,
527    /// The ID of the user message item that will be created when speech stops.
528    pub item_id: String,
529    /// The event type, must be `input_audio_buffer.speech_started`.
530    #[serde(rename = "type")]
531    pub type_: String,
532}
533
534/// Returned in `server_vad` mode when the server detects the end of speech in
535#[derive(Debug, Clone, Serialize, Deserialize)]
536#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
537pub struct InputAudioBufferSpeechStoppedEvent {
538    /// Milliseconds since the session started when speech stopped.
539    pub audio_end_ms: i64,
540    /// The unique ID of the server event.
541    pub event_id: String,
542    /// The ID of the user message item that will be created.
543    pub item_id: String,
544    /// The event type, must be `input_audio_buffer.speech_stopped`.
545    #[serde(rename = "type")]
546    pub type_: String,
547}
548
549/// Returned when the Server VAD timeout is triggered for the input audio buffer.
550#[derive(Debug, Clone, Serialize, Deserialize)]
551#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
552pub struct InputAudioBufferTimeoutTriggered {
553    /// Millisecond offset of audio written to the input audio buffer at the time the
554    pub audio_end_ms: i64,
555    /// Millisecond offset of audio written to the input audio buffer that was after the
556    pub audio_start_ms: i64,
557    /// The unique ID of the server event.
558    pub event_id: String,
559    /// The ID of the item associated with this segment.
560    pub item_id: String,
561    /// The event type, must be `input_audio_buffer.timeout_triggered`.
562    #[serde(rename = "type")]
563    pub type_: String,
564}
565
566/// A log probability object.
567#[derive(Debug, Clone, Serialize, Deserialize)]
568#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
569pub struct LogProbProperties {
570    /// The token that was used to generate the log probability.
571    pub token: String,
572    /// The bytes that were used to generate the log probability.
573    pub bytes: Vec<i64>,
574    /// The log probability of the token.
575    pub logprob: f64,
576}
577
578/// Returned when listing MCP tools has completed for an item.
579#[derive(Debug, Clone, Serialize, Deserialize)]
580#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
581pub struct McpListToolsCompleted {
582    /// The unique ID of the server event.
583    pub event_id: String,
584    /// The ID of the MCP list tools item.
585    pub item_id: String,
586    /// The event type, must be `mcp_list_tools.completed`.
587    #[serde(rename = "type")]
588    pub type_: String,
589}
590
591/// Returned when listing MCP tools has failed for an item.
592#[derive(Debug, Clone, Serialize, Deserialize)]
593#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
594pub struct McpListToolsFailed {
595    /// The unique ID of the server event.
596    pub event_id: String,
597    /// The ID of the MCP list tools item.
598    pub item_id: String,
599    /// The event type, must be `mcp_list_tools.failed`.
600    #[serde(rename = "type")]
601    pub type_: String,
602}
603
604/// Returned when listing MCP tools is in progress for an item.
605#[derive(Debug, Clone, Serialize, Deserialize)]
606#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
607pub struct McpListToolsInProgress {
608    /// The unique ID of the server event.
609    pub event_id: String,
610    /// The ID of the MCP list tools item.
611    pub item_id: String,
612    /// The event type, must be `mcp_list_tools.in_progress`.
613    #[serde(rename = "type")]
614    pub type_: String,
615}
616
617/// **WebRTC/SIP Only:** Emit to cut off the current audio response.
618#[derive(Debug, Clone, Serialize, Deserialize)]
619#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
620pub struct OutputAudioBufferClearEvent {
621    /// The event type, must be `output_audio_buffer.clear`.
622    #[serde(rename = "type")]
623    pub type_: String,
624    /// The unique ID of the client event used for error handling.
625    #[serde(skip_serializing_if = "Option::is_none", default)]
626    pub event_id: Option<String>,
627}
628
629#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
630#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
631#[non_exhaustive]
632pub enum RateLimitName {
633    #[serde(rename = "requests")]
634    Requests,
635    #[serde(rename = "tokens")]
636    Tokens,
637}
638
639#[derive(Debug, Clone, Serialize, Deserialize)]
640#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
641pub struct RateLimit {
642    /// The maximum allowed value for the rate limit.
643    #[serde(skip_serializing_if = "Option::is_none", default)]
644    pub limit: Option<i64>,
645    /// The name of the rate limit (`requests`, `tokens`).
646    #[serde(skip_serializing_if = "Option::is_none", default)]
647    pub name: Option<RateLimitName>,
648    /// The remaining value before the limit is reached.
649    #[serde(skip_serializing_if = "Option::is_none", default)]
650    pub remaining: Option<i64>,
651    /// Seconds until the rate limit resets.
652    #[serde(skip_serializing_if = "Option::is_none", default)]
653    pub reset_seconds: Option<f64>,
654}
655
656/// Emitted at the beginning of a Response to indicate the updated rate limits.
657#[derive(Debug, Clone, Serialize, Deserialize)]
658#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
659pub struct RateLimitsUpdatedEvent {
660    /// The unique ID of the server event.
661    pub event_id: String,
662    /// List of rate limit information.
663    pub rate_limits: Vec<RateLimit>,
664    /// The event type, must be `rate_limits.updated`.
665    #[serde(rename = "type")]
666    pub type_: String,
667}
668
669/// Configuration for input and output audio.
670#[derive(Debug, Clone, Serialize, Deserialize)]
671#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
672pub struct RealtimeAudioConfig {
673    #[serde(skip_serializing_if = "Option::is_none", default)]
674    pub input: Option<RealtimeAudioConfigInput>,
675    #[serde(skip_serializing_if = "Option::is_none", default)]
676    pub output: Option<RealtimeAudioConfigOutput>,
677}
678
679/// Configuration for input audio noise reduction.
680#[derive(Debug, Clone, Serialize, Deserialize)]
681#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
682pub struct NoiseReduction {
683    /// Type of noise reduction.
684    #[serde(rename = "type", skip_serializing_if = "Option::is_none", default)]
685    pub type_: Option<NoiseReductionType>,
686}
687
688#[derive(Debug, Clone, Serialize, Deserialize)]
689#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
690pub struct RealtimeAudioConfigInput {
691    /// The format of the input audio.
692    #[serde(skip_serializing_if = "Option::is_none", default)]
693    pub format: Option<RealtimeAudioFormats>,
694    /// Configuration for input audio noise reduction.
695    #[serde(skip_serializing_if = "Option::is_none", default)]
696    pub noise_reduction: Option<NoiseReduction>,
697    /// Configuration for input audio transcription, defaults to off and can be set to
698    #[serde(skip_serializing_if = "Option::is_none", default)]
699    pub transcription: Option<AudioTranscription>,
700    /// Configuration for turn detection, ether Server VAD or Semantic VAD.
701    #[serde(skip_serializing_if = "Option::is_none", default)]
702    pub turn_detection: Option<RealtimeAudioInputTurnDetection>,
703}
704
705/// Custom voice reference.
706#[derive(Debug, Clone, Serialize, Deserialize)]
707#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
708pub struct VoiceID {
709    /// The custom voice ID, e.g. `voice_1234`.
710    pub id: String,
711}
712
713#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
714#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
715#[non_exhaustive]
716pub enum Voice {
717    Alloy,
718    Ash,
719    Ballad,
720    Coral,
721    Echo,
722    Sage,
723    Shimmer,
724    Verse,
725    Marin,
726    Cedar,
727}
728
729#[derive(Debug, Clone, Serialize, Deserialize)]
730#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
731pub struct RealtimeAudioConfigOutput {
732    /// The format of the output audio.
733    #[serde(skip_serializing_if = "Option::is_none", default)]
734    pub format: Option<RealtimeAudioFormats>,
735    /// The speed of the model's spoken response as a multiple of the original speed.
736    #[serde(skip_serializing_if = "Option::is_none", default)]
737    pub speed: Option<f64>,
738    /// The voice the model uses to respond.
739    #[serde(skip_serializing_if = "Option::is_none", default)]
740    pub voice: Option<Voice>,
741}
742
743/// The PCM audio format. Only a 24kHz sample rate is supported.
744#[derive(Debug, Clone, Serialize, Deserialize)]
745#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
746pub struct AudioPCM {
747    /// The sample rate of the audio. Always `24000`.
748    #[serde(skip_serializing_if = "Option::is_none", default)]
749    pub rate: Option<String>,
750    /// The audio format. Always `audio/pcm`.
751    #[serde(rename = "type", skip_serializing_if = "Option::is_none", default)]
752    pub type_: Option<String>,
753}
754
755/// The G.711 μ-law format.
756#[derive(Debug, Clone, Serialize, Deserialize)]
757#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
758pub struct AudioPCMU {
759    /// The audio format. Always `audio/pcmu`.
760    #[serde(rename = "type", skip_serializing_if = "Option::is_none", default)]
761    pub type_: Option<String>,
762}
763
764/// The G.711 A-law format.
765#[derive(Debug, Clone, Serialize, Deserialize)]
766#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
767pub struct AudioPCMA {
768    /// The audio format. Always `audio/pcma`.
769    #[serde(rename = "type", skip_serializing_if = "Option::is_none", default)]
770    pub type_: Option<String>,
771}
772
773pub type RealtimeAudioFormats = serde_json::Value;
774
775/// Server-side voice activity detection (VAD) which flips on when user speech is detected and off after a period of silence.
776#[derive(Debug, Clone, Serialize, Deserialize)]
777#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
778pub struct ServerVad {
779    /// Type of turn detection, `server_vad` to turn on simple Server VAD.
780    #[serde(rename = "type")]
781    pub type_: String,
782    /// Whether or not to automatically generate a response when a VAD stop event
783    #[serde(skip_serializing_if = "Option::is_none", default)]
784    pub create_response: Option<bool>,
785    /// Optional timeout after which a model response will be triggered automatically.
786    #[serde(skip_serializing_if = "Option::is_none", default)]
787    pub idle_timeout_ms: Option<i64>,
788    /// Whether or not to automatically interrupt (cancel) any ongoing response with
789    #[serde(skip_serializing_if = "Option::is_none", default)]
790    pub interrupt_response: Option<bool>,
791    /// Used only for `server_vad` mode.
792    #[serde(skip_serializing_if = "Option::is_none", default)]
793    pub prefix_padding_ms: Option<i64>,
794    /// Used only for `server_vad` mode.
795    #[serde(skip_serializing_if = "Option::is_none", default)]
796    pub silence_duration_ms: Option<i64>,
797    /// Used only for `server_vad` mode.
798    #[serde(skip_serializing_if = "Option::is_none", default)]
799    pub threshold: Option<f64>,
800}
801
802#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
803#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
804#[non_exhaustive]
805pub enum SemanticVadEagerness {
806    #[serde(rename = "low")]
807    Low,
808    #[serde(rename = "medium")]
809    Medium,
810    #[serde(rename = "high")]
811    High,
812    #[serde(rename = "auto")]
813    Auto,
814}
815
816/// Server-side semantic turn detection which uses a model to determine when the user has finished speaking.
817#[derive(Debug, Clone, Serialize, Deserialize)]
818#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
819pub struct SemanticVad {
820    /// Type of turn detection, `semantic_vad` to turn on Semantic VAD.
821    #[serde(rename = "type")]
822    pub type_: String,
823    /// Whether or not to automatically generate a response when a VAD stop event
824    #[serde(skip_serializing_if = "Option::is_none", default)]
825    pub create_response: Option<bool>,
826    /// Used only for `semantic_vad` mode.
827    #[serde(skip_serializing_if = "Option::is_none", default)]
828    pub eagerness: Option<SemanticVadEagerness>,
829    /// Whether or not to automatically interrupt any ongoing response with output to
830    #[serde(skip_serializing_if = "Option::is_none", default)]
831    pub interrupt_response: Option<bool>,
832}
833
834pub type RealtimeAudioInputTurnDetection = serde_json::Value;
835
836pub type RealtimeClientEvent = serde_json::Value;
837
838#[derive(Debug, Clone, Serialize, Deserialize)]
839#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
840pub struct RealtimeConnectParams {
841    #[serde(skip_serializing_if = "Option::is_none", default)]
842    pub call_id: Option<String>,
843    #[serde(skip_serializing_if = "Option::is_none", default)]
844    pub model: Option<String>,
845}
846
847#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
848#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
849#[non_exhaustive]
850pub enum RealtimeConversationContentType {
851    #[serde(rename = "output_text")]
852    OutputText,
853    #[serde(rename = "output_audio")]
854    OutputAudio,
855}
856
857#[derive(Debug, Clone, Serialize, Deserialize)]
858#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
859pub struct RealtimeConversationContent {
860    /// Base64-encoded audio bytes, these will be parsed as the format specified in the
861    #[serde(skip_serializing_if = "Option::is_none", default)]
862    pub audio: Option<String>,
863    /// The text content.
864    #[serde(skip_serializing_if = "Option::is_none", default)]
865    pub text: Option<String>,
866    /// The transcript of the audio content, this will always be present if the output
867    #[serde(skip_serializing_if = "Option::is_none", default)]
868    pub transcript: Option<String>,
869    /// The content type, `output_text` or `output_audio` depending on the session
870    #[serde(rename = "type", skip_serializing_if = "Option::is_none", default)]
871    pub type_: Option<RealtimeConversationContentType>,
872}
873
874#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
875#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
876#[non_exhaustive]
877pub enum RealtimeConversationItemAssistantMessageStatus {
878    #[serde(rename = "completed")]
879    Completed,
880    #[serde(rename = "incomplete")]
881    Incomplete,
882    #[serde(rename = "in_progress")]
883    InProgress,
884}
885
886/// An assistant message item in a Realtime conversation.
887#[derive(Debug, Clone, Serialize, Deserialize)]
888#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
889pub struct RealtimeConversationItemAssistantMessage {
890    /// The content of the message.
891    pub content: Vec<RealtimeConversationContent>,
892    /// The role of the message sender. Always `assistant`.
893    pub role: String,
894    /// The type of the item. Always `message`.
895    #[serde(rename = "type")]
896    pub type_: String,
897    /// The unique ID of the item.
898    #[serde(skip_serializing_if = "Option::is_none", default)]
899    pub id: Option<String>,
900    /// Identifier for the API object being returned - always `realtime.item`.
901    #[serde(skip_serializing_if = "Option::is_none", default)]
902    pub object: Option<String>,
903    /// The status of the item. Has no effect on the conversation.
904    #[serde(skip_serializing_if = "Option::is_none", default)]
905    pub status: Option<RealtimeConversationItemAssistantMessageStatus>,
906}
907
908#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
909#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
910#[non_exhaustive]
911pub enum RealtimeConversationItemFunctionCallStatus {
912    #[serde(rename = "completed")]
913    Completed,
914    #[serde(rename = "incomplete")]
915    Incomplete,
916    #[serde(rename = "in_progress")]
917    InProgress,
918}
919
920/// A function call item in a Realtime conversation.
921#[derive(Debug, Clone, Serialize, Deserialize)]
922#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
923pub struct RealtimeConversationItemFunctionCall {
924    /// The arguments of the function call.
925    pub arguments: String,
926    /// The name of the function being called.
927    pub name: String,
928    /// The type of the item. Always `function_call`.
929    #[serde(rename = "type")]
930    pub type_: String,
931    /// The unique ID of the item.
932    #[serde(skip_serializing_if = "Option::is_none", default)]
933    pub id: Option<String>,
934    /// The ID of the function call.
935    #[serde(skip_serializing_if = "Option::is_none", default)]
936    pub call_id: Option<String>,
937    /// Identifier for the API object being returned - always `realtime.item`.
938    #[serde(skip_serializing_if = "Option::is_none", default)]
939    pub object: Option<String>,
940    /// The status of the item. Has no effect on the conversation.
941    #[serde(skip_serializing_if = "Option::is_none", default)]
942    pub status: Option<RealtimeConversationItemFunctionCallStatus>,
943}
944
945#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
946#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
947#[non_exhaustive]
948pub enum RealtimeConversationItemFunctionCallOutputStatus {
949    #[serde(rename = "completed")]
950    Completed,
951    #[serde(rename = "incomplete")]
952    Incomplete,
953    #[serde(rename = "in_progress")]
954    InProgress,
955}
956
957/// A function call output item in a Realtime conversation.
958#[derive(Debug, Clone, Serialize, Deserialize)]
959#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
960pub struct RealtimeConversationItemFunctionCallOutput {
961    /// The ID of the function call this output is for.
962    pub call_id: String,
963    /// The output of the function call, this is free text and can contain any
964    pub output: String,
965    /// The type of the item. Always `function_call_output`.
966    #[serde(rename = "type")]
967    pub type_: String,
968    /// The unique ID of the item.
969    #[serde(skip_serializing_if = "Option::is_none", default)]
970    pub id: Option<String>,
971    /// Identifier for the API object being returned - always `realtime.item`.
972    #[serde(skip_serializing_if = "Option::is_none", default)]
973    pub object: Option<String>,
974    /// The status of the item. Has no effect on the conversation.
975    #[serde(skip_serializing_if = "Option::is_none", default)]
976    pub status: Option<RealtimeConversationItemFunctionCallOutputStatus>,
977}
978
979#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
980#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
981#[non_exhaustive]
982pub enum RealtimeConversationItemSystemMessageStatus {
983    #[serde(rename = "completed")]
984    Completed,
985    #[serde(rename = "incomplete")]
986    Incomplete,
987    #[serde(rename = "in_progress")]
988    InProgress,
989}
990
991/// A system message in a Realtime conversation can be used to provide additional context or instructions to the model. This is similar but distinct from the instruction prompt provided at the start of a conversation, as system messages can be added at any point in the conversation. For major changes to the conversation's behavior, use instructions, but for smaller updates (e.g. "the user is now asking about a different topic"), use system messages.
992#[derive(Debug, Clone, Serialize, Deserialize)]
993#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
994pub struct RealtimeConversationItemSystemMessage {
995    /// The content of the message.
996    pub content: Vec<RealtimeConversationContent>,
997    /// The role of the message sender. Always `system`.
998    pub role: String,
999    /// The type of the item. Always `message`.
1000    #[serde(rename = "type")]
1001    pub type_: String,
1002    /// The unique ID of the item.
1003    #[serde(skip_serializing_if = "Option::is_none", default)]
1004    pub id: Option<String>,
1005    /// Identifier for the API object being returned - always `realtime.item`.
1006    #[serde(skip_serializing_if = "Option::is_none", default)]
1007    pub object: Option<String>,
1008    /// The status of the item. Has no effect on the conversation.
1009    #[serde(skip_serializing_if = "Option::is_none", default)]
1010    pub status: Option<RealtimeConversationItemSystemMessageStatus>,
1011}
1012
1013#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
1014#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
1015#[non_exhaustive]
1016pub enum RealtimeConversationContentDetail {
1017    #[serde(rename = "auto")]
1018    Auto,
1019    #[serde(rename = "low")]
1020    Low,
1021    #[serde(rename = "high")]
1022    High,
1023}
1024
1025#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
1026#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
1027#[non_exhaustive]
1028pub enum RealtimeConversationItemUserMessageStatus {
1029    #[serde(rename = "completed")]
1030    Completed,
1031    #[serde(rename = "incomplete")]
1032    Incomplete,
1033    #[serde(rename = "in_progress")]
1034    InProgress,
1035}
1036
1037/// A user message item in a Realtime conversation.
1038#[derive(Debug, Clone, Serialize, Deserialize)]
1039#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
1040pub struct RealtimeConversationItemUserMessage {
1041    /// The content of the message.
1042    pub content: Vec<RealtimeConversationContent>,
1043    /// The role of the message sender. Always `user`.
1044    pub role: String,
1045    /// The type of the item. Always `message`.
1046    #[serde(rename = "type")]
1047    pub type_: String,
1048    /// The unique ID of the item.
1049    #[serde(skip_serializing_if = "Option::is_none", default)]
1050    pub id: Option<String>,
1051    /// Identifier for the API object being returned - always `realtime.item`.
1052    #[serde(skip_serializing_if = "Option::is_none", default)]
1053    pub object: Option<String>,
1054    /// The status of the item. Has no effect on the conversation.
1055    #[serde(skip_serializing_if = "Option::is_none", default)]
1056    pub status: Option<RealtimeConversationItemUserMessageStatus>,
1057}
1058
1059/// Details of the error.
1060#[derive(Debug, Clone, Serialize, Deserialize)]
1061#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
1062pub struct RealtimeError {
1063    /// A human-readable error message.
1064    pub message: String,
1065    /// The type of error (e.g., "invalid_request_error", "server_error").
1066    #[serde(rename = "type")]
1067    pub type_: String,
1068    /// Error code, if any.
1069    #[serde(skip_serializing_if = "Option::is_none", default)]
1070    pub code: Option<String>,
1071    /// The event_id of the client event that caused the error, if applicable.
1072    #[serde(skip_serializing_if = "Option::is_none", default)]
1073    pub event_id: Option<String>,
1074    /// Parameter related to the error, if any.
1075    #[serde(skip_serializing_if = "Option::is_none", default)]
1076    pub param: Option<String>,
1077}
1078
1079/// Returned when an error occurs, which could be a client problem or a server
1080#[derive(Debug, Clone, Serialize, Deserialize)]
1081#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
1082pub struct RealtimeErrorEvent {
1083    /// Details of the error.
1084    pub error: RealtimeError,
1085    /// The unique ID of the server event.
1086    pub event_id: String,
1087    /// The event type, must be `error`.
1088    #[serde(rename = "type")]
1089    pub type_: String,
1090}
1091
1092#[derive(Debug, Clone, Serialize, Deserialize)]
1093#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
1094pub struct RealtimeFunctionTool {
1095    /// The description of the function, including guidance on when and how to call it,
1096    #[serde(skip_serializing_if = "Option::is_none", default)]
1097    pub description: Option<String>,
1098    /// The name of the function.
1099    #[serde(skip_serializing_if = "Option::is_none", default)]
1100    pub name: Option<String>,
1101    /// Parameters of the function in JSON Schema.
1102    #[serde(skip_serializing_if = "Option::is_none", default)]
1103    pub parameters: Option<serde_json::Value>,
1104    /// The type of the tool, i.e. `function`.
1105    #[serde(rename = "type", skip_serializing_if = "Option::is_none", default)]
1106    pub type_: Option<String>,
1107}
1108
1109/// A Realtime item requesting human approval of a tool invocation.
1110#[derive(Debug, Clone, Serialize, Deserialize)]
1111#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
1112pub struct RealtimeMcpApprovalRequest {
1113    /// The unique ID of the approval request.
1114    pub id: String,
1115    /// A JSON string of arguments for the tool.
1116    pub arguments: String,
1117    /// The name of the tool to run.
1118    pub name: String,
1119    /// The label of the MCP server making the request.
1120    pub server_label: String,
1121    /// The type of the item. Always `mcp_approval_request`.
1122    #[serde(rename = "type")]
1123    pub type_: String,
1124}
1125
1126/// A Realtime item responding to an MCP approval request.
1127#[derive(Debug, Clone, Serialize, Deserialize)]
1128#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
1129pub struct RealtimeMcpApprovalResponse {
1130    /// The unique ID of the approval response.
1131    pub id: String,
1132    /// The ID of the approval request being answered.
1133    pub approval_request_id: String,
1134    /// Whether the request was approved.
1135    pub approve: bool,
1136    /// The type of the item. Always `mcp_approval_response`.
1137    #[serde(rename = "type")]
1138    pub type_: String,
1139    /// Optional reason for the decision.
1140    #[serde(skip_serializing_if = "Option::is_none", default)]
1141    pub reason: Option<String>,
1142}
1143
1144/// A tool available on an MCP server.
1145#[derive(Debug, Clone, Serialize, Deserialize)]
1146#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
1147pub struct RealtimeMcpTool {
1148    /// The JSON schema describing the tool's input.
1149    pub input_schema: serde_json::Value,
1150    /// The name of the tool.
1151    pub name: String,
1152    /// Additional annotations about the tool.
1153    #[serde(skip_serializing_if = "Option::is_none", default)]
1154    pub annotations: Option<serde_json::Value>,
1155    /// The description of the tool.
1156    #[serde(skip_serializing_if = "Option::is_none", default)]
1157    pub description: Option<String>,
1158}
1159
1160/// A Realtime item listing tools available on an MCP server.
1161#[derive(Debug, Clone, Serialize, Deserialize)]
1162#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
1163pub struct RealtimeMcpListTools {
1164    /// The label of the MCP server.
1165    pub server_label: String,
1166    /// The tools available on the server.
1167    pub tools: Vec<RealtimeMcpTool>,
1168    /// The type of the item. Always `mcp_list_tools`.
1169    #[serde(rename = "type")]
1170    pub type_: String,
1171    /// The unique ID of the list.
1172    #[serde(skip_serializing_if = "Option::is_none", default)]
1173    pub id: Option<String>,
1174}
1175
1176#[derive(Debug, Clone, Serialize, Deserialize)]
1177#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
1178pub struct RealtimeMcpProtocolError {
1179    pub code: i64,
1180    pub message: String,
1181    #[serde(rename = "type")]
1182    pub type_: String,
1183}
1184
1185pub type Error = serde_json::Value;
1186
1187/// A Realtime item representing an invocation of a tool on an MCP server.
1188#[derive(Debug, Clone, Serialize, Deserialize)]
1189#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
1190pub struct RealtimeMcpToolCall {
1191    /// The unique ID of the tool call.
1192    pub id: String,
1193    /// A JSON string of the arguments passed to the tool.
1194    pub arguments: String,
1195    /// The name of the tool that was run.
1196    pub name: String,
1197    /// The label of the MCP server running the tool.
1198    pub server_label: String,
1199    /// The type of the item. Always `mcp_call`.
1200    #[serde(rename = "type")]
1201    pub type_: String,
1202    /// The ID of an associated approval request, if any.
1203    #[serde(skip_serializing_if = "Option::is_none", default)]
1204    pub approval_request_id: Option<String>,
1205    /// The error from the tool call, if any.
1206    #[serde(skip_serializing_if = "Option::is_none", default)]
1207    pub error: Option<Error>,
1208    /// The output from the tool call.
1209    #[serde(skip_serializing_if = "Option::is_none", default)]
1210    pub output: Option<String>,
1211}
1212
1213#[derive(Debug, Clone, Serialize, Deserialize)]
1214#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
1215pub struct RealtimeMcpToolExecutionError {
1216    pub message: String,
1217    #[serde(rename = "type")]
1218    pub type_: String,
1219}
1220
1221#[derive(Debug, Clone, Serialize, Deserialize)]
1222#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
1223pub struct RealtimeMcphttpError {
1224    pub code: i64,
1225    pub message: String,
1226    #[serde(rename = "type")]
1227    pub type_: String,
1228}
1229
1230#[derive(Debug, Clone, Serialize, Deserialize)]
1231#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
1232pub struct AudioOutput {
1233    /// The format of the output audio.
1234    #[serde(skip_serializing_if = "Option::is_none", default)]
1235    pub format: Option<RealtimeAudioFormats>,
1236    /// The voice the model uses to respond.
1237    #[serde(skip_serializing_if = "Option::is_none", default)]
1238    pub voice: Option<String>,
1239}
1240
1241/// Configuration for audio output.
1242#[derive(Debug, Clone, Serialize, Deserialize)]
1243#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
1244pub struct Audio {
1245    #[serde(skip_serializing_if = "Option::is_none", default)]
1246    pub output: Option<AudioOutput>,
1247}
1248
1249/// The response resource.
1250#[derive(Debug, Clone, Serialize, Deserialize)]
1251#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
1252pub struct RealtimeResponse {
1253    /// The unique ID of the response, will look like `resp_1234`.
1254    #[serde(skip_serializing_if = "Option::is_none", default)]
1255    pub id: Option<String>,
1256    /// Configuration for audio output.
1257    #[serde(skip_serializing_if = "Option::is_none", default)]
1258    pub audio: Option<Audio>,
1259    /// Which conversation the response is added to, determined by the `conversation`
1260    #[serde(skip_serializing_if = "Option::is_none", default)]
1261    pub conversation_id: Option<String>,
1262    /// Maximum number of output tokens for a single assistant response, inclusive of
1263    #[serde(skip_serializing_if = "Option::is_none", default)]
1264    pub max_output_tokens: Option<String>,
1265    /// Set of 16 key-value pairs that can be attached to an object.
1266    #[serde(skip_serializing_if = "Option::is_none", default)]
1267    pub metadata: Option<serde_json::Value>,
1268    /// The object type, must be `realtime.response`.
1269    #[serde(skip_serializing_if = "Option::is_none", default)]
1270    pub object: Option<String>,
1271    /// The list of output items generated by the response.
1272    #[serde(skip_serializing_if = "Option::is_none", default)]
1273    pub output: Option<Vec<ConversationItem>>,
1274    /// The set of modalities the model used to respond, currently the only possible
1275    #[serde(skip_serializing_if = "Option::is_none", default)]
1276    pub output_modalities: Option<Vec<serde_json::Value>>,
1277    /// The final status of the response (`completed`, `cancelled`, `failed`, or
1278    #[serde(skip_serializing_if = "Option::is_none", default)]
1279    pub status: Option<RealtimeResponseStatus>,
1280    /// Additional details about the status.
1281    #[serde(skip_serializing_if = "Option::is_none", default)]
1282    pub status_details: Option<RealtimeResponseStatus>,
1283    /// Usage statistics for the Response, this will correspond to billing.
1284    #[serde(skip_serializing_if = "Option::is_none", default)]
1285    pub usage: Option<RealtimeResponseUsage>,
1286}
1287
1288/// Custom voice reference.
1289#[derive(Debug, Clone, Serialize, Deserialize)]
1290#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
1291pub struct OutputVoiceID {
1292    /// The custom voice ID, e.g. `voice_1234`.
1293    pub id: String,
1294}
1295
1296#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
1297#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
1298#[non_exhaustive]
1299pub enum OutputVoice {
1300    Alloy,
1301    Ash,
1302    Ballad,
1303    Coral,
1304    Echo,
1305    Sage,
1306    Shimmer,
1307    Verse,
1308    Marin,
1309    Cedar,
1310}
1311
1312#[derive(Debug, Clone, Serialize, Deserialize)]
1313#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
1314pub struct RealtimeResponseOutput {
1315    /// The format of the output audio.
1316    #[serde(skip_serializing_if = "Option::is_none", default)]
1317    pub format: Option<RealtimeAudioFormats>,
1318    /// The voice the model uses to respond.
1319    #[serde(skip_serializing_if = "Option::is_none", default)]
1320    pub voice: Option<OutputVoice>,
1321}
1322
1323/// Configuration for audio input and output.
1324#[derive(Debug, Clone, Serialize, Deserialize)]
1325#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
1326pub struct RealtimeResponseCreateAudioOutput {
1327    #[serde(skip_serializing_if = "Option::is_none", default)]
1328    pub output: Option<RealtimeResponseOutput>,
1329}
1330
1331/// A filter object to specify which tools are allowed.
1332#[derive(Debug, Clone, Serialize, Deserialize)]
1333#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
1334pub struct AllowedToolsMcpToolFilter {
1335    /// Indicates whether or not a tool modifies data or is read-only.
1336    #[serde(skip_serializing_if = "Option::is_none", default)]
1337    pub read_only: Option<bool>,
1338    /// List of allowed tool names.
1339    #[serde(skip_serializing_if = "Option::is_none", default)]
1340    pub tool_names: Option<Vec<String>>,
1341}
1342
1343pub type AllowedTools = serde_json::Value;
1344
1345/// A filter object to specify which tools are allowed.
1346#[derive(Debug, Clone, Serialize, Deserialize)]
1347#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
1348pub struct RequireApprovalMcpToolApprovalFilterAlways {
1349    /// Indicates whether or not a tool modifies data or is read-only.
1350    #[serde(skip_serializing_if = "Option::is_none", default)]
1351    pub read_only: Option<bool>,
1352    /// List of allowed tool names.
1353    #[serde(skip_serializing_if = "Option::is_none", default)]
1354    pub tool_names: Option<Vec<String>>,
1355}
1356
1357/// A filter object to specify which tools are allowed.
1358#[derive(Debug, Clone, Serialize, Deserialize)]
1359#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
1360pub struct RequireApprovalMcpToolApprovalFilterNever {
1361    /// Indicates whether or not a tool modifies data or is read-only.
1362    #[serde(skip_serializing_if = "Option::is_none", default)]
1363    pub read_only: Option<bool>,
1364    /// List of allowed tool names.
1365    #[serde(skip_serializing_if = "Option::is_none", default)]
1366    pub tool_names: Option<Vec<String>>,
1367}
1368
1369/// Specify which of the MCP server's tools require approval.
1370#[derive(Debug, Clone, Serialize, Deserialize)]
1371#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
1372pub struct RequireApprovalMcpToolApprovalFilter {
1373    /// A filter object to specify which tools are allowed.
1374    #[serde(skip_serializing_if = "Option::is_none", default)]
1375    pub always: Option<RequireApprovalMcpToolApprovalFilterAlways>,
1376    /// A filter object to specify which tools are allowed.
1377    #[serde(skip_serializing_if = "Option::is_none", default)]
1378    pub never: Option<RequireApprovalMcpToolApprovalFilterNever>,
1379}
1380
1381#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
1382#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
1383#[non_exhaustive]
1384pub enum RequireApproval {
1385    Always,
1386    Never,
1387}
1388
1389#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
1390#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
1391#[non_exhaustive]
1392pub enum RealtimeResponseCreateMcpToolConnectorId {
1393    #[serde(rename = "connector_dropbox")]
1394    ConnectorDropbox,
1395    #[serde(rename = "connector_gmail")]
1396    ConnectorGmail,
1397    #[serde(rename = "connector_googlecalendar")]
1398    ConnectorGooglecalendar,
1399    #[serde(rename = "connector_googledrive")]
1400    ConnectorGoogledrive,
1401    #[serde(rename = "connector_microsoftteams")]
1402    ConnectorMicrosoftteams,
1403    #[serde(rename = "connector_outlookcalendar")]
1404    ConnectorOutlookcalendar,
1405    #[serde(rename = "connector_outlookemail")]
1406    ConnectorOutlookemail,
1407    #[serde(rename = "connector_sharepoint")]
1408    ConnectorSharepoint,
1409}
1410
1411/// Give the model access to additional tools via remote Model Context Protocol
1412#[derive(Debug, Clone, Serialize, Deserialize)]
1413#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
1414pub struct RealtimeResponseCreateMcpTool {
1415    /// A label for this MCP server, used to identify it in tool calls.
1416    pub server_label: String,
1417    /// The type of the MCP tool. Always `mcp`.
1418    #[serde(rename = "type")]
1419    pub type_: String,
1420    /// List of allowed tool names or a filter object.
1421    #[serde(skip_serializing_if = "Option::is_none", default)]
1422    pub allowed_tools: Option<AllowedTools>,
1423    /// An OAuth access token that can be used with a remote MCP server, either with a
1424    #[serde(skip_serializing_if = "Option::is_none", default)]
1425    pub authorization: Option<String>,
1426    /// Identifier for service connectors, like those available in ChatGPT.
1427    #[serde(skip_serializing_if = "Option::is_none", default)]
1428    pub connector_id: Option<RealtimeResponseCreateMcpToolConnectorId>,
1429    /// Whether this MCP tool is deferred and discovered via tool search.
1430    #[serde(skip_serializing_if = "Option::is_none", default)]
1431    pub defer_loading: Option<bool>,
1432    /// Optional HTTP headers to send to the MCP server.
1433    #[serde(skip_serializing_if = "Option::is_none", default)]
1434    pub headers: Option<std::collections::HashMap<String, String>>,
1435    /// Specify which of the MCP server's tools require approval.
1436    #[serde(skip_serializing_if = "Option::is_none", default)]
1437    pub require_approval: Option<RequireApproval>,
1438    /// Optional description of the MCP server, used to provide more context.
1439    #[serde(skip_serializing_if = "Option::is_none", default)]
1440    pub server_description: Option<String>,
1441    /// The URL for the MCP server.
1442    #[serde(skip_serializing_if = "Option::is_none", default)]
1443    pub server_url: Option<String>,
1444}
1445
1446pub type ToolChoice = serde_json::Value;
1447
1448pub type Tool = serde_json::Value;
1449
1450/// Create a new Realtime response with these parameters
1451#[derive(Debug, Clone, Serialize, Deserialize)]
1452#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
1453pub struct RealtimeResponseCreateParams {
1454    /// Configuration for audio input and output.
1455    #[serde(skip_serializing_if = "Option::is_none", default)]
1456    pub audio: Option<RealtimeResponseCreateAudioOutput>,
1457    /// Controls which conversation the response is added to.
1458    #[serde(skip_serializing_if = "Option::is_none", default)]
1459    pub conversation: Option<String>,
1460    /// Input items to include in the prompt for the model.
1461    #[serde(skip_serializing_if = "Option::is_none", default)]
1462    pub input: Option<Vec<ConversationItem>>,
1463    /// The default system instructions (i.e.
1464    #[serde(skip_serializing_if = "Option::is_none", default)]
1465    pub instructions: Option<String>,
1466    /// Maximum number of output tokens for a single assistant response, inclusive of
1467    #[serde(skip_serializing_if = "Option::is_none", default)]
1468    pub max_output_tokens: Option<String>,
1469    /// Set of 16 key-value pairs that can be attached to an object.
1470    #[serde(skip_serializing_if = "Option::is_none", default)]
1471    pub metadata: Option<serde_json::Value>,
1472    /// The set of modalities the model used to respond, currently the only possible
1473    #[serde(skip_serializing_if = "Option::is_none", default)]
1474    pub output_modalities: Option<Vec<serde_json::Value>>,
1475    /// Reference to a prompt template and its variables.
1476    #[serde(skip_serializing_if = "Option::is_none", default)]
1477    pub prompt: Option<serde_json::Value>,
1478    /// How the model chooses tools.
1479    #[serde(skip_serializing_if = "Option::is_none", default)]
1480    pub tool_choice: Option<ToolChoice>,
1481    /// Tools available to the model.
1482    #[serde(skip_serializing_if = "Option::is_none", default)]
1483    pub tools: Option<Vec<RealtimeMcpTool>>,
1484}
1485
1486/// A description of the error that caused the response to fail,
1487#[derive(Debug, Clone, Serialize, Deserialize)]
1488#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
1489pub struct RealtimeResponseError {
1490    /// Error code, if any.
1491    #[serde(skip_serializing_if = "Option::is_none", default)]
1492    pub code: Option<String>,
1493    /// The type of error.
1494    #[serde(rename = "type", skip_serializing_if = "Option::is_none", default)]
1495    pub type_: Option<String>,
1496}
1497
1498#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
1499#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
1500#[non_exhaustive]
1501pub enum RealtimeResponseStatusReason {
1502    #[serde(rename = "turn_detected")]
1503    TurnDetected,
1504    #[serde(rename = "client_cancelled")]
1505    ClientCancelled,
1506    #[serde(rename = "max_output_tokens")]
1507    MaxOutputTokens,
1508    #[serde(rename = "content_filter")]
1509    ContentFilter,
1510}
1511
1512#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
1513#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
1514#[non_exhaustive]
1515pub enum RealtimeResponseStatusType {
1516    #[serde(rename = "completed")]
1517    Completed,
1518    #[serde(rename = "cancelled")]
1519    Cancelled,
1520    #[serde(rename = "incomplete")]
1521    Incomplete,
1522    #[serde(rename = "failed")]
1523    Failed,
1524}
1525
1526/// Additional details about the status.
1527#[derive(Debug, Clone, Serialize, Deserialize)]
1528#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
1529pub struct RealtimeResponseStatus {
1530    /// A description of the error that caused the response to fail, populated when the
1531    #[serde(skip_serializing_if = "Option::is_none", default)]
1532    pub error: Option<Error>,
1533    /// The reason the Response did not complete.
1534    #[serde(skip_serializing_if = "Option::is_none", default)]
1535    pub reason: Option<RealtimeResponseStatusReason>,
1536    /// The type of error that caused the response to fail, corresponding with the
1537    #[serde(rename = "type", skip_serializing_if = "Option::is_none", default)]
1538    pub type_: Option<RealtimeResponseStatusType>,
1539}
1540
1541/// Usage statistics for the Response, this will correspond to billing.
1542#[derive(Debug, Clone, Serialize, Deserialize)]
1543#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
1544pub struct RealtimeResponseUsage {
1545    /// Details about the input tokens used in the Response.
1546    #[serde(skip_serializing_if = "Option::is_none", default)]
1547    pub input_token_details: Option<RealtimeResponseUsageInputTokenDetails>,
1548    /// The number of input tokens used in the Response, including text and audio
1549    #[serde(skip_serializing_if = "Option::is_none", default)]
1550    pub input_tokens: Option<i64>,
1551    /// Details about the output tokens used in the Response.
1552    #[serde(skip_serializing_if = "Option::is_none", default)]
1553    pub output_token_details: Option<RealtimeResponseUsageOutputTokenDetails>,
1554    /// The number of output tokens sent in the Response, including text and audio
1555    #[serde(skip_serializing_if = "Option::is_none", default)]
1556    pub output_tokens: Option<i64>,
1557    /// The total number of tokens in the Response including input and output text and
1558    #[serde(skip_serializing_if = "Option::is_none", default)]
1559    pub total_tokens: Option<i64>,
1560}
1561
1562/// Details about the cached tokens used as input for the Response.
1563#[derive(Debug, Clone, Serialize, Deserialize)]
1564#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
1565pub struct CachedTokensDetails {
1566    /// The number of cached audio tokens used as input for the Response.
1567    #[serde(skip_serializing_if = "Option::is_none", default)]
1568    pub audio_tokens: Option<i64>,
1569    /// The number of cached image tokens used as input for the Response.
1570    #[serde(skip_serializing_if = "Option::is_none", default)]
1571    pub image_tokens: Option<i64>,
1572    /// The number of cached text tokens used as input for the Response.
1573    #[serde(skip_serializing_if = "Option::is_none", default)]
1574    pub text_tokens: Option<i64>,
1575}
1576
1577/// Details about the input tokens used in the Response.
1578#[derive(Debug, Clone, Serialize, Deserialize)]
1579#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
1580pub struct RealtimeResponseUsageInputTokenDetails {
1581    /// The number of audio tokens used as input for the Response.
1582    #[serde(skip_serializing_if = "Option::is_none", default)]
1583    pub audio_tokens: Option<i64>,
1584    /// The number of cached tokens used as input for the Response.
1585    #[serde(skip_serializing_if = "Option::is_none", default)]
1586    pub cached_tokens: Option<i64>,
1587    /// Details about the cached tokens used as input for the Response.
1588    #[serde(skip_serializing_if = "Option::is_none", default)]
1589    pub cached_tokens_details: Option<CachedTokensDetails>,
1590    /// The number of image tokens used as input for the Response.
1591    #[serde(skip_serializing_if = "Option::is_none", default)]
1592    pub image_tokens: Option<i64>,
1593    /// The number of text tokens used as input for the Response.
1594    #[serde(skip_serializing_if = "Option::is_none", default)]
1595    pub text_tokens: Option<i64>,
1596}
1597
1598/// Details about the output tokens used in the Response.
1599#[derive(Debug, Clone, Serialize, Deserialize)]
1600#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
1601pub struct RealtimeResponseUsageOutputTokenDetails {
1602    /// The number of audio tokens used in the Response.
1603    #[serde(skip_serializing_if = "Option::is_none", default)]
1604    pub audio_tokens: Option<i64>,
1605    /// The number of text tokens used in the Response.
1606    #[serde(skip_serializing_if = "Option::is_none", default)]
1607    pub text_tokens: Option<i64>,
1608}
1609
1610/// Returned when a conversation item is retrieved with `conversation.item.retrieve`.
1611#[derive(Debug, Clone, Serialize, Deserialize)]
1612#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
1613pub struct ConversationItemRetrieved {
1614    /// The unique ID of the server event.
1615    pub event_id: String,
1616    /// A single item within a Realtime conversation.
1617    pub item: ConversationItem,
1618    /// The event type, must be `conversation.item.retrieved`.
1619    #[serde(rename = "type")]
1620    pub type_: String,
1621}
1622
1623/// **WebRTC/SIP Only:** Emitted when the server begins streaming audio to the client. This event is
1624#[derive(Debug, Clone, Serialize, Deserialize)]
1625#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
1626pub struct OutputAudioBufferStarted {
1627    /// The unique ID of the server event.
1628    pub event_id: String,
1629    /// The unique ID of the response that produced the audio.
1630    pub response_id: String,
1631    /// The event type, must be `output_audio_buffer.started`.
1632    #[serde(rename = "type")]
1633    pub type_: String,
1634}
1635
1636/// **WebRTC/SIP Only:** Emitted when the output audio buffer has been completely drained on the server,
1637#[derive(Debug, Clone, Serialize, Deserialize)]
1638#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
1639pub struct OutputAudioBufferStopped {
1640    /// The unique ID of the server event.
1641    pub event_id: String,
1642    /// The unique ID of the response that produced the audio.
1643    pub response_id: String,
1644    /// The event type, must be `output_audio_buffer.stopped`.
1645    #[serde(rename = "type")]
1646    pub type_: String,
1647}
1648
1649/// **WebRTC/SIP Only:** Emitted when the output audio buffer is cleared.
1650#[derive(Debug, Clone, Serialize, Deserialize)]
1651#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
1652pub struct OutputAudioBufferCleared {
1653    /// The unique ID of the server event.
1654    pub event_id: String,
1655    /// The unique ID of the response that produced the audio.
1656    pub response_id: String,
1657    /// The event type, must be `output_audio_buffer.cleared`.
1658    #[serde(rename = "type")]
1659    pub type_: String,
1660}
1661
1662pub type RealtimeServerEvent = serde_json::Value;
1663
1664/// Ephemeral key returned by the API.
1665#[derive(Debug, Clone, Serialize, Deserialize)]
1666#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
1667pub struct RealtimeSessionClientSecret {
1668    /// Timestamp for when the token expires.
1669    pub expires_at: i64,
1670    /// Ephemeral key usable in client environments to authenticate connections to the
1671    pub value: String,
1672}
1673
1674/// Realtime session object configuration.
1675#[derive(Debug, Clone, Serialize, Deserialize)]
1676#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
1677pub struct RealtimeSessionCreateRequest {
1678    /// The type of session to create. Always `realtime` for the Realtime API.
1679    #[serde(rename = "type")]
1680    pub type_: String,
1681    /// Configuration for input and output audio.
1682    #[serde(skip_serializing_if = "Option::is_none", default)]
1683    pub audio: Option<RealtimeAudioConfig>,
1684    /// Additional fields to include in server outputs.
1685    #[serde(skip_serializing_if = "Option::is_none", default)]
1686    pub include: Option<Vec<String>>,
1687    /// The default system instructions (i.e.
1688    #[serde(skip_serializing_if = "Option::is_none", default)]
1689    pub instructions: Option<String>,
1690    /// Maximum number of output tokens for a single assistant response, inclusive of
1691    #[serde(skip_serializing_if = "Option::is_none", default)]
1692    pub max_output_tokens: Option<String>,
1693    /// The Realtime model used for this session.
1694    #[serde(skip_serializing_if = "Option::is_none", default)]
1695    pub model: Option<String>,
1696    /// The set of modalities the model can respond with.
1697    #[serde(skip_serializing_if = "Option::is_none", default)]
1698    pub output_modalities: Option<Vec<serde_json::Value>>,
1699    /// Reference to a prompt template and its variables.
1700    #[serde(skip_serializing_if = "Option::is_none", default)]
1701    pub prompt: Option<serde_json::Value>,
1702    /// How the model chooses tools.
1703    #[serde(skip_serializing_if = "Option::is_none", default)]
1704    pub tool_choice: Option<RealtimeToolChoiceConfig>,
1705    /// Tools available to the model.
1706    #[serde(skip_serializing_if = "Option::is_none", default)]
1707    pub tools: Option<RealtimeToolsConfig>,
1708    /// Realtime API can write session traces to the
1709    #[serde(skip_serializing_if = "Option::is_none", default)]
1710    pub tracing: Option<RealtimeTracingConfig>,
1711    /// When the number of tokens in a conversation exceeds the model's input token
1712    #[serde(skip_serializing_if = "Option::is_none", default)]
1713    pub truncation: Option<RealtimeTruncation>,
1714}
1715
1716/// Configuration for input audio noise reduction.
1717#[derive(Debug, Clone, Serialize, Deserialize)]
1718#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
1719pub struct AudioInputNoiseReduction {
1720    /// Type of noise reduction.
1721    #[serde(rename = "type", skip_serializing_if = "Option::is_none", default)]
1722    pub type_: Option<NoiseReductionType>,
1723}
1724
1725/// Server-side voice activity detection (VAD) which flips on when user speech is detected and off after a period of silence.
1726#[derive(Debug, Clone, Serialize, Deserialize)]
1727#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
1728pub struct AudioInputTurnDetectionServerVad {
1729    /// Type of turn detection, `server_vad` to turn on simple Server VAD.
1730    #[serde(rename = "type")]
1731    pub type_: String,
1732    /// Whether or not to automatically generate a response when a VAD stop event
1733    #[serde(skip_serializing_if = "Option::is_none", default)]
1734    pub create_response: Option<bool>,
1735    /// Optional timeout after which a model response will be triggered automatically.
1736    #[serde(skip_serializing_if = "Option::is_none", default)]
1737    pub idle_timeout_ms: Option<i64>,
1738    /// Whether or not to automatically interrupt (cancel) any ongoing response with
1739    #[serde(skip_serializing_if = "Option::is_none", default)]
1740    pub interrupt_response: Option<bool>,
1741    /// Used only for `server_vad` mode.
1742    #[serde(skip_serializing_if = "Option::is_none", default)]
1743    pub prefix_padding_ms: Option<i64>,
1744    /// Used only for `server_vad` mode.
1745    #[serde(skip_serializing_if = "Option::is_none", default)]
1746    pub silence_duration_ms: Option<i64>,
1747    /// Used only for `server_vad` mode.
1748    #[serde(skip_serializing_if = "Option::is_none", default)]
1749    pub threshold: Option<f64>,
1750}
1751
1752#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
1753#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
1754#[non_exhaustive]
1755pub enum AudioInputTurnDetectionSemanticVadEagerness {
1756    #[serde(rename = "low")]
1757    Low,
1758    #[serde(rename = "medium")]
1759    Medium,
1760    #[serde(rename = "high")]
1761    High,
1762    #[serde(rename = "auto")]
1763    Auto,
1764}
1765
1766/// Server-side semantic turn detection which uses a model to determine when the user has finished speaking.
1767#[derive(Debug, Clone, Serialize, Deserialize)]
1768#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
1769pub struct AudioInputTurnDetectionSemanticVad {
1770    /// Type of turn detection, `semantic_vad` to turn on Semantic VAD.
1771    #[serde(rename = "type")]
1772    pub type_: String,
1773    /// Whether or not to automatically generate a response when a VAD stop event
1774    #[serde(skip_serializing_if = "Option::is_none", default)]
1775    pub create_response: Option<bool>,
1776    /// Used only for `semantic_vad` mode.
1777    #[serde(skip_serializing_if = "Option::is_none", default)]
1778    pub eagerness: Option<AudioInputTurnDetectionSemanticVadEagerness>,
1779    /// Whether or not to automatically interrupt any ongoing response with output to
1780    #[serde(skip_serializing_if = "Option::is_none", default)]
1781    pub interrupt_response: Option<bool>,
1782}
1783
1784pub type AudioInputTurnDetection = serde_json::Value;
1785
1786#[derive(Debug, Clone, Serialize, Deserialize)]
1787#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
1788pub struct AudioInput {
1789    /// The format of the input audio.
1790    #[serde(skip_serializing_if = "Option::is_none", default)]
1791    pub format: Option<RealtimeAudioFormats>,
1792    /// Configuration for input audio noise reduction.
1793    #[serde(skip_serializing_if = "Option::is_none", default)]
1794    pub noise_reduction: Option<AudioInputNoiseReduction>,
1795    /// Configuration for input audio transcription, defaults to off and can be set to
1796    #[serde(skip_serializing_if = "Option::is_none", default)]
1797    pub transcription: Option<AudioTranscription>,
1798    /// Configuration for turn detection, ether Server VAD or Semantic VAD.
1799    #[serde(skip_serializing_if = "Option::is_none", default)]
1800    pub turn_detection: Option<AudioInputTurnDetection>,
1801}
1802
1803/// A filter object to specify which tools are allowed.
1804#[derive(Debug, Clone, Serialize, Deserialize)]
1805#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
1806pub struct ToolMcpToolAllowedToolsMcpToolFilter {
1807    /// Indicates whether or not a tool modifies data or is read-only.
1808    #[serde(skip_serializing_if = "Option::is_none", default)]
1809    pub read_only: Option<bool>,
1810    /// List of allowed tool names.
1811    #[serde(skip_serializing_if = "Option::is_none", default)]
1812    pub tool_names: Option<Vec<String>>,
1813}
1814
1815pub type ToolMcpToolAllowedTools = serde_json::Value;
1816
1817/// A filter object to specify which tools are allowed.
1818#[derive(Debug, Clone, Serialize, Deserialize)]
1819#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
1820pub struct ToolMcpToolRequireApprovalMcpToolApprovalFilterAlways {
1821    /// Indicates whether or not a tool modifies data or is read-only.
1822    #[serde(skip_serializing_if = "Option::is_none", default)]
1823    pub read_only: Option<bool>,
1824    /// List of allowed tool names.
1825    #[serde(skip_serializing_if = "Option::is_none", default)]
1826    pub tool_names: Option<Vec<String>>,
1827}
1828
1829/// A filter object to specify which tools are allowed.
1830#[derive(Debug, Clone, Serialize, Deserialize)]
1831#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
1832pub struct ToolMcpToolRequireApprovalMcpToolApprovalFilterNever {
1833    /// Indicates whether or not a tool modifies data or is read-only.
1834    #[serde(skip_serializing_if = "Option::is_none", default)]
1835    pub read_only: Option<bool>,
1836    /// List of allowed tool names.
1837    #[serde(skip_serializing_if = "Option::is_none", default)]
1838    pub tool_names: Option<Vec<String>>,
1839}
1840
1841/// Specify which of the MCP server's tools require approval.
1842#[derive(Debug, Clone, Serialize, Deserialize)]
1843#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
1844pub struct ToolMcpToolRequireApprovalMcpToolApprovalFilter {
1845    /// A filter object to specify which tools are allowed.
1846    #[serde(skip_serializing_if = "Option::is_none", default)]
1847    pub always: Option<ToolMcpToolRequireApprovalMcpToolApprovalFilterAlways>,
1848    /// A filter object to specify which tools are allowed.
1849    #[serde(skip_serializing_if = "Option::is_none", default)]
1850    pub never: Option<ToolMcpToolRequireApprovalMcpToolApprovalFilterNever>,
1851}
1852
1853#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
1854#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
1855#[non_exhaustive]
1856pub enum ToolMcpToolRequireApproval {
1857    Always,
1858    Never,
1859}
1860
1861#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
1862#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
1863#[non_exhaustive]
1864pub enum ToolMcpToolConnectorId {
1865    #[serde(rename = "connector_dropbox")]
1866    ConnectorDropbox,
1867    #[serde(rename = "connector_gmail")]
1868    ConnectorGmail,
1869    #[serde(rename = "connector_googlecalendar")]
1870    ConnectorGooglecalendar,
1871    #[serde(rename = "connector_googledrive")]
1872    ConnectorGoogledrive,
1873    #[serde(rename = "connector_microsoftteams")]
1874    ConnectorMicrosoftteams,
1875    #[serde(rename = "connector_outlookcalendar")]
1876    ConnectorOutlookcalendar,
1877    #[serde(rename = "connector_outlookemail")]
1878    ConnectorOutlookemail,
1879    #[serde(rename = "connector_sharepoint")]
1880    ConnectorSharepoint,
1881}
1882
1883/// Give the model access to additional tools via remote Model Context Protocol
1884#[derive(Debug, Clone, Serialize, Deserialize)]
1885#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
1886pub struct ToolMcpTool {
1887    /// A label for this MCP server, used to identify it in tool calls.
1888    pub server_label: String,
1889    /// The type of the MCP tool. Always `mcp`.
1890    #[serde(rename = "type")]
1891    pub type_: String,
1892    /// List of allowed tool names or a filter object.
1893    #[serde(skip_serializing_if = "Option::is_none", default)]
1894    pub allowed_tools: Option<ToolMcpToolAllowedTools>,
1895    /// An OAuth access token that can be used with a remote MCP server, either with a
1896    #[serde(skip_serializing_if = "Option::is_none", default)]
1897    pub authorization: Option<String>,
1898    /// Identifier for service connectors, like those available in ChatGPT.
1899    #[serde(skip_serializing_if = "Option::is_none", default)]
1900    pub connector_id: Option<ToolMcpToolConnectorId>,
1901    /// Whether this MCP tool is deferred and discovered via tool search.
1902    #[serde(skip_serializing_if = "Option::is_none", default)]
1903    pub defer_loading: Option<bool>,
1904    /// Optional HTTP headers to send to the MCP server.
1905    #[serde(skip_serializing_if = "Option::is_none", default)]
1906    pub headers: Option<std::collections::HashMap<String, String>>,
1907    /// Specify which of the MCP server's tools require approval.
1908    #[serde(skip_serializing_if = "Option::is_none", default)]
1909    pub require_approval: Option<ToolMcpToolRequireApproval>,
1910    /// Optional description of the MCP server, used to provide more context.
1911    #[serde(skip_serializing_if = "Option::is_none", default)]
1912    pub server_description: Option<String>,
1913    /// The URL for the MCP server.
1914    #[serde(skip_serializing_if = "Option::is_none", default)]
1915    pub server_url: Option<String>,
1916}
1917
1918/// Granular configuration for tracing.
1919#[derive(Debug, Clone, Serialize, Deserialize)]
1920#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
1921pub struct TracingTracingConfiguration {
1922    /// The group id to attach to this trace to enable filtering and grouping in the
1923    #[serde(skip_serializing_if = "Option::is_none", default)]
1924    pub group_id: Option<String>,
1925    /// The arbitrary metadata to attach to this trace to enable filtering in the Traces
1926    #[serde(skip_serializing_if = "Option::is_none", default)]
1927    pub metadata: Option<serde_json::Value>,
1928    /// The name of the workflow to attach to this trace.
1929    #[serde(skip_serializing_if = "Option::is_none", default)]
1930    pub workflow_name: Option<String>,
1931}
1932
1933#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
1934#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
1935#[non_exhaustive]
1936pub enum Tracing {
1937    Auto,
1938}
1939
1940/// A new Realtime session configuration, with an ephemeral key.
1941#[derive(Debug, Clone, Serialize, Deserialize)]
1942#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
1943pub struct RealtimeSessionCreateResponse {
1944    /// Ephemeral key returned by the API.
1945    pub client_secret: RealtimeSessionClientSecret,
1946    /// The type of session to create. Always `realtime` for the Realtime API.
1947    #[serde(rename = "type")]
1948    pub type_: String,
1949    /// Configuration for input and output audio.
1950    #[serde(skip_serializing_if = "Option::is_none", default)]
1951    pub audio: Option<Audio>,
1952    /// Additional fields to include in server outputs.
1953    #[serde(skip_serializing_if = "Option::is_none", default)]
1954    pub include: Option<Vec<String>>,
1955    /// The default system instructions (i.e.
1956    #[serde(skip_serializing_if = "Option::is_none", default)]
1957    pub instructions: Option<String>,
1958    /// Maximum number of output tokens for a single assistant response, inclusive of
1959    #[serde(skip_serializing_if = "Option::is_none", default)]
1960    pub max_output_tokens: Option<String>,
1961    /// The Realtime model used for this session.
1962    #[serde(skip_serializing_if = "Option::is_none", default)]
1963    pub model: Option<String>,
1964    /// The set of modalities the model can respond with.
1965    #[serde(skip_serializing_if = "Option::is_none", default)]
1966    pub output_modalities: Option<Vec<serde_json::Value>>,
1967    /// Reference to a prompt template and its variables.
1968    #[serde(skip_serializing_if = "Option::is_none", default)]
1969    pub prompt: Option<serde_json::Value>,
1970    /// How the model chooses tools.
1971    #[serde(skip_serializing_if = "Option::is_none", default)]
1972    pub tool_choice: Option<ToolChoice>,
1973    /// Tools available to the model.
1974    #[serde(skip_serializing_if = "Option::is_none", default)]
1975    pub tools: Option<Vec<RealtimeMcpTool>>,
1976    /// Realtime API can write session traces to the
1977    #[serde(skip_serializing_if = "Option::is_none", default)]
1978    pub tracing: Option<Tracing>,
1979    /// When the number of tokens in a conversation exceeds the model's input token
1980    #[serde(skip_serializing_if = "Option::is_none", default)]
1981    pub truncation: Option<RealtimeTruncation>,
1982}
1983
1984pub type RealtimeToolChoiceConfig = serde_json::Value;
1985
1986pub type RealtimeToolsConfig = Vec<RealtimeToolsConfigUnion>;
1987
1988/// A filter object to specify which tools are allowed.
1989#[derive(Debug, Clone, Serialize, Deserialize)]
1990#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
1991pub struct McpAllowedToolsMcpToolFilter {
1992    /// Indicates whether or not a tool modifies data or is read-only.
1993    #[serde(skip_serializing_if = "Option::is_none", default)]
1994    pub read_only: Option<bool>,
1995    /// List of allowed tool names.
1996    #[serde(skip_serializing_if = "Option::is_none", default)]
1997    pub tool_names: Option<Vec<String>>,
1998}
1999
2000pub type McpAllowedTools = serde_json::Value;
2001
2002/// A filter object to specify which tools are allowed.
2003#[derive(Debug, Clone, Serialize, Deserialize)]
2004#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
2005pub struct McpRequireApprovalMcpToolApprovalFilterAlways {
2006    /// Indicates whether or not a tool modifies data or is read-only.
2007    #[serde(skip_serializing_if = "Option::is_none", default)]
2008    pub read_only: Option<bool>,
2009    /// List of allowed tool names.
2010    #[serde(skip_serializing_if = "Option::is_none", default)]
2011    pub tool_names: Option<Vec<String>>,
2012}
2013
2014/// A filter object to specify which tools are allowed.
2015#[derive(Debug, Clone, Serialize, Deserialize)]
2016#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
2017pub struct McpRequireApprovalMcpToolApprovalFilterNever {
2018    /// Indicates whether or not a tool modifies data or is read-only.
2019    #[serde(skip_serializing_if = "Option::is_none", default)]
2020    pub read_only: Option<bool>,
2021    /// List of allowed tool names.
2022    #[serde(skip_serializing_if = "Option::is_none", default)]
2023    pub tool_names: Option<Vec<String>>,
2024}
2025
2026/// Specify which of the MCP server's tools require approval.
2027#[derive(Debug, Clone, Serialize, Deserialize)]
2028#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
2029pub struct McpRequireApprovalMcpToolApprovalFilter {
2030    /// A filter object to specify which tools are allowed.
2031    #[serde(skip_serializing_if = "Option::is_none", default)]
2032    pub always: Option<McpRequireApprovalMcpToolApprovalFilterAlways>,
2033    /// A filter object to specify which tools are allowed.
2034    #[serde(skip_serializing_if = "Option::is_none", default)]
2035    pub never: Option<McpRequireApprovalMcpToolApprovalFilterNever>,
2036}
2037
2038#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
2039#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
2040#[non_exhaustive]
2041pub enum McpRequireApproval {
2042    Always,
2043    Never,
2044}
2045
2046#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
2047#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
2048#[non_exhaustive]
2049pub enum McpConnectorId {
2050    #[serde(rename = "connector_dropbox")]
2051    ConnectorDropbox,
2052    #[serde(rename = "connector_gmail")]
2053    ConnectorGmail,
2054    #[serde(rename = "connector_googlecalendar")]
2055    ConnectorGooglecalendar,
2056    #[serde(rename = "connector_googledrive")]
2057    ConnectorGoogledrive,
2058    #[serde(rename = "connector_microsoftteams")]
2059    ConnectorMicrosoftteams,
2060    #[serde(rename = "connector_outlookcalendar")]
2061    ConnectorOutlookcalendar,
2062    #[serde(rename = "connector_outlookemail")]
2063    ConnectorOutlookemail,
2064    #[serde(rename = "connector_sharepoint")]
2065    ConnectorSharepoint,
2066}
2067
2068/// Give the model access to additional tools via remote Model Context Protocol
2069#[derive(Debug, Clone, Serialize, Deserialize)]
2070#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
2071pub struct Mcp {
2072    /// A label for this MCP server, used to identify it in tool calls.
2073    pub server_label: String,
2074    /// The type of the MCP tool. Always `mcp`.
2075    #[serde(rename = "type")]
2076    pub type_: String,
2077    /// List of allowed tool names or a filter object.
2078    #[serde(skip_serializing_if = "Option::is_none", default)]
2079    pub allowed_tools: Option<McpAllowedTools>,
2080    /// An OAuth access token that can be used with a remote MCP server, either with a
2081    #[serde(skip_serializing_if = "Option::is_none", default)]
2082    pub authorization: Option<String>,
2083    /// Identifier for service connectors, like those available in ChatGPT.
2084    #[serde(skip_serializing_if = "Option::is_none", default)]
2085    pub connector_id: Option<McpConnectorId>,
2086    /// Whether this MCP tool is deferred and discovered via tool search.
2087    #[serde(skip_serializing_if = "Option::is_none", default)]
2088    pub defer_loading: Option<bool>,
2089    /// Optional HTTP headers to send to the MCP server.
2090    #[serde(skip_serializing_if = "Option::is_none", default)]
2091    pub headers: Option<std::collections::HashMap<String, String>>,
2092    /// Specify which of the MCP server's tools require approval.
2093    #[serde(skip_serializing_if = "Option::is_none", default)]
2094    pub require_approval: Option<McpRequireApproval>,
2095    /// Optional description of the MCP server, used to provide more context.
2096    #[serde(skip_serializing_if = "Option::is_none", default)]
2097    pub server_description: Option<String>,
2098    /// The URL for the MCP server.
2099    #[serde(skip_serializing_if = "Option::is_none", default)]
2100    pub server_url: Option<String>,
2101}
2102
2103pub type RealtimeToolsConfigUnion = serde_json::Value;
2104
2105/// Granular configuration for tracing.
2106#[derive(Debug, Clone, Serialize, Deserialize)]
2107#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
2108pub struct TracingConfiguration {
2109    /// The group id to attach to this trace to enable filtering and grouping in the
2110    #[serde(skip_serializing_if = "Option::is_none", default)]
2111    pub group_id: Option<String>,
2112    /// The arbitrary metadata to attach to this trace to enable filtering in the Traces
2113    #[serde(skip_serializing_if = "Option::is_none", default)]
2114    pub metadata: Option<serde_json::Value>,
2115    /// The name of the workflow to attach to this trace.
2116    #[serde(skip_serializing_if = "Option::is_none", default)]
2117    pub workflow_name: Option<String>,
2118}
2119
2120#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
2121#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
2122#[non_exhaustive]
2123pub enum RealtimeTracingConfig {
2124    Auto,
2125}
2126
2127/// Configuration for input and output audio.
2128#[derive(Debug, Clone, Serialize, Deserialize)]
2129#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
2130pub struct RealtimeTranscriptionSessionAudio {
2131    #[serde(skip_serializing_if = "Option::is_none", default)]
2132    pub input: Option<RealtimeTranscriptionSessionAudioInput>,
2133}
2134
2135#[derive(Debug, Clone, Serialize, Deserialize)]
2136#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
2137pub struct RealtimeTranscriptionSessionAudioInput {
2138    /// The PCM audio format. Only a 24kHz sample rate is supported.
2139    #[serde(skip_serializing_if = "Option::is_none", default)]
2140    pub format: Option<RealtimeAudioFormats>,
2141    /// Configuration for input audio noise reduction.
2142    #[serde(skip_serializing_if = "Option::is_none", default)]
2143    pub noise_reduction: Option<NoiseReduction>,
2144    /// Configuration for input audio transcription, defaults to off and can be set to
2145    #[serde(skip_serializing_if = "Option::is_none", default)]
2146    pub transcription: Option<AudioTranscription>,
2147    /// Configuration for turn detection, ether Server VAD or Semantic VAD.
2148    #[serde(skip_serializing_if = "Option::is_none", default)]
2149    pub turn_detection: Option<RealtimeTranscriptionSessionAudioInputTurnDetection>,
2150}
2151
2152pub type RealtimeTranscriptionSessionAudioInputTurnDetection = serde_json::Value;
2153
2154/// Realtime transcription session object configuration.
2155#[derive(Debug, Clone, Serialize, Deserialize)]
2156#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
2157pub struct RealtimeTranscriptionSessionCreateRequest {
2158    /// The type of session to create.
2159    #[serde(rename = "type")]
2160    pub type_: String,
2161    /// Configuration for input and output audio.
2162    #[serde(skip_serializing_if = "Option::is_none", default)]
2163    pub audio: Option<RealtimeTranscriptionSessionAudio>,
2164    /// Additional fields to include in server outputs.
2165    #[serde(skip_serializing_if = "Option::is_none", default)]
2166    pub include: Option<Vec<String>>,
2167}
2168
2169/// A Realtime transcription session configuration object.
2170#[derive(Debug, Clone, Serialize, Deserialize)]
2171#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
2172pub struct RealtimeTranscriptionSessionCreateResponse {
2173    /// Unique identifier for the session that looks like `sess_1234567890abcdef`.
2174    pub id: String,
2175    /// The object type. Always `realtime.transcription_session`.
2176    pub object: String,
2177    /// The type of session. Always `transcription` for transcription sessions.
2178    #[serde(rename = "type")]
2179    pub type_: String,
2180    /// Configuration for input audio for the session.
2181    #[serde(skip_serializing_if = "Option::is_none", default)]
2182    pub audio: Option<Audio>,
2183    /// Expiration timestamp for the session, in seconds since epoch.
2184    #[serde(skip_serializing_if = "Option::is_none", default)]
2185    pub expires_at: Option<i64>,
2186    /// Additional fields to include in server outputs.
2187    #[serde(skip_serializing_if = "Option::is_none", default)]
2188    pub include: Option<Vec<String>>,
2189}
2190
2191/// Configuration for turn detection.
2192#[derive(Debug, Clone, Serialize, Deserialize)]
2193#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
2194pub struct RealtimeTranscriptionSessionTurnDetection {
2195    /// Amount of audio to include before the VAD detected speech (in milliseconds).
2196    #[serde(skip_serializing_if = "Option::is_none", default)]
2197    pub prefix_padding_ms: Option<i64>,
2198    /// Duration of silence to detect speech stop (in milliseconds).
2199    #[serde(skip_serializing_if = "Option::is_none", default)]
2200    pub silence_duration_ms: Option<i64>,
2201    /// Activation threshold for VAD (0.0 to 1.0), this defaults to 0.5.
2202    #[serde(skip_serializing_if = "Option::is_none", default)]
2203    pub threshold: Option<f64>,
2204    /// Type of turn detection, only `server_vad` is currently supported.
2205    #[serde(rename = "type", skip_serializing_if = "Option::is_none", default)]
2206    pub type_: Option<String>,
2207}
2208
2209#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
2210#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
2211#[non_exhaustive]
2212pub enum RealtimeTruncation {
2213    Auto,
2214    Disabled,
2215}
2216
2217/// Optional custom token limits for this truncation strategy.
2218#[derive(Debug, Clone, Serialize, Deserialize)]
2219#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
2220pub struct TokenLimits {
2221    /// Maximum tokens allowed in the conversation after instructions (which including
2222    #[serde(skip_serializing_if = "Option::is_none", default)]
2223    pub post_instructions: Option<i64>,
2224}
2225
2226/// Retain a fraction of the conversation tokens when the conversation exceeds the input token limit. This allows you to amortize truncations across multiple turns, which can help improve cached token usage.
2227#[derive(Debug, Clone, Serialize, Deserialize)]
2228#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
2229pub struct RealtimeTruncationRetentionRatio {
2230    /// Fraction of post-instruction conversation tokens to retain (`0.0` - `1.0`) when
2231    pub retention_ratio: f64,
2232    /// Use retention ratio truncation.
2233    #[serde(rename = "type")]
2234    pub type_: String,
2235    /// Optional custom token limits for this truncation strategy.
2236    #[serde(skip_serializing_if = "Option::is_none", default)]
2237    pub token_limits: Option<TokenLimits>,
2238}
2239
2240/// Returned when the model-generated audio is updated.
2241#[derive(Debug, Clone, Serialize, Deserialize)]
2242#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
2243pub struct ResponseAudioDeltaEvent {
2244    /// The index of the content part in the item's content array.
2245    pub content_index: i64,
2246    /// Base64-encoded audio data delta.
2247    pub delta: String,
2248    /// The unique ID of the server event.
2249    pub event_id: String,
2250    /// The ID of the item.
2251    pub item_id: String,
2252    /// The index of the output item in the response.
2253    pub output_index: i64,
2254    /// The ID of the response.
2255    pub response_id: String,
2256    /// The event type, must be `response.output_audio.delta`.
2257    #[serde(rename = "type")]
2258    pub type_: String,
2259}
2260
2261/// Returned when the model-generated audio is done.
2262#[derive(Debug, Clone, Serialize, Deserialize)]
2263#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
2264pub struct ResponseAudioDoneEvent {
2265    /// The index of the content part in the item's content array.
2266    pub content_index: i64,
2267    /// The unique ID of the server event.
2268    pub event_id: String,
2269    /// The ID of the item.
2270    pub item_id: String,
2271    /// The index of the output item in the response.
2272    pub output_index: i64,
2273    /// The ID of the response.
2274    pub response_id: String,
2275    /// The event type, must be `response.output_audio.done`.
2276    #[serde(rename = "type")]
2277    pub type_: String,
2278}
2279
2280/// Returned when the model-generated transcription of audio output is updated.
2281#[derive(Debug, Clone, Serialize, Deserialize)]
2282#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
2283pub struct ResponseAudioTranscriptDeltaEvent {
2284    /// The index of the content part in the item's content array.
2285    pub content_index: i64,
2286    /// The transcript delta.
2287    pub delta: String,
2288    /// The unique ID of the server event.
2289    pub event_id: String,
2290    /// The ID of the item.
2291    pub item_id: String,
2292    /// The index of the output item in the response.
2293    pub output_index: i64,
2294    /// The ID of the response.
2295    pub response_id: String,
2296    /// The event type, must be `response.output_audio_transcript.delta`.
2297    #[serde(rename = "type")]
2298    pub type_: String,
2299}
2300
2301/// Returned when the model-generated transcription of audio output is done
2302#[derive(Debug, Clone, Serialize, Deserialize)]
2303#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
2304pub struct ResponseAudioTranscriptDoneEvent {
2305    /// The index of the content part in the item's content array.
2306    pub content_index: i64,
2307    /// The unique ID of the server event.
2308    pub event_id: String,
2309    /// The ID of the item.
2310    pub item_id: String,
2311    /// The index of the output item in the response.
2312    pub output_index: i64,
2313    /// The ID of the response.
2314    pub response_id: String,
2315    /// The final transcript of the audio.
2316    pub transcript: String,
2317    /// The event type, must be `response.output_audio_transcript.done`.
2318    #[serde(rename = "type")]
2319    pub type_: String,
2320}
2321
2322/// Send this event to cancel an in-progress response.
2323#[derive(Debug, Clone, Serialize, Deserialize)]
2324#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
2325pub struct ResponseCancelEvent {
2326    /// The event type, must be `response.cancel`.
2327    #[serde(rename = "type")]
2328    pub type_: String,
2329    /// Optional client-generated ID used to identify this event.
2330    #[serde(skip_serializing_if = "Option::is_none", default)]
2331    pub event_id: Option<String>,
2332    /// A specific response ID to cancel - if not provided, will cancel an in-progress
2333    #[serde(skip_serializing_if = "Option::is_none", default)]
2334    pub response_id: Option<String>,
2335}
2336
2337#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
2338#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
2339#[non_exhaustive]
2340pub enum ContentPartPartType {
2341    #[serde(rename = "text")]
2342    Text,
2343    #[serde(rename = "audio")]
2344    Audio,
2345}
2346
2347/// The content part that was added.
2348#[derive(Debug, Clone, Serialize, Deserialize)]
2349#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
2350pub struct ContentPartPart {
2351    /// Base64-encoded audio data (if type is "audio").
2352    #[serde(skip_serializing_if = "Option::is_none", default)]
2353    pub audio: Option<String>,
2354    /// The text content (if type is "text").
2355    #[serde(skip_serializing_if = "Option::is_none", default)]
2356    pub text: Option<String>,
2357    /// The transcript of the audio (if type is "audio").
2358    #[serde(skip_serializing_if = "Option::is_none", default)]
2359    pub transcript: Option<String>,
2360    /// The content type ("text", "audio").
2361    #[serde(rename = "type", skip_serializing_if = "Option::is_none", default)]
2362    pub type_: Option<ContentPartPartType>,
2363}
2364
2365/// Returned when a new content part is added to an assistant message item during
2366#[derive(Debug, Clone, Serialize, Deserialize)]
2367#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
2368pub struct ResponseContentPartAddedEvent {
2369    /// The index of the content part in the item's content array.
2370    pub content_index: i64,
2371    /// The unique ID of the server event.
2372    pub event_id: String,
2373    /// The ID of the item to which the content part was added.
2374    pub item_id: String,
2375    /// The index of the output item in the response.
2376    pub output_index: i64,
2377    /// The content part that was added.
2378    pub part: ContentPartPart,
2379    /// The ID of the response.
2380    pub response_id: String,
2381    /// The event type, must be `response.content_part.added`.
2382    #[serde(rename = "type")]
2383    pub type_: String,
2384}
2385
2386/// Returned when a content part is done streaming in an assistant message item.
2387#[derive(Debug, Clone, Serialize, Deserialize)]
2388#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
2389pub struct ResponseContentPartDoneEvent {
2390    /// The index of the content part in the item's content array.
2391    pub content_index: i64,
2392    /// The unique ID of the server event.
2393    pub event_id: String,
2394    /// The ID of the item.
2395    pub item_id: String,
2396    /// The index of the output item in the response.
2397    pub output_index: i64,
2398    /// The content part that is done.
2399    pub part: ContentPartPart,
2400    /// The ID of the response.
2401    pub response_id: String,
2402    /// The event type, must be `response.content_part.done`.
2403    #[serde(rename = "type")]
2404    pub type_: String,
2405}
2406
2407/// This event instructs the server to create a Response, which means triggering
2408#[derive(Debug, Clone, Serialize, Deserialize)]
2409#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
2410pub struct ResponseCreateEvent {
2411    /// The event type, must be `response.create`.
2412    #[serde(rename = "type")]
2413    pub type_: String,
2414    /// Optional client-generated ID used to identify this event.
2415    #[serde(skip_serializing_if = "Option::is_none", default)]
2416    pub event_id: Option<String>,
2417    /// Create a new Realtime response with these parameters
2418    #[serde(skip_serializing_if = "Option::is_none", default)]
2419    pub response: Option<RealtimeResponseCreateParams>,
2420}
2421
2422/// Returned when a new Response is created.
2423#[derive(Debug, Clone, Serialize, Deserialize)]
2424#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
2425pub struct ResponseCreatedEvent {
2426    /// The unique ID of the server event.
2427    pub event_id: String,
2428    /// The response resource.
2429    pub response: RealtimeResponse,
2430    /// The event type, must be `response.created`.
2431    #[serde(rename = "type")]
2432    pub type_: String,
2433}
2434
2435/// Returned when a Response is done streaming.
2436#[derive(Debug, Clone, Serialize, Deserialize)]
2437#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
2438pub struct ResponseDoneEvent {
2439    /// The unique ID of the server event.
2440    pub event_id: String,
2441    /// The response resource.
2442    pub response: RealtimeResponse,
2443    /// The event type, must be `response.done`.
2444    #[serde(rename = "type")]
2445    pub type_: String,
2446}
2447
2448/// Returned when the model-generated function call arguments are updated.
2449#[derive(Debug, Clone, Serialize, Deserialize)]
2450#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
2451pub struct ResponseFunctionCallArgumentsDeltaEvent {
2452    /// The ID of the function call.
2453    pub call_id: String,
2454    /// The arguments delta as a JSON string.
2455    pub delta: String,
2456    /// The unique ID of the server event.
2457    pub event_id: String,
2458    /// The ID of the function call item.
2459    pub item_id: String,
2460    /// The index of the output item in the response.
2461    pub output_index: i64,
2462    /// The ID of the response.
2463    pub response_id: String,
2464    /// The event type, must be `response.function_call_arguments.delta`.
2465    #[serde(rename = "type")]
2466    pub type_: String,
2467}
2468
2469/// Returned when the model-generated function call arguments are done streaming.
2470#[derive(Debug, Clone, Serialize, Deserialize)]
2471#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
2472pub struct ResponseFunctionCallArgumentsDoneEvent {
2473    /// The final arguments as a JSON string.
2474    pub arguments: String,
2475    /// The ID of the function call.
2476    pub call_id: String,
2477    /// The unique ID of the server event.
2478    pub event_id: String,
2479    /// The ID of the function call item.
2480    pub item_id: String,
2481    /// The name of the function that was called.
2482    pub name: String,
2483    /// The index of the output item in the response.
2484    pub output_index: i64,
2485    /// The ID of the response.
2486    pub response_id: String,
2487    /// The event type, must be `response.function_call_arguments.done`.
2488    #[serde(rename = "type")]
2489    pub type_: String,
2490}
2491
2492/// Returned when MCP tool call arguments are updated during response generation.
2493#[derive(Debug, Clone, Serialize, Deserialize)]
2494#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
2495pub struct ResponseMcpCallArgumentsDelta {
2496    /// The JSON-encoded arguments delta.
2497    pub delta: String,
2498    /// The unique ID of the server event.
2499    pub event_id: String,
2500    /// The ID of the MCP tool call item.
2501    pub item_id: String,
2502    /// The index of the output item in the response.
2503    pub output_index: i64,
2504    /// The ID of the response.
2505    pub response_id: String,
2506    /// The event type, must be `response.mcp_call_arguments.delta`.
2507    #[serde(rename = "type")]
2508    pub type_: String,
2509    /// If present, indicates the delta text was obfuscated.
2510    #[serde(skip_serializing_if = "Option::is_none", default)]
2511    pub obfuscation: Option<String>,
2512}
2513
2514/// Returned when MCP tool call arguments are finalized during response generation.
2515#[derive(Debug, Clone, Serialize, Deserialize)]
2516#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
2517pub struct ResponseMcpCallArgumentsDone {
2518    /// The final JSON-encoded arguments string.
2519    pub arguments: String,
2520    /// The unique ID of the server event.
2521    pub event_id: String,
2522    /// The ID of the MCP tool call item.
2523    pub item_id: String,
2524    /// The index of the output item in the response.
2525    pub output_index: i64,
2526    /// The ID of the response.
2527    pub response_id: String,
2528    /// The event type, must be `response.mcp_call_arguments.done`.
2529    #[serde(rename = "type")]
2530    pub type_: String,
2531}
2532
2533/// Returned when an MCP tool call has completed successfully.
2534#[derive(Debug, Clone, Serialize, Deserialize)]
2535#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
2536pub struct ResponseMcpCallCompleted {
2537    /// The unique ID of the server event.
2538    pub event_id: String,
2539    /// The ID of the MCP tool call item.
2540    pub item_id: String,
2541    /// The index of the output item in the response.
2542    pub output_index: i64,
2543    /// The event type, must be `response.mcp_call.completed`.
2544    #[serde(rename = "type")]
2545    pub type_: String,
2546}
2547
2548/// Returned when an MCP tool call has failed.
2549#[derive(Debug, Clone, Serialize, Deserialize)]
2550#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
2551pub struct ResponseMcpCallFailed {
2552    /// The unique ID of the server event.
2553    pub event_id: String,
2554    /// The ID of the MCP tool call item.
2555    pub item_id: String,
2556    /// The index of the output item in the response.
2557    pub output_index: i64,
2558    /// The event type, must be `response.mcp_call.failed`.
2559    #[serde(rename = "type")]
2560    pub type_: String,
2561}
2562
2563/// Returned when an MCP tool call has started and is in progress.
2564#[derive(Debug, Clone, Serialize, Deserialize)]
2565#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
2566pub struct ResponseMcpCallInProgress {
2567    /// The unique ID of the server event.
2568    pub event_id: String,
2569    /// The ID of the MCP tool call item.
2570    pub item_id: String,
2571    /// The index of the output item in the response.
2572    pub output_index: i64,
2573    /// The event type, must be `response.mcp_call.in_progress`.
2574    #[serde(rename = "type")]
2575    pub type_: String,
2576}
2577
2578/// Returned when a new Item is created during Response generation.
2579#[derive(Debug, Clone, Serialize, Deserialize)]
2580#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
2581pub struct ResponseOutputItemAddedEvent {
2582    /// The unique ID of the server event.
2583    pub event_id: String,
2584    /// A single item within a Realtime conversation.
2585    pub item: ConversationItem,
2586    /// The index of the output item in the Response.
2587    pub output_index: i64,
2588    /// The ID of the Response to which the item belongs.
2589    pub response_id: String,
2590    /// The event type, must be `response.output_item.added`.
2591    #[serde(rename = "type")]
2592    pub type_: String,
2593}
2594
2595/// Returned when an Item is done streaming.
2596#[derive(Debug, Clone, Serialize, Deserialize)]
2597#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
2598pub struct ResponseOutputItemDoneEvent {
2599    /// The unique ID of the server event.
2600    pub event_id: String,
2601    /// A single item within a Realtime conversation.
2602    pub item: ConversationItem,
2603    /// The index of the output item in the Response.
2604    pub output_index: i64,
2605    /// The ID of the Response to which the item belongs.
2606    pub response_id: String,
2607    /// The event type, must be `response.output_item.done`.
2608    #[serde(rename = "type")]
2609    pub type_: String,
2610}
2611
2612/// Returned when the text value of an "output_text" content part is updated.
2613#[derive(Debug, Clone, Serialize, Deserialize)]
2614#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
2615pub struct ResponseTextDeltaEvent {
2616    /// The index of the content part in the item's content array.
2617    pub content_index: i64,
2618    /// The text delta.
2619    pub delta: String,
2620    /// The unique ID of the server event.
2621    pub event_id: String,
2622    /// The ID of the item.
2623    pub item_id: String,
2624    /// The index of the output item in the response.
2625    pub output_index: i64,
2626    /// The ID of the response.
2627    pub response_id: String,
2628    /// The event type, must be `response.output_text.delta`.
2629    #[serde(rename = "type")]
2630    pub type_: String,
2631}
2632
2633/// Returned when the text value of an "output_text" content part is done streaming.
2634#[derive(Debug, Clone, Serialize, Deserialize)]
2635#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
2636pub struct ResponseTextDoneEvent {
2637    /// The index of the content part in the item's content array.
2638    pub content_index: i64,
2639    /// The unique ID of the server event.
2640    pub event_id: String,
2641    /// The ID of the item.
2642    pub item_id: String,
2643    /// The index of the output item in the response.
2644    pub output_index: i64,
2645    /// The ID of the response.
2646    pub response_id: String,
2647    /// The final text content.
2648    pub text: String,
2649    /// The event type, must be `response.output_text.done`.
2650    #[serde(rename = "type")]
2651    pub type_: String,
2652}
2653
2654/// Returned when a Session is created.
2655#[derive(Debug, Clone, Serialize, Deserialize)]
2656#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
2657pub struct SessionCreatedEvent {
2658    /// The unique ID of the server event.
2659    pub event_id: String,
2660    /// The session configuration.
2661    pub session: Session,
2662    /// The event type, must be `session.created`.
2663    #[serde(rename = "type")]
2664    pub type_: String,
2665}
2666
2667/// Send this event to update the session’s configuration.
2668#[derive(Debug, Clone, Serialize, Deserialize)]
2669#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
2670pub struct SessionUpdateEvent {
2671    /// Update the Realtime session.
2672    pub session: Session,
2673    /// The event type, must be `session.update`.
2674    #[serde(rename = "type")]
2675    pub type_: String,
2676    /// Optional client-generated ID used to identify this event.
2677    #[serde(skip_serializing_if = "Option::is_none", default)]
2678    pub event_id: Option<String>,
2679}
2680
2681/// Returned when a session is updated with a `session.update` event, unless
2682#[derive(Debug, Clone, Serialize, Deserialize)]
2683#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
2684pub struct SessionUpdatedEvent {
2685    /// The unique ID of the server event.
2686    pub event_id: String,
2687    /// The session configuration.
2688    pub session: Session,
2689    /// The event type, must be `session.updated`.
2690    #[serde(rename = "type")]
2691    pub type_: String,
2692}