openai 4.77.3 → 4.78.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/README.md +1 -1
  3. package/package.json +1 -1
  4. package/resources/beta/beta.d.ts +4 -0
  5. package/resources/beta/beta.d.ts.map +1 -1
  6. package/resources/beta/beta.js +4 -0
  7. package/resources/beta/beta.js.map +1 -1
  8. package/resources/beta/beta.mjs +4 -0
  9. package/resources/beta/beta.mjs.map +1 -1
  10. package/resources/beta/index.d.ts +1 -0
  11. package/resources/beta/index.d.ts.map +1 -1
  12. package/resources/beta/index.js +10 -8
  13. package/resources/beta/index.js.map +1 -1
  14. package/resources/beta/index.mjs +1 -0
  15. package/resources/beta/index.mjs.map +1 -1
  16. package/resources/beta/realtime/index.d.ts +3 -0
  17. package/resources/beta/realtime/index.d.ts.map +1 -0
  18. package/resources/beta/realtime/index.js +9 -0
  19. package/resources/beta/realtime/index.js.map +1 -0
  20. package/resources/beta/realtime/index.mjs +4 -0
  21. package/resources/beta/realtime/index.mjs.map +1 -0
  22. package/resources/beta/realtime/realtime.d.ts +1584 -0
  23. package/resources/beta/realtime/realtime.d.ts.map +1 -0
  24. package/resources/beta/realtime/realtime.js +39 -0
  25. package/resources/beta/realtime/realtime.js.map +1 -0
  26. package/resources/beta/realtime/realtime.mjs +12 -0
  27. package/resources/beta/realtime/realtime.mjs.map +1 -0
  28. package/resources/beta/realtime/sessions.d.ts +455 -0
  29. package/resources/beta/realtime/sessions.d.ts.map +1 -0
  30. package/resources/beta/realtime/sessions.js +25 -0
  31. package/resources/beta/realtime/sessions.js.map +1 -0
  32. package/resources/beta/realtime/sessions.mjs +21 -0
  33. package/resources/beta/realtime/sessions.mjs.map +1 -0
  34. package/src/resources/beta/beta.ts +6 -0
  35. package/src/resources/beta/index.ts +1 -0
  36. package/src/resources/beta/realtime/index.ts +4 -0
  37. package/src/resources/beta/realtime/realtime.ts +1904 -0
  38. package/src/resources/beta/realtime/sessions.ts +546 -0
  39. package/src/version.ts +1 -1
  40. package/version.d.ts +1 -1
  41. package/version.js +1 -1
  42. package/version.mjs +1 -1
