-
Notifications
You must be signed in to change notification settings - Fork 916
/
Copy pathrealtime.ts
1908 lines (1641 loc) · 48.2 KB
/
realtime.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
import { APIResource } from '../../../resource';
import * as RealtimeAPI from './realtime';
import * as SessionsAPI from './sessions';
import {
Session as SessionsAPISession,
SessionCreateParams,
SessionCreateResponse,
Sessions,
} from './sessions';
export class Realtime extends APIResource {
sessions: SessionsAPI.Sessions = new SessionsAPI.Sessions(this._client);
}
/**
* Returned when a conversation is created. Emitted right after session creation.
*/
export interface ConversationCreatedEvent {
/**
* The conversation resource.
*/
conversation: ConversationCreatedEvent.Conversation;
/**
* The unique ID of the server event.
*/
event_id: string;
/**
* The event type, must be `conversation.created`.
*/
type: 'conversation.created';
}
export namespace ConversationCreatedEvent {
/**
* The conversation resource.
*/
export interface Conversation {
/**
* The unique ID of the conversation.
*/
id?: string;
/**
* The object type, must be `realtime.conversation`.
*/
object?: 'realtime.conversation';
}
}
/**
* The item to add to the conversation.
*/
export interface ConversationItem {
/**
* The unique ID of the item, this can be generated by the client to help manage
* server-side context, but is not required because the server will generate one if
* not provided.
*/
id?: string;
/**
* The arguments of the function call (for `function_call` items).
*/
arguments?: string;
/**
* The ID of the function call (for `function_call` and `function_call_output`
* items). If passed on a `function_call_output` item, the server will check that a
* `function_call` item with the same ID exists in the conversation history.
*/
call_id?: string;
/**
* The content of the message, applicable for `message` items.
*
* - Message items of role `system` support only `input_text` content
* - Message items of role `user` support `input_text` and `input_audio` content
* - Message items of role `assistant` support `text` content.
*/
content?: Array<ConversationItemContent>;
/**
* The name of the function being called (for `function_call` items).
*/
name?: string;
/**
* Identifier for the API object being returned - always `realtime.item`.
*/
object?: 'realtime.item';
/**
* The output of the function call (for `function_call_output` items).
*/
output?: string;
/**
* The role of the message sender (`user`, `assistant`, `system`), only applicable
* for `message` items.
*/
role?: 'user' | 'assistant' | 'system';
/**
* The status of the item (`completed`, `incomplete`). These have no effect on the
* conversation, but are accepted for consistency with the
* `conversation.item.created` event.
*/
status?: 'completed' | 'incomplete';
/**
* The type of the item (`message`, `function_call`, `function_call_output`).
*/
type?: 'message' | 'function_call' | 'function_call_output';
}
export interface ConversationItemContent {
/**
* ID of a previous conversation item to reference (for `item_reference` content
* types in `response.create` events). These can reference both client and server
* created items.
*/
id?: string;
/**
* Base64-encoded audio bytes, used for `input_audio` content type.
*/
audio?: string;
/**
* The text content, used for `input_text` and `text` content types.
*/
text?: string;
/**
* The transcript of the audio, used for `input_audio` content type.
*/
transcript?: string;
/**
* The content type (`input_text`, `input_audio`, `item_reference`, `text`).
*/
type?: 'input_text' | 'input_audio' | 'item_reference' | 'text';
}
/**
* Add a new Item to the Conversation's context, including messages, function
* calls, and function call responses. This event can be used both to populate a
* "history" of the conversation and to add new items mid-stream, but has the
* current limitation that it cannot populate assistant audio messages.
*
* If successful, the server will respond with a `conversation.item.created` event,
* otherwise an `error` event will be sent.
*/
export interface ConversationItemCreateEvent {
/**
* The item to add to the conversation.
*/
item: ConversationItem;
/**
* The event type, must be `conversation.item.create`.
*/
type: 'conversation.item.create';
/**
* Optional client-generated ID used to identify this event.
*/
event_id?: string;
/**
* The ID of the preceding item after which the new item will be inserted. If not
* set, the new item will be appended to the end of the conversation. If set to
* `root`, the new item will be added to the beginning of the conversation. If set
* to an existing ID, it allows an item to be inserted mid-conversation. If the ID
* cannot be found, an error will be returned and the item will not be added.
*/
previous_item_id?: string;
}
/**
* Returned when a conversation item is created. There are several scenarios that
* produce this event:
*
* - The server is generating a Response, which if successful will produce either
* one or two Items, which will be of type `message` (role `assistant`) or type
* `function_call`.
* - The input audio buffer has been committed, either by the client or the server
* (in `server_vad` mode). The server will take the content of the input audio
* buffer and add it to a new user message Item.
* - The client has sent a `conversation.item.create` event to add a new Item to
* the Conversation.
*/
export interface ConversationItemCreatedEvent {
/**
* The unique ID of the server event.
*/
event_id: string;
/**
* The item to add to the conversation.
*/
item: ConversationItem;
/**
* The ID of the preceding item in the Conversation context, allows the client to
* understand the order of the conversation.
*/
previous_item_id: string;
/**
* The event type, must be `conversation.item.created`.
*/
type: 'conversation.item.created';
}
/**
* Send this event when you want to remove any item from the conversation history.
* The server will respond with a `conversation.item.deleted` event, unless the
* item does not exist in the conversation history, in which case the server will
* respond with an error.
*/
export interface ConversationItemDeleteEvent {
/**
* The ID of the item to delete.
*/
item_id: string;
/**
* The event type, must be `conversation.item.delete`.
*/
type: 'conversation.item.delete';
/**
* Optional client-generated ID used to identify this event.
*/
event_id?: string;
}
/**
* Returned when an item in the conversation is deleted by the client with a
* `conversation.item.delete` event. This event is used to synchronize the server's
* understanding of the conversation history with the client's view.
*/
export interface ConversationItemDeletedEvent {
/**
* The unique ID of the server event.
*/
event_id: string;
/**
* The ID of the item that was deleted.
*/
item_id: string;
/**
* The event type, must be `conversation.item.deleted`.
*/
type: 'conversation.item.deleted';
}
/**
* This event is the output of audio transcription for user audio written to the
* user audio buffer. Transcription begins when the input audio buffer is committed
* by the client or server (in `server_vad` mode). Transcription runs
* asynchronously with Response creation, so this event may come before or after
* the Response events.
*
* Realtime API models accept audio natively, and thus input transcription is a
* separate process run on a separate ASR (Automatic Speech Recognition) model,
* currently always `whisper-1`. Thus the transcript may diverge somewhat from the
* model's interpretation, and should be treated as a rough guide.
*/
export interface ConversationItemInputAudioTranscriptionCompletedEvent {
/**
* The index of the content part containing the audio.
*/
content_index: number;
/**
* The unique ID of the server event.
*/
event_id: string;
/**
* The ID of the user message item containing the audio.
*/
item_id: string;
/**
* The transcribed text.
*/
transcript: string;
/**
* The event type, must be `conversation.item.input_audio_transcription.completed`.
*/
type: 'conversation.item.input_audio_transcription.completed';
}
/**
* Returned when input audio transcription is configured, and a transcription
* request for a user message failed. These events are separate from other `error`
* events so that the client can identify the related Item.
*/
export interface ConversationItemInputAudioTranscriptionFailedEvent {
/**
* The index of the content part containing the audio.
*/
content_index: number;
/**
* Details of the transcription error.
*/
error: ConversationItemInputAudioTranscriptionFailedEvent.Error;
/**
* The unique ID of the server event.
*/
event_id: string;
/**
* The ID of the user message item.
*/
item_id: string;
/**
* The event type, must be `conversation.item.input_audio_transcription.failed`.
*/
type: 'conversation.item.input_audio_transcription.failed';
}
export namespace ConversationItemInputAudioTranscriptionFailedEvent {
/**
* Details of the transcription error.
*/
export interface Error {
/**
* Error code, if any.
*/
code?: string;
/**
* A human-readable error message.
*/
message?: string;
/**
* Parameter related to the error, if any.
*/
param?: string;
/**
* The type of error.
*/
type?: string;
}
}
/**
* Send this event to truncate a previous assistant message’s audio. The server
* will produce audio faster than realtime, so this event is useful when the user
* interrupts to truncate audio that has already been sent to the client but not
* yet played. This will synchronize the server's understanding of the audio with
* the client's playback.
*
* Truncating audio will delete the server-side text transcript to ensure there is
* not text in the context that hasn't been heard by the user.
*
* If successful, the server will respond with a `conversation.item.truncated`
* event.
*/
export interface ConversationItemTruncateEvent {
/**
* Inclusive duration up to which audio is truncated, in milliseconds. If the
* audio_end_ms is greater than the actual audio duration, the server will respond
* with an error.
*/
audio_end_ms: number;
/**
* The index of the content part to truncate. Set this to 0.
*/
content_index: number;
/**
* The ID of the assistant message item to truncate. Only assistant message items
* can be truncated.
*/
item_id: string;
/**
* The event type, must be `conversation.item.truncate`.
*/
type: 'conversation.item.truncate';
/**
* Optional client-generated ID used to identify this event.
*/
event_id?: string;
}
/**
* Returned when an earlier assistant audio message item is truncated by the client
* with a `conversation.item.truncate` event. This event is used to synchronize the
* server's understanding of the audio with the client's playback.
*
* This action will truncate the audio and remove the server-side text transcript
* to ensure there is no text in the context that hasn't been heard by the user.
*/
export interface ConversationItemTruncatedEvent {
/**
* The duration up to which the audio was truncated, in milliseconds.
*/
audio_end_ms: number;
/**
* The index of the content part that was truncated.
*/
content_index: number;
/**
* The unique ID of the server event.
*/
event_id: string;
/**
* The ID of the assistant message item that was truncated.
*/
item_id: string;
/**
* The event type, must be `conversation.item.truncated`.
*/
type: 'conversation.item.truncated';
}
/**
* Returned when an error occurs, which could be a client problem or a server
* problem. Most errors are recoverable and the session will stay open, we
* recommend to implementors to monitor and log error messages by default.
*/
export interface ErrorEvent {
/**
* Details of the error.
*/
error: ErrorEvent.Error;
/**
* The unique ID of the server event.
*/
event_id: string;
/**
* The event type, must be `error`.
*/
type: 'error';
}
export namespace ErrorEvent {
/**
* Details of the error.
*/
export interface Error {
/**
* A human-readable error message.
*/
message: string;
/**
* The type of error (e.g., "invalid_request_error", "server_error").
*/
type: string;
/**
* Error code, if any.
*/
code?: string | null;
/**
* The event_id of the client event that caused the error, if applicable.
*/
event_id?: string | null;
/**
* Parameter related to the error, if any.
*/
param?: string | null;
}
}
/**
* Send this event to append audio bytes to the input audio buffer. The audio
* buffer is temporary storage you can write to and later commit. In Server VAD
* mode, the audio buffer is used to detect speech and the server will decide when
* to commit. When Server VAD is disabled, you must commit the audio buffer
* manually.
*
* The client may choose how much audio to place in each event up to a maximum of
* 15 MiB, for example streaming smaller chunks from the client may allow the VAD
* to be more responsive. Unlike made other client events, the server will not send
* a confirmation response to this event.
*/
export interface InputAudioBufferAppendEvent {
/**
* Base64-encoded audio bytes. This must be in the format specified by the
* `input_audio_format` field in the session configuration.
*/
audio: string;
/**
* The event type, must be `input_audio_buffer.append`.
*/
type: 'input_audio_buffer.append';
/**
* Optional client-generated ID used to identify this event.
*/
event_id?: string;
}
/**
* Send this event to clear the audio bytes in the buffer. The server will respond
* with an `input_audio_buffer.cleared` event.
*/
export interface InputAudioBufferClearEvent {
/**
* The event type, must be `input_audio_buffer.clear`.
*/
type: 'input_audio_buffer.clear';
/**
* Optional client-generated ID used to identify this event.
*/
event_id?: string;
}
/**
* Returned when the input audio buffer is cleared by the client with a
* `input_audio_buffer.clear` event.
*/
export interface InputAudioBufferClearedEvent {
/**
* The unique ID of the server event.
*/
event_id: string;
/**
* The event type, must be `input_audio_buffer.cleared`.
*/
type: 'input_audio_buffer.cleared';
}
/**
* 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.
*
* Committing the input audio buffer will trigger input audio transcription (if
* enabled in session configuration), but it will not create a response from the
* model. The server will respond with an `input_audio_buffer.committed` event.
*/
export interface InputAudioBufferCommitEvent {
/**
* The event type, must be `input_audio_buffer.commit`.
*/
type: 'input_audio_buffer.commit';
/**
* Optional client-generated ID used to identify this event.
*/
event_id?: string;
}
/**
* Returned when an input audio buffer is committed, either by the client or
* automatically in server VAD mode. The `item_id` property is the ID of the user
* message item that will be created, thus a `conversation.item.created` event will
* also be sent to the client.
*/
export interface InputAudioBufferCommittedEvent {
/**
* The unique ID of the server event.
*/
event_id: string;
/**
* The ID of the user message item that will be created.
*/
item_id: string;
/**
* The ID of the preceding item after which the new item will be inserted.
*/
previous_item_id: string;
/**
* The event type, must be `input_audio_buffer.committed`.
*/
type: 'input_audio_buffer.committed';
}
/**
* Sent by the server when in `server_vad` mode to indicate that speech has been
* detected in the audio buffer. This can happen any time audio is added to the
* buffer (unless speech is already detected). The client may want to use this
* event to interrupt audio playback or provide visual feedback to the user.
*
* The client should expect to receive a `input_audio_buffer.speech_stopped` event
* when speech stops. The `item_id` property is the ID of the user message item
* that will be created when speech stops and will also be included in the
* `input_audio_buffer.speech_stopped` event (unless the client manually commits
* the audio buffer during VAD activation).
*/
export interface InputAudioBufferSpeechStartedEvent {
/**
* Milliseconds from the start of all audio written to the buffer during the
* session when speech was first detected. This will correspond to the beginning of
* audio sent to the model, and thus includes the `prefix_padding_ms` configured in
* the Session.
*/
audio_start_ms: number;
/**
* The unique ID of the server event.
*/
event_id: string;
/**
* The ID of the user message item that will be created when speech stops.
*/
item_id: string;
/**
* The event type, must be `input_audio_buffer.speech_started`.
*/
type: 'input_audio_buffer.speech_started';
}
/**
* Returned in `server_vad` mode when the server detects the end of speech in the
* audio buffer. The server will also send an `conversation.item.created` event
* with the user message item that is created from the audio buffer.
*/
export interface InputAudioBufferSpeechStoppedEvent {
/**
* Milliseconds since the session started when speech stopped. This will correspond
* to the end of audio sent to the model, and thus includes the
* `min_silence_duration_ms` configured in the Session.
*/
audio_end_ms: number;
/**
* The unique ID of the server event.
*/
event_id: string;
/**
* The ID of the user message item that will be created.
*/
item_id: string;
/**
* The event type, must be `input_audio_buffer.speech_stopped`.
*/
type: 'input_audio_buffer.speech_stopped';
}
/**
* Emitted at the beginning of a Response to indicate the updated rate limits. When
* a Response is created some tokens will be "reserved" for the output tokens, the
* rate limits shown here reflect that reservation, which is then adjusted
* accordingly once the Response is completed.
*/
export interface RateLimitsUpdatedEvent {
/**
* The unique ID of the server event.
*/
event_id: string;
/**
* List of rate limit information.
*/
rate_limits: Array<RateLimitsUpdatedEvent.RateLimit>;
/**
* The event type, must be `rate_limits.updated`.
*/
type: 'rate_limits.updated';
}
export namespace RateLimitsUpdatedEvent {
export interface RateLimit {
/**
* The maximum allowed value for the rate limit.
*/
limit?: number;
/**
* The name of the rate limit (`requests`, `tokens`).
*/
name?: 'requests' | 'tokens';
/**
* The remaining value before the limit is reached.
*/
remaining?: number;
/**
* Seconds until the rate limit resets.
*/
reset_seconds?: number;
}
}
/**
* All events that the client can send to the Realtime API
*/
export type RealtimeClientEvent =
| SessionUpdateEvent
| InputAudioBufferAppendEvent
| InputAudioBufferCommitEvent
| InputAudioBufferClearEvent
| ConversationItemCreateEvent
| ConversationItemTruncateEvent
| ConversationItemDeleteEvent
| ResponseCreateEvent
| ResponseCancelEvent;
/**
* The response resource.
*/
export interface RealtimeResponse {
/**
* The unique ID of the response.
*/
id?: string;
/**
* Developer-provided string key-value pairs associated with this response.
*/
metadata?: unknown | null;
/**
* The object type, must be `realtime.response`.
*/
object?: 'realtime.response';
/**
* The list of output items generated by the response.
*/
output?: Array<ConversationItem>;
/**
* The final status of the response (`completed`, `cancelled`, `failed`, or
* `incomplete`).
*/
status?: 'completed' | 'cancelled' | 'failed' | 'incomplete';
/**
* Additional details about the status.
*/
status_details?: RealtimeResponseStatus;
/**
* Usage statistics for the Response, this will correspond to billing. A Realtime
* API session will maintain a conversation context and append new Items to the
* Conversation, thus output from previous turns (text and audio tokens) will
* become the input for later turns.
*/
usage?: RealtimeResponseUsage;
}
/**
* Additional details about the status.
*/
export interface RealtimeResponseStatus {
/**
* A description of the error that caused the response to fail, populated when the
* `status` is `failed`.
*/
error?: RealtimeResponseStatus.Error;
/**
* The reason the Response did not complete. For a `cancelled` Response, one of
* `turn_detected` (the server VAD detected a new start of speech) or
* `client_cancelled` (the client sent a cancel event). For an `incomplete`
* Response, one of `max_output_tokens` or `content_filter` (the server-side safety
* filter activated and cut off the response).
*/
reason?: 'turn_detected' | 'client_cancelled' | 'max_output_tokens' | 'content_filter';
/**
* The type of error that caused the response to fail, corresponding with the
* `status` field (`completed`, `cancelled`, `incomplete`, `failed`).
*/
type?: 'completed' | 'cancelled' | 'incomplete' | 'failed';
}
export namespace RealtimeResponseStatus {
/**
* A description of the error that caused the response to fail, populated when the
* `status` is `failed`.
*/
export interface Error {
/**
* Error code, if any.
*/
code?: string;
/**
* The type of error.
*/
type?: string;
}
}
/**
* Usage statistics for the Response, this will correspond to billing. A Realtime
* API session will maintain a conversation context and append new Items to the
* Conversation, thus output from previous turns (text and audio tokens) will
* become the input for later turns.
*/
export interface RealtimeResponseUsage {
/**
* Details about the input tokens used in the Response.
*/
input_token_details?: RealtimeResponseUsage.InputTokenDetails;
/**
* The number of input tokens used in the Response, including text and audio
* tokens.
*/
input_tokens?: number;
/**
* Details about the output tokens used in the Response.
*/
output_token_details?: RealtimeResponseUsage.OutputTokenDetails;
/**
* The number of output tokens sent in the Response, including text and audio
* tokens.
*/
output_tokens?: number;
/**
* The total number of tokens in the Response including input and output text and
* audio tokens.
*/
total_tokens?: number;
}
export namespace RealtimeResponseUsage {
/**
* Details about the input tokens used in the Response.
*/
export interface InputTokenDetails {
/**
* The number of audio tokens used in the Response.
*/
audio_tokens?: number;
/**
* The number of cached tokens used in the Response.
*/
cached_tokens?: number;
/**
* The number of text tokens used in the Response.
*/
text_tokens?: number;
}
/**
* Details about the output tokens used in the Response.
*/
export interface OutputTokenDetails {
/**
* The number of audio tokens used in the Response.
*/
audio_tokens?: number;
/**
* The number of text tokens used in the Response.
*/
text_tokens?: number;
}
}
/**
* All events that the Realtime API can send back
*/
export type RealtimeServerEvent =
| ErrorEvent
| SessionCreatedEvent
| SessionUpdatedEvent
| ConversationCreatedEvent
| InputAudioBufferCommittedEvent
| InputAudioBufferClearedEvent
| InputAudioBufferSpeechStartedEvent
| InputAudioBufferSpeechStoppedEvent
| ConversationItemCreatedEvent
| ConversationItemInputAudioTranscriptionCompletedEvent
| ConversationItemInputAudioTranscriptionFailedEvent
| ConversationItemTruncatedEvent
| ConversationItemDeletedEvent
| ResponseCreatedEvent
| ResponseDoneEvent
| ResponseOutputItemAddedEvent
| ResponseOutputItemDoneEvent
| ResponseContentPartAddedEvent
| ResponseContentPartDoneEvent
| ResponseTextDeltaEvent
| ResponseTextDoneEvent
| ResponseAudioTranscriptDeltaEvent
| ResponseAudioTranscriptDoneEvent
| ResponseAudioDeltaEvent
| ResponseAudioDoneEvent
| ResponseFunctionCallArgumentsDeltaEvent
| ResponseFunctionCallArgumentsDoneEvent
| RateLimitsUpdatedEvent;
/**
* Returned when the model-generated audio is updated.
*/
export interface ResponseAudioDeltaEvent {
/**
* The index of the content part in the item's content array.
*/
content_index: number;
/**
* Base64-encoded audio data delta.
*/
delta: string;
/**
* The unique ID of the server event.
*/
event_id: string;
/**
* The ID of the item.
*/
item_id: string;
/**
* The index of the output item in the response.
*/
output_index: number;
/**
* The ID of the response.
*/
response_id: string;
/**
* The event type, must be `response.audio.delta`.
*/
type: 'response.audio.delta';
}
/**
* Returned when the model-generated audio is done. Also emitted when a Response is
* interrupted, incomplete, or cancelled.
*/
export interface ResponseAudioDoneEvent {
/**
* The index of the content part in the item's content array.
*/
content_index: number;
/**
* The unique ID of the server event.
*/
event_id: string;
/**
* The ID of the item.
*/
item_id: string;
/**
* The index of the output item in the response.
*/
output_index: number;
/**
* The ID of the response.
*/
response_id: string;
/**
* The event type, must be `response.audio.done`.
*/