realtime.d.ts 81 KB

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