@@ -0,0 +1,1904 @@
1
+ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
+
3
+ import { APIResource } from '../../../resource';
4
+ import * as RealtimeAPI from './realtime';
5
+ import * as SessionsAPI from './sessions';
6
+ import {
7
+ Session as SessionsAPISession,
8
+ SessionCreateParams,
9
+ SessionCreateResponse,
10
+ Sessions,
11
+ } from './sessions';
12
+
13
+ export class Realtime extends APIResource {
14
+ sessions: SessionsAPI.Sessions = new SessionsAPI.Sessions(this._client);
15
+ }
16
+
17
+ /**
18
+ * Returned when a conversation is created. Emitted right after session creation.
19
+ */
20
+ export interface ConversationCreatedEvent {
21
+ /**
22
+ * The conversation resource.
23
+ */
24
+ conversation: ConversationCreatedEvent.Conversation;
25
+
26
+ /**
27
+ * The unique ID of the server event.
28
+ */
29
+ event_id: string;
30
+
31
+ /**
32
+ * The event type, must be `conversation.created`.
33
+ */
34
+ type: 'conversation.created';
35
+ }
36
+
37
+ export namespace ConversationCreatedEvent {
38
+ /**
39
+ * The conversation resource.
40
+ */
41
+ export interface Conversation {
42
+ /**
43
+ * The unique ID of the conversation.
44
+ */
45
+ id?: string;
46
+
47
+ /**
48
+ * The object type, must be `realtime.conversation`.
49
+ */
50
+ object?: 'realtime.conversation';
51
+ }
52
+ }
53
+
54
+ /**
55
+ * The item to add to the conversation.
56
+ */
57
+ export interface ConversationItem {
58
+ /**
59
+ * The unique ID of the item, this can be generated by the client to help manage
60
+ * server-side context, but is not required because the server will generate one if
61
+ * not provided.
62
+ */
63
+ id?: string;
64
+
65
+ /**
66
+ * The arguments of the function call (for `function_call` items).
67
+ */
68
+ arguments?: string;
69
+
70
+ /**
71
+ * The ID of the function call (for `function_call` and `function_call_output`
72
+ * items). If passed on a `function_call_output` item, the server will check that a
73
+ * `function_call` item with the same ID exists in the conversation history.
74
+ */
75
+ call_id?: string;
76
+
77
+ /**
78
+ * The content of the message, applicable for `message` items.
79
+ *
80
+ * - Message items of role `system` support only `input_text` content
81
+ * - Message items of role `user` support `input_text` and `input_audio` content
82
+ * - Message items of role `assistant` support `text` content.
83
+ */
84
+ content?: Array<ConversationItemContent>;
85
+
86
+ /**
87
+ * The name of the function being called (for `function_call` items).
88
+ */
89
+ name?: string;
90
+
91
+ /**
92
+ * Identifier for the API object being returned - always `realtime.item`.
93
+ */
94
+ object?: 'realtime.item';
95
+
96
+ /**
97
+ * The output of the function call (for `function_call_output` items).
98
+ */
99
+ output?: string;
100
+
101
+ /**
102
+ * The role of the message sender (`user`, `assistant`, `system`), only applicable
103
+ * for `message` items.
104
+ */
105
+ role?: 'user' | 'assistant' | 'system';
106
+
107
+ /**
108
+ * The status of the item (`completed`, `incomplete`). These have no effect on the
109
+ * conversation, but are accepted for consistency with the
110
+ * `conversation.item.created` event.
111
+ */
112
+ status?: 'completed' | 'incomplete';
113
+
114
+ /**
115
+ * The type of the item (`message`, `function_call`, `function_call_output`).
116
+ */
117
+ type?: 'message' | 'function_call' | 'function_call_output';
118
+ }
119
+
120
+ export interface ConversationItemContent {
121
+ /**
122
+ * ID of a previous conversation item to reference (for `item_reference` content
123
+ * types in `response.create` events). These can reference both client and server
124
+ * created items.
125
+ */
126
+ id?: string;
127
+
128
+ /**
129
+ * Base64-encoded audio bytes, used for `input_audio` content type.
130
+ */
131
+ audio?: string;
132
+
133
+ /**
134
+ * The text content, used for `input_text` and `text` content types.
135
+ */
136
+ text?: string;
137
+
138
+ /**
139
+ * The transcript of the audio, used for `input_audio` content type.
140
+ */
141
+ transcript?: string;
142
+
143
+ /**
144
+ * The content type (`input_text`, `input_audio`, `item_reference`, `text`).
145
+ */
146
+ type?: 'input_text' | 'input_audio' | 'item_reference' | 'text';
147
+ }
148
+
149
+ /**
150
+ * Add a new Item to the Conversation's context, including messages, function
151
+ * calls, and function call responses. This event can be used both to populate a
152
+ * "history" of the conversation and to add new items mid-stream, but has the
153
+ * current limitation that it cannot populate assistant audio messages.
154
+ *
155
+ * If successful, the server will respond with a `conversation.item.created` event,
156
+ * otherwise an `error` event will be sent.
157
+ */
158
+ export interface ConversationItemCreateEvent {
159
+ /**
160
+ * The item to add to the conversation.
161
+ */
162
+ item: ConversationItem;
163
+
164
+ /**
165
+ * The event type, must be `conversation.item.create`.
166
+ */
167
+ type: 'conversation.item.create';
168
+
169
+ /**
170
+ * Optional client-generated ID used to identify this event.
171
+ */
172
+ event_id?: string;
173
+
174
+ /**
175
+ * The ID of the preceding item after which the new item will be inserted. If not
176
+ * set, the new item will be appended to the end of the conversation. If set, it
177
+ * allows an item to be inserted mid-conversation. If the ID cannot be found, an
178
+ * error will be returned and the item will not be added.
179
+ */
180
+ previous_item_id?: string;
181
+ }
182
+
183
+ /**
184
+ * Returned when a conversation item is created. There are several scenarios that
185
+ * produce this event:
186
+ *
187
+ * - The server is generating a Response, which if successful will produce either
188
+ * one or two Items, which will be of type `message` (role `assistant`) or type
189
+ * `function_call`.
190
+ * - The input audio buffer has been committed, either by the client or the server
191
+ * (in `server_vad` mode). The server will take the content of the input audio
192
+ * buffer and add it to a new user message Item.
193
+ * - The client has sent a `conversation.item.create` event to add a new Item to
194
+ * the Conversation.
195
+ */
196
+ export interface ConversationItemCreatedEvent {
197
+ /**
198
+ * The unique ID of the server event.
199
+ */
200
+ event_id: string;
201
+
202
+ /**
203
+ * The item to add to the conversation.
204
+ */
205
+ item: ConversationItem;
206
+
207
+ /**
208
+ * The ID of the preceding item in the Conversation context, allows the client to
209
+ * understand the order of the conversation.
210
+ */
211
+ previous_item_id: string;
212
+
213
+ /**
214
+ * The event type, must be `conversation.item.created`.
215
+ */
216
+ type: 'conversation.item.created';
217
+ }
218
+
219
+ /**
220
+ * Send this event when you want to remove any item from the conversation history.
221
+ * The server will respond with a `conversation.item.deleted` event, unless the
222
+ * item does not exist in the conversation history, in which case the server will
223
+ * respond with an error.
224
+ */
225
+ export interface ConversationItemDeleteEvent {
226
+ /**
227
+ * The ID of the item to delete.
228
+ */
229
+ item_id: string;
230
+
231
+ /**
232
+ * The event type, must be `conversation.item.delete`.
233
+ */
234
+ type: 'conversation.item.delete';
235
+
236
+ /**
237
+ * Optional client-generated ID used to identify this event.
238
+ */
239
+ event_id?: string;
240
+ }
241
+
242
+ /**
243
+ * Returned when an item in the conversation is deleted by the client with a
244
+ * `conversation.item.delete` event. This event is used to synchronize the server's
245
+ * understanding of the conversation history with the client's view.
246
+ */
247
+ export interface ConversationItemDeletedEvent {
248
+ /**
249
+ * The unique ID of the server event.
250
+ */
251
+ event_id: string;
252
+
253
+ /**
254
+ * The ID of the item that was deleted.
255
+ */
256
+ item_id: string;
257
+
258
+ /**
259
+ * The event type, must be `conversation.item.deleted`.
260
+ */
261
+ type: 'conversation.item.deleted';
262
+ }
263
+
264
+ /**
265
+ * This event is the output of audio transcription for user audio written to the
266
+ * user audio buffer. Transcription begins when the input audio buffer is committed
267
+ * by the client or server (in `server_vad` mode). Transcription runs
268
+ * asynchronously with Response creation, so this event may come before or after
269
+ * the Response events.
270
+ *
271
+ * Realtime API models accept audio natively, and thus input transcription is a
272
+ * separate process run on a separate ASR (Automatic Speech Recognition) model,
273
+ * currently always `whisper-1`. Thus the transcript may diverge somewhat from the
274
+ * model's interpretation, and should be treated as a rough guide.
275
+ */
276
+ export interface ConversationItemInputAudioTranscriptionCompletedEvent {
277
+ /**
278
+ * The index of the content part containing the audio.
279
+ */
280
+ content_index: number;
281
+
282
+ /**
283
+ * The unique ID of the server event.
284
+ */
285
+ event_id: string;
286
+
287
+ /**
288
+ * The ID of the user message item containing the audio.
289
+ */
290
+ item_id: string;
291
+
292
+ /**
293
+ * The transcribed text.
294
+ */
295
+ transcript: string;
296
+
297
+ /**
298
+ * The event type, must be `conversation.item.input_audio_transcription.completed`.
299
+ */
300
+ type: 'conversation.item.input_audio_transcription.completed';
301
+ }
302
+
303
+ /**
304
+ * Returned when input audio transcription is configured, and a transcription
305
+ * request for a user message failed. These events are separate from other `error`
306
+ * events so that the client can identify the related Item.
307
+ */
308
+ export interface ConversationItemInputAudioTranscriptionFailedEvent {
309
+ /**
310
+ * The index of the content part containing the audio.
311
+ */
312
+ content_index: number;
313
+
314
+ /**
315
+ * Details of the transcription error.
316
+ */
317
+ error: ConversationItemInputAudioTranscriptionFailedEvent.Error;
318
+
319
+ /**
320
+ * The unique ID of the server event.
321
+ */
322
+ event_id: string;
323
+
324
+ /**
325
+ * The ID of the user message item.
326
+ */
327
+ item_id: string;
328
+
329
+ /**
330
+ * The event type, must be `conversation.item.input_audio_transcription.failed`.
331
+ */
332
+ type: 'conversation.item.input_audio_transcription.failed';
333
+ }
334
+
335
+ export namespace ConversationItemInputAudioTranscriptionFailedEvent {
336
+ /**
337
+ * Details of the transcription error.
338
+ */
339
+ export interface Error {
340
+ /**
341
+ * Error code, if any.
342
+ */
343
+ code?: string;
344
+
345
+ /**
346
+ * A human-readable error message.
347
+ */
348
+ message?: string;
349
+
350
+ /**
351
+ * Parameter related to the error, if any.
352
+ */
353
+ param?: string;
354
+
355
+ /**
356
+ * The type of error.
357
+ */
358
+ type?: string;
359
+ }
360
+ }
361
+
362
+ /**
363
+ * Send this event to truncate a previous assistant message’s audio. The server
364
+ * will produce audio faster than realtime, so this event is useful when the user
365
+ * interrupts to truncate audio that has already been sent to the client but not
366
+ * yet played. This will synchronize the server's understanding of the audio with
367
+ * the client's playback.
368
+ *
369
+ * Truncating audio will delete the server-side text transcript to ensure there is
370
+ * not text in the context that hasn't been heard by the user.
371
+ *
372
+ * If successful, the server will respond with a `conversation.item.truncated`
373
+ * event.
374
+ */
375
+ export interface ConversationItemTruncateEvent {
376
+ /**
377
+ * Inclusive duration up to which audio is truncated, in milliseconds. If the
378
+ * audio_end_ms is greater than the actual audio duration, the server will respond
379
+ * with an error.
380
+ */
381
+ audio_end_ms: number;
382
+
383
+ /**
384
+ * The index of the content part to truncate. Set this to 0.
385
+ */
386
+ content_index: number;
387
+
388
+ /**
389
+ * The ID of the assistant message item to truncate. Only assistant message items
390
+ * can be truncated.
391
+ */
392
+ item_id: string;
393
+
394
+ /**
395
+ * The event type, must be `conversation.item.truncate`.
396
+ */
397
+ type: 'conversation.item.truncate';
398
+
399
+ /**
400
+ * Optional client-generated ID used to identify this event.
401
+ */
402
+ event_id?: string;
403
+ }
404
+
405
+ /**
406
+ * Returned when an earlier assistant audio message item is truncated by the client
407
+ * with a `conversation.item.truncate` event. This event is used to synchronize the
408
+ * server's understanding of the audio with the client's playback.
409
+ *
410
+ * This action will truncate the audio and remove the server-side text transcript
411
+ * to ensure there is no text in the context that hasn't been heard by the user.
412
+ */
413
+ export interface ConversationItemTruncatedEvent {
414
+ /**
415
+ * The duration up to which the audio was truncated, in milliseconds.
416
+ */
417
+ audio_end_ms: number;
418
+
419
+ /**
420
+ * The index of the content part that was truncated.
421
+ */
422
+ content_index: number;
423
+
424
+ /**
425
+ * The unique ID of the server event.
426
+ */
427
+ event_id: string;
428
+
429
+ /**
430
+ * The ID of the assistant message item that was truncated.
431
+ */
432
+ item_id: string;
433
+
434
+ /**
435
+ * The event type, must be `conversation.item.truncated`.
436
+ */
437
+ type: 'conversation.item.truncated';
438
+ }
439
+
440
+ /**
441
+ * Returned when an error occurs, which could be a client problem or a server
442
+ * problem. Most errors are recoverable and the session will stay open, we
443
+ * recommend to implementors to monitor and log error messages by default.
444
+ */
445
+ export interface ErrorEvent {
446
+ /**
447
+ * Details of the error.
448
+ */
449
+ error: ErrorEvent.Error;
450
+
451
+ /**
452
+ * The unique ID of the server event.
453
+ */
454
+ event_id: string;
455
+
456
+ /**
457
+ * The event type, must be `error`.
458
+ */
459
+ type: 'error';
460
+ }
461
+
462
+ export namespace ErrorEvent {
463
+ /**
464
+ * Details of the error.
465
+ */
466
+ export interface Error {
467
+ /**
468
+ * A human-readable error message.
469
+ */
470
+ message: string;
471
+
472
+ /**
473
+ * The type of error (e.g., "invalid_request_error", "server_error").
474
+ */
475
+ type: string;
476
+
477
+ /**
478
+ * Error code, if any.
479
+ */
480
+ code?: string | null;
481
+
482
+ /**
483
+ * The event_id of the client event that caused the error, if applicable.
484
+ */
485
+ event_id?: string | null;
486
+
487
+ /**
488
+ * Parameter related to the error, if any.
489
+ */
490
+ param?: string | null;
491
+ }
492
+ }
493
+
494
+ /**
495
+ * Send this event to append audio bytes to the input audio buffer. The audio
496
+ * buffer is temporary storage you can write to and later commit. In Server VAD
497
+ * mode, the audio buffer is used to detect speech and the server will decide when
498
+ * to commit. When Server VAD is disabled, you must commit the audio buffer
499
+ * manually.
500
+ *
501
+ * The client may choose how much audio to place in each event up to a maximum of
502
+ * 15 MiB, for example streaming smaller chunks from the client may allow the VAD
503
+ * to be more responsive. Unlike made other client events, the server will not send
504
+ * a confirmation response to this event.
505
+ */
506
+ export interface InputAudioBufferAppendEvent {
507
+ /**
508
+ * Base64-encoded audio bytes. This must be in the format specified by the
509
+ * `input_audio_format` field in the session configuration.
510
+ */
511
+ audio: string;
512
+
513
+ /**
514
+ * The event type, must be `input_audio_buffer.append`.
515
+ */
516
+ type: 'input_audio_buffer.append';
517
+
518
+ /**
519
+ * Optional client-generated ID used to identify this event.
520
+ */
521
+ event_id?: string;
522
+ }
523
+
524
+ /**
525
+ * Send this event to clear the audio bytes in the buffer. The server will respond
526
+ * with an `input_audio_buffer.cleared` event.
527
+ */
528
+ export interface InputAudioBufferClearEvent {
529
+ /**
530
+ * The event type, must be `input_audio_buffer.clear`.
531
+ */
532
+ type: 'input_audio_buffer.clear';
533
+
534
+ /**
535
+ * Optional client-generated ID used to identify this event.
536
+ */
537
+ event_id?: string;
538
+ }
539
+
540
+ /**
541
+ * Returned when the input audio buffer is cleared by the client with a
542
+ * `input_audio_buffer.clear` event.
543
+ */
544
+ export interface InputAudioBufferClearedEvent {
545
+ /**
546
+ * The unique ID of the server event.
547
+ */
548
+ event_id: string;
549
+
550
+ /**
551
+ * The event type, must be `input_audio_buffer.cleared`.
552
+ */
553
+ type: 'input_audio_buffer.cleared';
554
+ }
555
+
556
+ /**
557
+ * Send this event to commit the user input audio buffer, which will create a new
558
+ * user message item in the conversation. This event will produce an error if the
559
+ * input audio buffer is empty. When in Server VAD mode, the client does not need
560
+ * to send this event, the server will commit the audio buffer automatically.
561
+ *
562
+ * Committing the input audio buffer will trigger input audio transcription (if
563
+ * enabled in session configuration), but it will not create a response from the
564
+ * model. The server will respond with an `input_audio_buffer.committed` event.
565
+ */
566
+ export interface InputAudioBufferCommitEvent {
567
+ /**
568
+ * The event type, must be `input_audio_buffer.commit`.
569
+ */
570
+ type: 'input_audio_buffer.commit';
571
+
572
+ /**
573
+ * Optional client-generated ID used to identify this event.
574
+ */
575
+ event_id?: string;
576
+ }
577
+
578
+ /**
579
+ * Returned when an input audio buffer is committed, either by the client or
580
+ * automatically in server VAD mode. The `item_id` property is the ID of the user
581
+ * message item that will be created, thus a `conversation.item.created` event will
582
+ * also be sent to the client.
583
+ */
584
+ export interface InputAudioBufferCommittedEvent {
585
+ /**
586
+ * The unique ID of the server event.
587
+ */
588
+ event_id: string;
589
+
590
+ /**
591
+ * The ID of the user message item that will be created.
592
+ */
593
+ item_id: string;
594
+
595
+ /**
596
+ * The ID of the preceding item after which the new item will be inserted.
597
+ */
598
+ previous_item_id: string;
599
+
600
+ /**
601
+ * The event type, must be `input_audio_buffer.committed`.
602
+ */
603
+ type: 'input_audio_buffer.committed';
604
+ }
605
+
606
+ /**
607
+ * Sent by the server when in `server_vad` mode to indicate that speech has been
608
+ * detected in the audio buffer. This can happen any time audio is added to the
609
+ * buffer (unless speech is already detected). The client may want to use this
610
+ * event to interrupt audio playback or provide visual feedback to the user.
611
+ *
612
+ * The client should expect to receive a `input_audio_buffer.speech_stopped` event
613
+ * when speech stops. The `item_id` property is the ID of the user message item
614
+ * that will be created when speech stops and will also be included in the
615
+ * `input_audio_buffer.speech_stopped` event (unless the client manually commits
616
+ * the audio buffer during VAD activation).
617
+ */
618
+ export interface InputAudioBufferSpeechStartedEvent {
619
+ /**
620
+ * Milliseconds from the start of all audio written to the buffer during the
621
+ * session when speech was first detected. This will correspond to the beginning of
622
+ * audio sent to the model, and thus includes the `prefix_padding_ms` configured in
623
+ * the Session.
624
+ */
625
+ audio_start_ms: number;
626
+
627
+ /**
628
+ * The unique ID of the server event.
629
+ */
630
+ event_id: string;
631
+
632
+ /**
633
+ * The ID of the user message item that will be created when speech stops.
634
+ */
635
+ item_id: string;
636
+
637
+ /**
638
+ * The event type, must be `input_audio_buffer.speech_started`.
639
+ */
640
+ type: 'input_audio_buffer.speech_started';
641
+ }
642
+
643
+ /**
644
+ * Returned in `server_vad` mode when the server detects the end of speech in the
645
+ * audio buffer. The server will also send an `conversation.item.created` event
646
+ * with the user message item that is created from the audio buffer.
647
+ */
648
+ export interface InputAudioBufferSpeechStoppedEvent {
649
+ /**
650
+ * Milliseconds since the session started when speech stopped. This will correspond
651
+ * to the end of audio sent to the model, and thus includes the
652
+ * `min_silence_duration_ms` configured in the Session.
653
+ */
654
+ audio_end_ms: number;
655
+
656
+ /**
657
+ * The unique ID of the server event.
658
+ */
659
+ event_id: string;
660
+
661
+ /**
662
+ * The ID of the user message item that will be created.
663
+ */
664
+ item_id: string;
665
+
666
+ /**
667
+ * The event type, must be `input_audio_buffer.speech_stopped`.
668
+ */
669
+ type: 'input_audio_buffer.speech_stopped';
670
+ }
671
+
672
+ /**
673
+ * Emitted at the beginning of a Response to indicate the updated rate limits. When
674
+ * a Response is created some tokens will be "reserved" for the output tokens, the
675
+ * rate limits shown here reflect that reservation, which is then adjusted
676
+ * accordingly once the Response is completed.
677
+ */
678
+ export interface RateLimitsUpdatedEvent {
679
+ /**
680
+ * The unique ID of the server event.
681
+ */
682
+ event_id: string;
683
+
684
+ /**
685
+ * List of rate limit information.
686
+ */
687
+ rate_limits: Array<RateLimitsUpdatedEvent.RateLimit>;
688
+
689
+ /**
690
+ * The event type, must be `rate_limits.updated`.
691
+ */
692
+ type: 'rate_limits.updated';
693
+ }
694
+
695
+ export namespace RateLimitsUpdatedEvent {
696
+ export interface RateLimit {
697
+ /**
698
+ * The maximum allowed value for the rate limit.
699
+ */
700
+ limit?: number;
701
+
702
+ /**
703
+ * The name of the rate limit (`requests`, `tokens`).
704
+ */
705
+ name?: 'requests' | 'tokens';
706
+
707
+ /**
708
+ * The remaining value before the limit is reached.
709
+ */
710
+ remaining?: number;
711
+
712
+ /**
713
+ * Seconds until the rate limit resets.
714
+ */
715
+ reset_seconds?: number;
716
+ }
717
+ }
718
+
719
+ /**
720
+ * All events that the client can send to the Realtime API
721
+ */
722
+ export type RealtimeClientEvent =
723
+ | SessionUpdateEvent
724
+ | InputAudioBufferAppendEvent
725
+ | InputAudioBufferCommitEvent
726
+ | InputAudioBufferClearEvent
727
+ | ConversationItemCreateEvent
728
+ | ConversationItemTruncateEvent
729
+ | ConversationItemDeleteEvent
730
+ | ResponseCreateEvent
731
+ | ResponseCancelEvent;
732
+
733
+ /**
734
+ * The response resource.
735
+ */
736
+ export interface RealtimeResponse {
737
+ /**
738
+ * The unique ID of the response.
739
+ */
740
+ id?: string;
741
+
742
+ /**
743
+ * Developer-provided string key-value pairs associated with this response.
744
+ */
745
+ metadata?: unknown | null;
746
+
747
+ /**
748
+ * The object type, must be `realtime.response`.
749
+ */
750
+ object?: 'realtime.response';
751
+
752
+ /**
753
+ * The list of output items generated by the response.
754
+ */
755
+ output?: Array<ConversationItem>;
756
+
757
+ /**
758
+ * The final status of the response (`completed`, `cancelled`, `failed`, or
759
+ * `incomplete`).
760
+ */
761
+ status?: 'completed' | 'cancelled' | 'failed' | 'incomplete';
762
+
763
+ /**
764
+ * Additional details about the status.
765
+ */
766
+ status_details?: RealtimeResponseStatus;
767
+
768
+ /**
769
+ * Usage statistics for the Response, this will correspond to billing. A Realtime
770
+ * API session will maintain a conversation context and append new Items to the
771
+ * Conversation, thus output from previous turns (text and audio tokens) will
772
+ * become the input for later turns.
773
+ */
774
+ usage?: RealtimeResponseUsage;
775
+ }
776
+
777
+ /**
778
+ * Additional details about the status.
779
+ */
780
+ export interface RealtimeResponseStatus {
781
+ /**
782
+ * A description of the error that caused the response to fail, populated when the
783
+ * `status` is `failed`.
784
+ */
785
+ error?: RealtimeResponseStatus.Error;
786
+
787
+ /**
788
+ * The reason the Response did not complete. For a `cancelled` Response, one of
789
+ * `turn_detected` (the server VAD detected a new start of speech) or
790
+ * `client_cancelled` (the client sent a cancel event). For an `incomplete`
791
+ * Response, one of `max_output_tokens` or `content_filter` (the server-side safety
792
+ * filter activated and cut off the response).
793
+ */
794
+ reason?: 'turn_detected' | 'client_cancelled' | 'max_output_tokens' | 'content_filter';
795
+
796
+ /**
797
+ * The type of error that caused the response to fail, corresponding with the
798
+ * `status` field (`completed`, `cancelled`, `incomplete`, `failed`).
799
+ */
800
+ type?: 'completed' | 'cancelled' | 'incomplete' | 'failed';
801
+ }
802
+
803
+ export namespace RealtimeResponseStatus {
804
+ /**
805
+ * A description of the error that caused the response to fail, populated when the
806
+ * `status` is `failed`.
807
+ */
808
+ export interface Error {
809
+ /**
810
+ * Error code, if any.
811
+ */
812
+ code?: string;
813
+
814
+ /**
815
+ * The type of error.
816
+ */
817
+ type?: string;
818
+ }
819
+ }
820
+
821
+ /**
822
+ * Usage statistics for the Response, this will correspond to billing. A Realtime
823
+ * API session will maintain a conversation context and append new Items to the
824
+ * Conversation, thus output from previous turns (text and audio tokens) will
825
+ * become the input for later turns.
826
+ */
827
+ export interface RealtimeResponseUsage {
828
+ /**
829
+ * Details about the input tokens used in the Response.
830
+ */
831
+ input_token_details?: RealtimeResponseUsage.InputTokenDetails;
832
+
833
+ /**
834
+ * The number of input tokens used in the Response, including text and audio
835
+ * tokens.
836
+ */
837
+ input_tokens?: number;
838
+
839
+ /**
840
+ * Details about the output tokens used in the Response.
841
+ */
842
+ output_token_details?: RealtimeResponseUsage.OutputTokenDetails;
843
+
844
+ /**
845
+ * The number of output tokens sent in the Response, including text and audio
846
+ * tokens.
847
+ */
848
+ output_tokens?: number;
849
+
850
+ /**
851
+ * The total number of tokens in the Response including input and output text and
852
+ * audio tokens.
853
+ */
854
+ total_tokens?: number;
855
+ }
856
+
857
+ export namespace RealtimeResponseUsage {
858
+ /**
859
+ * Details about the input tokens used in the Response.
860
+ */
861
+ export interface InputTokenDetails {
862
+ /**
863
+ * The number of audio tokens used in the Response.
864
+ */
865
+ audio_tokens?: number;
866
+
867
+ /**
868
+ * The number of cached tokens used in the Response.
869
+ */
870
+ cached_tokens?: number;
871
+
872
+ /**
873
+ * The number of text tokens used in the Response.
874
+ */
875
+ text_tokens?: number;
876
+ }
877
+
878
+ /**
879
+ * Details about the output tokens used in the Response.
880
+ */
881
+ export interface OutputTokenDetails {
882
+ /**
883
+ * The number of audio tokens used in the Response.
884
+ */
885
+ audio_tokens?: number;
886
+
887
+ /**
888
+ * The number of text tokens used in the Response.
889
+ */
890
+ text_tokens?: number;
891
+ }
892
+ }
893
+
894
+ /**
895
+ * All events that the Realtime API can send back
896
+ */
897
+ export type RealtimeServerEvent =
898
+ | ErrorEvent
899
+ | SessionCreatedEvent
900
+ | SessionUpdatedEvent
901
+ | ConversationCreatedEvent
902
+ | InputAudioBufferCommittedEvent
903
+ | InputAudioBufferClearedEvent
904
+ | InputAudioBufferSpeechStartedEvent
905
+ | InputAudioBufferSpeechStoppedEvent
906
+ | ConversationItemCreatedEvent
907
+ | ConversationItemInputAudioTranscriptionCompletedEvent
908
+ | ConversationItemInputAudioTranscriptionFailedEvent
909
+ | ConversationItemTruncatedEvent
910
+ | ConversationItemDeletedEvent
911
+ | ResponseCreatedEvent
912
+ | ResponseDoneEvent
913
+ | ResponseOutputItemAddedEvent
914
+ | ResponseOutputItemDoneEvent
915
+ | ResponseContentPartAddedEvent
916
+ | ResponseContentPartDoneEvent
917
+ | ResponseTextDeltaEvent
918
+ | ResponseTextDoneEvent
919
+ | ResponseAudioTranscriptDeltaEvent
920
+ | ResponseAudioTranscriptDoneEvent
921
+ | ResponseAudioDeltaEvent
922
+ | ResponseAudioDoneEvent
923
+ | ResponseFunctionCallArgumentsDeltaEvent
924
+ | ResponseFunctionCallArgumentsDoneEvent
925
+ | RateLimitsUpdatedEvent;
926
+
927
+ /**
928
+ * Returned when the model-generated audio is updated.
929
+ */
930
+ export interface ResponseAudioDeltaEvent {
931
+ /**
932
+ * The index of the content part in the item's content array.
933
+ */
934
+ content_index: number;
935
+
936
+ /**
937
+ * Base64-encoded audio data delta.
938
+ */
939
+ delta: string;
940
+
941
+ /**
942
+ * The unique ID of the server event.
943
+ */
944
+ event_id: string;
945
+
946
+ /**
947
+ * The ID of the item.
948
+ */
949
+ item_id: string;
950
+
951
+ /**
952
+ * The index of the output item in the response.
953
+ */
954
+ output_index: number;
955
+
956
+ /**
957
+ * The ID of the response.
958
+ */
959
+ response_id: string;
960
+
961
+ /**
962
+ * The event type, must be `response.audio.delta`.
963
+ */
964
+ type: 'response.audio.delta';
965
+ }
966
+
967
+ /**
968
+ * Returned when the model-generated audio is done. Also emitted when a Response is
969
+ * interrupted, incomplete, or cancelled.
970
+ */
971
+ export interface ResponseAudioDoneEvent {
972
+ /**
973
+ * The index of the content part in the item's content array.
974
+ */
975
+ content_index: number;
976
+
977
+ /**
978
+ * The unique ID of the server event.
979
+ */
980
+ event_id: string;
981
+
982
+ /**
983
+ * The ID of the item.
984
+ */
985
+ item_id: string;
986
+
987
+ /**
988
+ * The index of the output item in the response.
989
+ */
990
+ output_index: number;
991
+
992
+ /**
993
+ * The ID of the response.
994
+ */
995
+ response_id: string;
996
+
997
+ /**
998
+ * The event type, must be `response.audio.done`.
999
+ */
1000
+ type: 'response.audio.done';
1001
+ }
1002
+
1003
+ /**
1004
+ * Returned when the model-generated transcription of audio output is updated.
1005
+ */
1006
+ export interface ResponseAudioTranscriptDeltaEvent {
1007
+ /**
1008
+ * The index of the content part in the item's content array.
1009
+ */
1010
+ content_index: number;
1011
+
1012
+ /**
1013
+ * The transcript delta.
1014
+ */
1015
+ delta: string;
1016
+
1017
+ /**
1018
+ * The unique ID of the server event.
1019
+ */
1020
+ event_id: string;
1021
+
1022
+ /**
1023
+ * The ID of the item.
1024
+ */
1025
+ item_id: string;
1026
+
1027
+ /**
1028
+ * The index of the output item in the response.
1029
+ */
1030
+ output_index: number;
1031
+
1032
+ /**
1033
+ * The ID of the response.
1034
+ */
1035
+ response_id: string;
1036
+
1037
+ /**
1038
+ * The event type, must be `response.audio_transcript.delta`.
1039
+ */
1040
+ type: 'response.audio_transcript.delta';
1041
+ }
1042
+
1043
+ /**
1044
+ * Returned when the model-generated transcription of audio output is done
1045
+ * streaming. Also emitted when a Response is interrupted, incomplete, or
1046
+ * cancelled.
1047
+ */
1048
+ export interface ResponseAudioTranscriptDoneEvent {
1049
+ /**
1050
+ * The index of the content part in the item's content array.
1051
+ */
1052
+ content_index: number;
1053
+
1054
+ /**
1055
+ * The unique ID of the server event.
1056
+ */
1057
+ event_id: string;
1058
+
1059
+ /**
1060
+ * The ID of the item.
1061
+ */
1062
+ item_id: string;
1063
+
1064
+ /**
1065
+ * The index of the output item in the response.
1066
+ */
1067
+ output_index: number;
1068
+
1069
+ /**
1070
+ * The ID of the response.
1071
+ */
1072
+ response_id: string;
1073
+
1074
+ /**
1075
+ * The final transcript of the audio.
1076
+ */
1077
+ transcript: string;
1078
+
1079
+ /**
1080
+ * The event type, must be `response.audio_transcript.done`.
1081
+ */
1082
+ type: 'response.audio_transcript.done';
1083
+ }
1084
+
1085
+ /**
1086
+ * Send this event to cancel an in-progress response. The server will respond with
1087
+ * a `response.cancelled` event or an error if there is no response to cancel.
1088
+ */
1089
+ export interface ResponseCancelEvent {
1090
+ /**
1091
+ * The event type, must be `response.cancel`.
1092
+ */
1093
+ type: 'response.cancel';
1094
+
1095
+ /**
1096
+ * Optional client-generated ID used to identify this event.
1097
+ */
1098
+ event_id?: string;
1099
+
1100
+ /**
1101
+ * A specific response ID to cancel - if not provided, will cancel an in-progress
1102
+ * response in the default conversation.
1103
+ */
1104
+ response_id?: string;
1105
+ }
1106
+
1107
+ /**
1108
+ * Returned when a new content part is added to an assistant message item during
1109
+ * response generation.
1110
+ */
1111
+ export interface ResponseContentPartAddedEvent {
1112
+ /**
1113
+ * The index of the content part in the item's content array.
1114
+ */
1115
+ content_index: number;
1116
+
1117
+ /**
1118
+ * The unique ID of the server event.
1119
+ */
1120
+ event_id: string;
1121
+
1122
+ /**
1123
+ * The ID of the item to which the content part was added.
1124
+ */
1125
+ item_id: string;
1126
+
1127
+ /**
1128
+ * The index of the output item in the response.
1129
+ */
1130
+ output_index: number;
1131
+
1132
+ /**
1133
+ * The content part that was added.
1134
+ */
1135
+ part: ResponseContentPartAddedEvent.Part;
1136
+
1137
+ /**
1138
+ * The ID of the response.
1139
+ */
1140
+ response_id: string;
1141
+
1142
+ /**
1143
+ * The event type, must be `response.content_part.added`.
1144
+ */
1145
+ type: 'response.content_part.added';
1146
+ }
1147
+
1148
+ export namespace ResponseContentPartAddedEvent {
1149
+ /**
1150
+ * The content part that was added.
1151
+ */
1152
+ export interface Part {
1153
+ /**
1154
+ * Base64-encoded audio data (if type is "audio").
1155
+ */
1156
+ audio?: string;
1157
+
1158
+ /**
1159
+ * The text content (if type is "text").
1160
+ */
1161
+ text?: string;
1162
+
1163
+ /**
1164
+ * The transcript of the audio (if type is "audio").
1165
+ */
1166
+ transcript?: string;
1167
+
1168
+ /**
1169
+ * The content type ("text", "audio").
1170
+ */
1171
+ type?: 'text' | 'audio';
1172
+ }
1173
+ }
1174
+
1175
+ /**
1176
+ * Returned when a content part is done streaming in an assistant message item.
1177
+ * Also emitted when a Response is interrupted, incomplete, or cancelled.
1178
+ */
1179
+ export interface ResponseContentPartDoneEvent {
1180
+ /**
1181
+ * The index of the content part in the item's content array.
1182
+ */
1183
+ content_index: number;
1184
+
1185
+ /**
1186
+ * The unique ID of the server event.
1187
+ */
1188
+ event_id: string;
1189
+
1190
+ /**
1191
+ * The ID of the item.
1192
+ */
1193
+ item_id: string;
1194
+
1195
+ /**
1196
+ * The index of the output item in the response.
1197
+ */
1198
+ output_index: number;
1199
+
1200
+ /**
1201
+ * The content part that is done.
1202
+ */
1203
+ part: ResponseContentPartDoneEvent.Part;
1204
+
1205
+ /**
1206
+ * The ID of the response.
1207
+ */
1208
+ response_id: string;
1209
+
1210
+ /**
1211
+ * The event type, must be `response.content_part.done`.
1212
+ */
1213
+ type: 'response.content_part.done';
1214
+ }
1215
+
1216
+ export namespace ResponseContentPartDoneEvent {
1217
+ /**
1218
+ * The content part that is done.
1219
+ */
1220
+ export interface Part {
1221
+ /**
1222
+ * Base64-encoded audio data (if type is "audio").
1223
+ */
1224
+ audio?: string;
1225
+
1226
+ /**
1227
+ * The text content (if type is "text").
1228
+ */
1229
+ text?: string;
1230
+
1231
+ /**
1232
+ * The transcript of the audio (if type is "audio").
1233
+ */
1234
+ transcript?: string;
1235
+
1236
+ /**
1237
+ * The content type ("text", "audio").
1238
+ */
1239
+ type?: 'text' | 'audio';
1240
+ }
1241
+ }
1242
+
1243
+ /**
1244
+ * This event instructs the server to create a Response, which means triggering
1245
+ * model inference. When in Server VAD mode, the server will create Responses
1246
+ * automatically.
1247
+ *
1248
+ * A Response will include at least one Item, and may have two, in which case the
1249
+ * second will be a function call. These Items will be appended to the conversation
1250
+ * history.
1251
+ *
1252
+ * The server will respond with a `response.created` event, events for Items and
1253
+ * content created, and finally a `response.done` event to indicate the Response is
1254
+ * complete.
1255
+ *
1256
+ * The `response.create` event includes inference configuration like
1257
+ * `instructions`, and `temperature`. These fields will override the Session's
1258
+ * configuration for this Response only.
1259
+ */
1260
+ export interface ResponseCreateEvent {
1261
+ /**
1262
+ * The event type, must be `response.create`.
1263
+ */
1264
+ type: 'response.create';
1265
+
1266
+ /**
1267
+ * Optional client-generated ID used to identify this event.
1268
+ */
1269
+ event_id?: string;
1270
+
1271
+ /**
1272
+ * Create a new Realtime response with these parameters
1273
+ */
1274
+ response?: ResponseCreateEvent.Response;
1275
+ }
1276
+
1277
+ export namespace ResponseCreateEvent {
1278
+ /**
1279
+ * Create a new Realtime response with these parameters
1280
+ */
1281
+ export interface Response {
1282
+ /**
1283
+ * Controls which conversation the response is added to. Currently supports `auto`
1284
+ * and `none`, with `auto` as the default value. The `auto` value means that the
1285
+ * contents of the response will be added to the default conversation. Set this to
1286
+ * `none` to create an out-of-band response which will not add items to default
1287
+ * conversation.
1288
+ */
1289
+ conversation?: (string & {}) | 'auto' | 'none';
1290
+
1291
+ /**
1292
+ * Input items to include in the prompt for the model. Creates a new context for
1293
+ * this response, without including the default conversation. Can include
1294
+ * references to items from the default conversation.
1295
+ */
1296
+ input?: Array<RealtimeAPI.ConversationItem>;
1297
+
1298
+ /**
1299
+ * The default system instructions (i.e. system message) prepended to model calls.
1300
+ * This field allows the client to guide the model on desired responses. The model
1301
+ * can be instructed on response content and format, (e.g. "be extremely succinct",
1302
+ * "act friendly", "here are examples of good responses") and on audio behavior
1303
+ * (e.g. "talk quickly", "inject emotion into your voice", "laugh frequently"). The
1304
+ * instructions are not guaranteed to be followed by the model, but they provide
1305
+ * guidance to the model on the desired behavior.
1306
+ *
1307
+ * Note that the server sets default instructions which will be used if this field
1308
+ * is not set and are visible in the `session.created` event at the start of the
1309
+ * session.
1310
+ */
1311
+ instructions?: string;
1312
+
1313
+ /**
1314
+ * Maximum number of output tokens for a single assistant response, inclusive of
1315
+ * tool calls. Provide an integer between 1 and 4096 to limit output tokens, or
1316
+ * `inf` for the maximum available tokens for a given model. Defaults to `inf`.
1317
+ */
1318
+ max_response_output_tokens?: number | 'inf';
1319
+
1320
+ /**
1321
+ * Set of 16 key-value pairs that can be attached to an object. This can be useful
1322
+ * for storing additional information about the object in a structured format. Keys
1323
+ * can be a maximum of 64 characters long and values can be a maximum of 512
1324
+ * characters long.
1325
+ */
1326
+ metadata?: unknown | null;
1327
+
1328
+ /**
1329
+ * The set of modalities the model can respond with. To disable audio, set this to
1330
+ * ["text"].
1331
+ */
1332
+ modalities?: Array<'text' | 'audio'>;
1333
+
1334
+ /**
1335
+ * The format of output audio. Options are `pcm16`, `g711_ulaw`, or `g711_alaw`.
1336
+ */
1337
+ output_audio_format?: 'pcm16' | 'g711_ulaw' | 'g711_alaw';
1338
+
1339
+ /**
1340
+ * Sampling temperature for the model, limited to [0.6, 1.2]. Defaults to 0.8.
1341
+ */
1342
+ temperature?: number;
1343
+
1344
+ /**
1345
+ * How the model chooses tools. Options are `auto`, `none`, `required`, or specify
1346
+ * a function, like `{"type": "function", "function": {"name": "my_function"}}`.
1347
+ */
1348
+ tool_choice?: string;
1349
+
1350
+ /**
1351
+ * Tools (functions) available to the model.
1352
+ */
1353
+ tools?: Array<Response.Tool>;
1354
+
1355
+ /**
1356
+ * The voice the model uses to respond. Voice cannot be changed during the session
1357
+ * once the model has responded with audio at least once. Current voice options are
1358
+ * `alloy`, `ash`, `ballad`, `coral`, `echo` `sage`, `shimmer` and `verse`.
1359
+ */
1360
+ voice?: 'alloy' | 'ash' | 'ballad' | 'coral' | 'echo' | 'sage' | 'shimmer' | 'verse';
1361
+ }
1362
+
1363
+ export namespace Response {
1364
+ export interface Tool {
1365
+ /**
1366
+ * The description of the function, including guidance on when and how to call it,
1367
+ * and guidance about what to tell the user when calling (if anything).
1368
+ */
1369
+ description?: string;
1370
+
1371
+ /**
1372
+ * The name of the function.
1373
+ */
1374
+ name?: string;
1375
+
1376
+ /**
1377
+ * Parameters of the function in JSON Schema.
1378
+ */
1379
+ parameters?: unknown;
1380
+
1381
+ /**
1382
+ * The type of the tool, i.e. `function`.
1383
+ */
1384
+ type?: 'function';
1385
+ }
1386
+ }
1387
+ }
1388
+
1389
+ /**
1390
+ * Returned when a new Response is created. The first event of response creation,
1391
+ * where the response is in an initial state of `in_progress`.
1392
+ */
1393
+ export interface ResponseCreatedEvent {
1394
+ /**
1395
+ * The unique ID of the server event.
1396
+ */
1397
+ event_id: string;
1398
+
1399
+ /**
1400
+ * The response resource.
1401
+ */
1402
+ response: RealtimeResponse;
1403
+
1404
+ /**
1405
+ * The event type, must be `response.created`.
1406
+ */
1407
+ type: 'response.created';
1408
+ }
1409
+
1410
+ /**
1411
+ * Returned when a Response is done streaming. Always emitted, no matter the final
1412
+ * state. The Response object included in the `response.done` event will include
1413
+ * all output Items in the Response but will omit the raw audio data.
1414
+ */
1415
+ export interface ResponseDoneEvent {
1416
+ /**
1417
+ * The unique ID of the server event.
1418
+ */
1419
+ event_id: string;
1420
+
1421
+ /**
1422
+ * The response resource.
1423
+ */
1424
+ response: RealtimeResponse;
1425
+
1426
+ /**
1427
+ * The event type, must be `response.done`.
1428
+ */
1429
+ type: 'response.done';
1430
+ }
1431
+
1432
+ /**
1433
+ * Returned when the model-generated function call arguments are updated.
1434
+ */
1435
+ export interface ResponseFunctionCallArgumentsDeltaEvent {
1436
+ /**
1437
+ * The ID of the function call.
1438
+ */
1439
+ call_id: string;
1440
+
1441
+ /**
1442
+ * The arguments delta as a JSON string.
1443
+ */
1444
+ delta: string;
1445
+
1446
+ /**
1447
+ * The unique ID of the server event.
1448
+ */
1449
+ event_id: string;
1450
+
1451
+ /**
1452
+ * The ID of the function call item.
1453
+ */
1454
+ item_id: string;
1455
+
1456
+ /**
1457
+ * The index of the output item in the response.
1458
+ */
1459
+ output_index: number;
1460
+
1461
+ /**
1462
+ * The ID of the response.
1463
+ */
1464
+ response_id: string;
1465
+
1466
+ /**
1467
+ * The event type, must be `response.function_call_arguments.delta`.
1468
+ */
1469
+ type: 'response.function_call_arguments.delta';
1470
+ }
1471
+
1472
+ /**
1473
+ * Returned when the model-generated function call arguments are done streaming.
1474
+ * Also emitted when a Response is interrupted, incomplete, or cancelled.
1475
+ */
1476
+ export interface ResponseFunctionCallArgumentsDoneEvent {
1477
+ /**
1478
+ * The final arguments as a JSON string.
1479
+ */
1480
+ arguments: string;
1481
+
1482
+ /**
1483
+ * The ID of the function call.
1484
+ */
1485
+ call_id: string;
1486
+
1487
+ /**
1488
+ * The unique ID of the server event.
1489
+ */
1490
+ event_id: string;
1491
+
1492
+ /**
1493
+ * The ID of the function call item.
1494
+ */
1495
+ item_id: string;
1496
+
1497
+ /**
1498
+ * The index of the output item in the response.
1499
+ */
1500
+ output_index: number;
1501
+
1502
+ /**
1503
+ * The ID of the response.
1504
+ */
1505
+ response_id: string;
1506
+
1507
+ /**
1508
+ * The event type, must be `response.function_call_arguments.done`.
1509
+ */
1510
+ type: 'response.function_call_arguments.done';
1511
+ }
1512
+
1513
+ /**
1514
+ * Returned when a new Item is created during Response generation.
1515
+ */
1516
+ export interface ResponseOutputItemAddedEvent {
1517
+ /**
1518
+ * The unique ID of the server event.
1519
+ */
1520
+ event_id: string;
1521
+
1522
+ /**
1523
+ * The item to add to the conversation.
1524
+ */
1525
+ item: ConversationItem;
1526
+
1527
+ /**
1528
+ * The index of the output item in the Response.
1529
+ */
1530
+ output_index: number;
1531
+
1532
+ /**
1533
+ * The ID of the Response to which the item belongs.
1534
+ */
1535
+ response_id: string;
1536
+
1537
+ /**
1538
+ * The event type, must be `response.output_item.added`.
1539
+ */
1540
+ type: 'response.output_item.added';
1541
+ }
1542
+
1543
+ /**
1544
+ * Returned when an Item is done streaming. Also emitted when a Response is
1545
+ * interrupted, incomplete, or cancelled.
1546
+ */
1547
+ export interface ResponseOutputItemDoneEvent {
1548
+ /**
1549
+ * The unique ID of the server event.
1550
+ */
1551
+ event_id: string;
1552
+
1553
+ /**
1554
+ * The item to add to the conversation.
1555
+ */
1556
+ item: ConversationItem;
1557
+
1558
+ /**
1559
+ * The index of the output item in the Response.
1560
+ */
1561
+ output_index: number;
1562
+
1563
+ /**
1564
+ * The ID of the Response to which the item belongs.
1565
+ */
1566
+ response_id: string;
1567
+
1568
+ /**
1569
+ * The event type, must be `response.output_item.done`.
1570
+ */
1571
+ type: 'response.output_item.done';
1572
+ }
1573
+
1574
+ /**
1575
+ * Returned when the text value of a "text" content part is updated.
1576
+ */
1577
+ export interface ResponseTextDeltaEvent {
1578
+ /**
1579
+ * The index of the content part in the item's content array.
1580
+ */
1581
+ content_index: number;
1582
+
1583
+ /**
1584
+ * The text delta.
1585
+ */
1586
+ delta: string;
1587
+
1588
+ /**
1589
+ * The unique ID of the server event.
1590
+ */
1591
+ event_id: string;
1592
+
1593
+ /**
1594
+ * The ID of the item.
1595
+ */
1596
+ item_id: string;
1597
+
1598
+ /**
1599
+ * The index of the output item in the response.
1600
+ */
1601
+ output_index: number;
1602
+
1603
+ /**
1604
+ * The ID of the response.
1605
+ */
1606
+ response_id: string;
1607
+
1608
+ /**
1609
+ * The event type, must be `response.text.delta`.
1610
+ */
1611
+ type: 'response.text.delta';
1612
+ }
1613
+
1614
+ /**
1615
+ * Returned when the text value of a "text" content part is done streaming. Also
1616
+ * emitted when a Response is interrupted, incomplete, or cancelled.
1617
+ */
1618
+ export interface ResponseTextDoneEvent {
1619
+ /**
1620
+ * The index of the content part in the item's content array.
1621
+ */
1622
+ content_index: number;
1623
+
1624
+ /**
1625
+ * The unique ID of the server event.
1626
+ */
1627
+ event_id: string;
1628
+
1629
+ /**
1630
+ * The ID of the item.
1631
+ */
1632
+ item_id: string;
1633
+
1634
+ /**
1635
+ * The index of the output item in the response.
1636
+ */
1637
+ output_index: number;
1638
+
1639
+ /**
1640
+ * The ID of the response.
1641
+ */
1642
+ response_id: string;
1643
+
1644
+ /**
1645
+ * The final text content.
1646
+ */
1647
+ text: string;
1648
+
1649
+ /**
1650
+ * The event type, must be `response.text.done`.
1651
+ */
1652
+ type: 'response.text.done';
1653
+ }
1654
+
1655
+ /**
1656
+ * Returned when a Session is created. Emitted automatically when a new connection
1657
+ * is established as the first server event. This event will contain the default
1658
+ * Session configuration.
1659
+ */
1660
+ export interface SessionCreatedEvent {
1661
+ /**
1662
+ * The unique ID of the server event.
1663
+ */
1664
+ event_id: string;
1665
+
1666
+ /**
1667
+ * Realtime session object configuration.
1668
+ */
1669
+ session: SessionsAPI.Session;
1670
+
1671
+ /**
1672
+ * The event type, must be `session.created`.
1673
+ */
1674
+ type: 'session.created';
1675
+ }
1676
+
1677
+ /**
1678
+ * Send this event to update the session’s default configuration. The client may
1679
+ * send this event at any time to update the session configuration, and any field
1680
+ * may be updated at any time, except for "voice". The server will respond with a
1681
+ * `session.updated` event that shows the full effective configuration. Only fields
1682
+ * that are present are updated, thus the correct way to clear a field like
1683
+ * "instructions" is to pass an empty string.
1684
+ */
1685
+ export interface SessionUpdateEvent {
1686
+ /**
1687
+ * Realtime session object configuration.
1688
+ */
1689
+ session: SessionUpdateEvent.Session;
1690
+
1691
+ /**
1692
+ * The event type, must be `session.update`.
1693
+ */
1694
+ type: 'session.update';
1695
+
1696
+ /**
1697
+ * Optional client-generated ID used to identify this event.
1698
+ */
1699
+ event_id?: string;
1700
+ }
1701
+
1702
+ export namespace SessionUpdateEvent {
1703
+ /**
1704
+ * Realtime session object configuration.
1705
+ */
1706
+ export interface Session {
1707
+ /**
1708
+ * The Realtime model used for this session.
1709
+ */
1710
+ model:
1711
+ | 'gpt-4o-realtime-preview'
1712
+ | 'gpt-4o-realtime-preview-2024-10-01'
1713
+ | 'gpt-4o-realtime-preview-2024-12-17'
1714
+ | 'gpt-4o-mini-realtime-preview'
1715
+ | 'gpt-4o-mini-realtime-preview-2024-12-17';
1716
+
1717
+ /**
1718
+ * The format of input audio. Options are `pcm16`, `g711_ulaw`, or `g711_alaw`.
1719
+ */
1720
+ input_audio_format?: 'pcm16' | 'g711_ulaw' | 'g711_alaw';
1721
+
1722
+ /**
1723
+ * Configuration for input audio transcription, defaults to off and can be set to
1724
+ * `null` to turn off once on. Input audio transcription is not native to the
1725
+ * model, since the model consumes audio directly. Transcription runs
1726
+ * asynchronously through Whisper and should be treated as rough guidance rather
1727
+ * than the representation understood by the model.
1728
+ */
1729
+ input_audio_transcription?: Session.InputAudioTranscription;
1730
+
1731
+ /**
1732
+ * The default system instructions (i.e. system message) prepended to model calls.
1733
+ * This field allows the client to guide the model on desired responses. The model
1734
+ * can be instructed on response content and format, (e.g. "be extremely succinct",
1735
+ * "act friendly", "here are examples of good responses") and on audio behavior
1736
+ * (e.g. "talk quickly", "inject emotion into your voice", "laugh frequently"). The
1737
+ * instructions are not guaranteed to be followed by the model, but they provide
1738
+ * guidance to the model on the desired behavior.
1739
+ *
1740
+ * Note that the server sets default instructions which will be used if this field
1741
+ * is not set and are visible in the `session.created` event at the start of the
1742
+ * session.
1743
+ */
1744
+ instructions?: string;
1745
+
1746
+ /**
1747
+ * Maximum number of output tokens for a single assistant response, inclusive of
1748
+ * tool calls. Provide an integer between 1 and 4096 to limit output tokens, or
1749
+ * `inf` for the maximum available tokens for a given model. Defaults to `inf`.
1750
+ */
1751
+ max_response_output_tokens?: number | 'inf';
1752
+
1753
+ /**
1754
+ * The set of modalities the model can respond with. To disable audio, set this to
1755
+ * ["text"].
1756
+ */
1757
+ modalities?: Array<'text' | 'audio'>;
1758
+
1759
+ /**
1760
+ * The format of output audio. Options are `pcm16`, `g711_ulaw`, or `g711_alaw`.
1761
+ */
1762
+ output_audio_format?: 'pcm16' | 'g711_ulaw' | 'g711_alaw';
1763
+
1764
+ /**
1765
+ * Sampling temperature for the model, limited to [0.6, 1.2]. Defaults to 0.8.
1766
+ */
1767
+ temperature?: number;
1768
+
1769
+ /**
1770
+ * How the model chooses tools. Options are `auto`, `none`, `required`, or specify
1771
+ * a function.
1772
+ */
1773
+ tool_choice?: string;
1774
+
1775
+ /**
1776
+ * Tools (functions) available to the model.
1777
+ */
1778
+ tools?: Array<Session.Tool>;
1779
+
1780
+ /**
1781
+ * Configuration for turn detection. Can be set to `null` to turn off. Server VAD
1782
+ * means that the model will detect the start and end of speech based on audio
1783
+ * volume and respond at the end of user speech.
1784
+ */
1785
+ turn_detection?: Session.TurnDetection;
1786
+
1787
+ /**
1788
+ * The voice the model uses to respond. Voice cannot be changed during the session
1789
+ * once the model has responded with audio at least once. Current voice options are
1790
+ * `alloy`, `ash`, `ballad`, `coral`, `echo` `sage`, `shimmer` and `verse`.
1791
+ */
1792
+ voice?: 'alloy' | 'ash' | 'ballad' | 'coral' | 'echo' | 'sage' | 'shimmer' | 'verse';
1793
+ }
1794
+
1795
+ export namespace Session {
1796
+ /**
1797
+ * Configuration for input audio transcription, defaults to off and can be set to
1798
+ * `null` to turn off once on. Input audio transcription is not native to the
1799
+ * model, since the model consumes audio directly. Transcription runs
1800
+ * asynchronously through Whisper and should be treated as rough guidance rather
1801
+ * than the representation understood by the model.
1802
+ */
1803
+ export interface InputAudioTranscription {
1804
+ /**
1805
+ * The model to use for transcription, `whisper-1` is the only currently supported
1806
+ * model.
1807
+ */
1808
+ model?: string;
1809
+ }
1810
+
1811
+ export interface Tool {
1812
+ /**
1813
+ * The description of the function, including guidance on when and how to call it,
1814
+ * and guidance about what to tell the user when calling (if anything).
1815
+ */
1816
+ description?: string;
1817
+
1818
+ /**
1819
+ * The name of the function.
1820
+ */
1821
+ name?: string;
1822
+
1823
+ /**
1824
+ * Parameters of the function in JSON Schema.
1825
+ */
1826
+ parameters?: unknown;
1827
+
1828
+ /**
1829
+ * The type of the tool, i.e. `function`.
1830
+ */
1831
+ type?: 'function';
1832
+ }
1833
+
1834
+ /**
1835
+ * Configuration for turn detection. Can be set to `null` to turn off. Server VAD
1836
+ * means that the model will detect the start and end of speech based on audio
1837
+ * volume and respond at the end of user speech.
1838
+ */
1839
+ export interface TurnDetection {
1840
+ /**
1841
+ * Whether or not to automatically generate a response when VAD is enabled. `true`
1842
+ * by default.
1843
+ */
1844
+ create_response?: boolean;
1845
+
1846
+ /**
1847
+ * Amount of audio to include before the VAD detected speech (in milliseconds).
1848
+ * Defaults to 300ms.
1849
+ */
1850
+ prefix_padding_ms?: number;
1851
+
1852
+ /**
1853
+ * Duration of silence to detect speech stop (in milliseconds). Defaults to 500ms.
1854
+ * With shorter values the model will respond more quickly, but may jump in on
1855
+ * short pauses from the user.
1856
+ */
1857
+ silence_duration_ms?: number;
1858
+
1859
+ /**
1860
+ * Activation threshold for VAD (0.0 to 1.0), this defaults to 0.5. A higher
1861
+ * threshold will require louder audio to activate the model, and thus might
1862
+ * perform better in noisy environments.
1863
+ */
1864
+ threshold?: number;
1865
+
1866
+ /**
1867
+ * Type of turn detection, only `server_vad` is currently supported.
1868
+ */
1869
+ type?: string;
1870
+ }
1871
+ }
1872
+ }
1873
+
1874
+ /**
1875
+ * Returned when a session is updated with a `session.update` event, unless there
1876
+ * is an error.
1877
+ */
1878
+ export interface SessionUpdatedEvent {
1879
+ /**
1880
+ * The unique ID of the server event.
1881
+ */
1882
+ event_id: string;
1883
+
1884
+ /**
1885
+ * Realtime session object configuration.
1886
+ */
1887
+ session: SessionsAPI.Session;
1888
+
1889
+ /**
1890
+ * The event type, must be `session.updated`.
1891
+ */
1892
+ type: 'session.updated';
1893
+ }
1894
+
1895
+ Realtime.Sessions = Sessions;
1896
+
1897
+ export declare namespace Realtime {
1898
+ export {
1899
+ Sessions as Sessions,
1900
+ type SessionsAPISession as Session,
1901
+ type SessionCreateResponse as SessionCreateResponse,
1902
+ type SessionCreateParams as SessionCreateParams,
1903
+ };
1904
+ }